Search in sources :

Example 1 with DosFileAttributeView

use of java.nio.file.attribute.DosFileAttributeView in project core by CubeEngine.

the class FileUtil method hideFile.

public static boolean hideFile(Path path) {
    try {
        DosFileAttributeView attributeView = Files.getFileAttributeView(path, DosFileAttributeView.class);
        attributeView.setHidden(true);
        return true;
    } catch (IOException e) {
        return false;
    }
}
Also used : DosFileAttributeView(java.nio.file.attribute.DosFileAttributeView) IOException(java.io.IOException)

Example 2 with DosFileAttributeView

use of java.nio.file.attribute.DosFileAttributeView in project cryptofs by cryptomator.

the class CryptoFileSystemImpl method copyAttributes.

private void copyAttributes(Path src, Path dst) throws IOException {
    Set<Class<? extends FileAttributeView>> supportedAttributeViewTypes = fileStore.supportedFileAttributeViewTypes();
    if (supportedAttributeViewTypes.contains(BasicFileAttributeView.class)) {
        BasicFileAttributes srcAttrs = Files.readAttributes(src, BasicFileAttributes.class);
        BasicFileAttributeView dstAttrView = Files.getFileAttributeView(dst, BasicFileAttributeView.class);
        dstAttrView.setTimes(srcAttrs.lastModifiedTime(), srcAttrs.lastAccessTime(), srcAttrs.creationTime());
    }
    if (supportedAttributeViewTypes.contains(FileOwnerAttributeView.class)) {
        FileOwnerAttributeView srcAttrView = Files.getFileAttributeView(src, FileOwnerAttributeView.class);
        FileOwnerAttributeView dstAttrView = Files.getFileAttributeView(dst, FileOwnerAttributeView.class);
        dstAttrView.setOwner(srcAttrView.getOwner());
    }
    if (supportedAttributeViewTypes.contains(PosixFileAttributeView.class)) {
        PosixFileAttributes srcAttrs = Files.readAttributes(src, PosixFileAttributes.class);
        PosixFileAttributeView dstAttrView = Files.getFileAttributeView(dst, PosixFileAttributeView.class);
        dstAttrView.setGroup(srcAttrs.group());
        dstAttrView.setPermissions(srcAttrs.permissions());
    }
    if (supportedAttributeViewTypes.contains(DosFileAttributeView.class)) {
        DosFileAttributes srcAttrs = Files.readAttributes(src, DosFileAttributes.class);
        DosFileAttributeView dstAttrView = Files.getFileAttributeView(dst, DosFileAttributeView.class);
        dstAttrView.setArchive(srcAttrs.isArchive());
        dstAttrView.setHidden(srcAttrs.isHidden());
        dstAttrView.setReadOnly(srcAttrs.isReadOnly());
        dstAttrView.setSystem(srcAttrs.isSystem());
    }
}
Also used : BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) FileOwnerAttributeView(java.nio.file.attribute.FileOwnerAttributeView) DosFileAttributeView(java.nio.file.attribute.DosFileAttributeView) DosFileAttributes(java.nio.file.attribute.DosFileAttributes) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) DosFileAttributeView(java.nio.file.attribute.DosFileAttributeView) BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) FileAttributeView(java.nio.file.attribute.FileAttributeView) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView)

Example 3 with DosFileAttributeView

use of java.nio.file.attribute.DosFileAttributeView in project cryptofs by cryptomator.

the class DeletingFileVisitor method setWritable.

private static void setWritable(Path path) throws IOException {
    DosFileAttributeView dosAttributes = Files.getFileAttributeView(path, DosFileAttributeView.class);
    PosixFileAttributeView posixAttributes = Files.getFileAttributeView(path, PosixFileAttributeView.class);
    if (dosAttributes != null) {
        dosAttributes.setReadOnly(false);
        dosAttributes.setSystem(false);
    }
    if (posixAttributes != null) {
        posixAttributes.setPermissions(POSIX_PERMISSIONS_770);
    }
}
Also used : DosFileAttributeView(java.nio.file.attribute.DosFileAttributeView) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView)

Example 4 with DosFileAttributeView

use of java.nio.file.attribute.DosFileAttributeView in project jimfs by google.

the class DosAttributeProviderTest method testView.

@Test
public void testView() throws IOException {
    DosFileAttributeView view = provider.view(fileLookup(), ImmutableMap.<String, FileAttributeView>of("basic", new BasicAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS)));
    assertNotNull(view);
    assertThat(view.name()).isEqualTo("dos");
    DosFileAttributes attrs = view.readAttributes();
    assertThat(attrs.isHidden()).isFalse();
    assertThat(attrs.isArchive()).isFalse();
    assertThat(attrs.isReadOnly()).isFalse();
    assertThat(attrs.isSystem()).isFalse();
    view.setArchive(true);
    view.setReadOnly(true);
    view.setHidden(true);
    view.setSystem(false);
    assertThat(attrs.isHidden()).isFalse();
    assertThat(attrs.isArchive()).isFalse();
    assertThat(attrs.isReadOnly()).isFalse();
    attrs = view.readAttributes();
    assertThat(attrs.isHidden()).isTrue();
    assertThat(attrs.isArchive()).isTrue();
    assertThat(attrs.isReadOnly()).isTrue();
    assertThat(attrs.isSystem()).isFalse();
    view.setTimes(FileTime.fromMillis(0L), null, null);
    assertThat(view.readAttributes().lastModifiedTime()).isEqualTo(FileTime.fromMillis(0L));
}
Also used : DosFileAttributeView(java.nio.file.attribute.DosFileAttributeView) DosFileAttributes(java.nio.file.attribute.DosFileAttributes) Test(org.junit.Test)

Example 5 with DosFileAttributeView

use of java.nio.file.attribute.DosFileAttributeView in project ant by apache.

the class SetPermissions method tryDos.

private void tryDos(Path p, boolean failIfDosIsNotSupported) {
    log("Falling back to DosFileAttributeView");
    boolean readOnly = !isWritable();
    DosFileAttributeView view = Files.getFileAttributeView(p, DosFileAttributeView.class);
    if (view != null) {
        try {
            view.setReadOnly(readOnly);
        } catch (IOException ioe) {
            maybeThrowException(ioe, "Failed to set permissions on '%s' due to %s", p, ioe.getMessage());
        } catch (SecurityException uoe) {
            maybeThrowException(null, "the SecurityManager denies role accessUserInformation or write access for SecurityManager.checkWrite for resource '%s'", p);
        }
    } else {
        String msg = String.format("the associated path '%s' does not support the DosFileAttributeView", p);
        if (failIfDosIsNotSupported) {
            throw new BuildException(msg);
        }
        log("Warning: " + msg, Project.MSG_ERR);
    }
}
Also used : DosFileAttributeView(java.nio.file.attribute.DosFileAttributeView) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Aggregations

DosFileAttributeView (java.nio.file.attribute.DosFileAttributeView)5 IOException (java.io.IOException)2 DosFileAttributes (java.nio.file.attribute.DosFileAttributes)2 PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)2 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 FileAttributeView (java.nio.file.attribute.FileAttributeView)1 FileOwnerAttributeView (java.nio.file.attribute.FileOwnerAttributeView)1 PosixFileAttributes (java.nio.file.attribute.PosixFileAttributes)1 BuildException (org.apache.tools.ant.BuildException)1 Test (org.junit.Test)1