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;
}
}
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());
}
}
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);
}
}
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));
}
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);
}
}
Aggregations