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); } }
final Path path = Paths.get(thename); final DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class); view.setReadOnly(true);
@Override public void writeAttribute(Object value, MemoryEntry entry) throws IOException { entry.getFileAttributeView(DosFileAttributeView.class).setReadOnly((Boolean) value); }
DosFileAttributeView attrs = Files.getFileAttributeView( file, DosFileAttributeView.class); attrs.setSystem(true); attrs.setHidden(true); attrs.setReadOnly(true);
public static void markAsReadOnly(File file) throws IOException { boolean succeeded = file.setReadOnly(); // We need to add this extra logic due to a bug in windows (JDK-6728842) if (!succeeded) { Path filePath = file.toPath(); FileStore fileStore = Files.getFileStore(filePath); if (fileStore.supportsFileAttributeView(DosFileAttributeView.class)) { DosFileAttributeView fileAttributeView = Files.getFileAttributeView(filePath, DosFileAttributeView.class); fileAttributeView.setReadOnly(true); } } }
@Override public boolean putFileInfo(String fileName, IFileInfo info, int options) { Path path = Paths.get(fileName); // To be consistent with fetchInfo do not following symbolic links to set archive, read only and hidden attributes. DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); try { view.setArchive(info.getAttribute(EFS.ATTRIBUTE_ARCHIVE)); view.setReadOnly(info.getAttribute(EFS.ATTRIBUTE_READ_ONLY)); view.setHidden(info.getAttribute(EFS.ATTRIBUTE_HIDDEN)); } catch (IOException e) { return false; } return true; } }
@Override public boolean putFileInfo(String fileName, IFileInfo info, int options) { Path path = Paths.get(fileName); // To be consistent with fetchInfo do not following symbolic links to set archive, read only and hidden attributes. DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); try { view.setArchive(info.getAttribute(EFS.ATTRIBUTE_ARCHIVE)); view.setReadOnly(info.getAttribute(EFS.ATTRIBUTE_READ_ONLY)); view.setHidden(info.getAttribute(EFS.ATTRIBUTE_HIDDEN)); } catch (IOException e) { return false; } return true; } }
@Override public boolean putFileInfo(String fileName, IFileInfo info, int options) { Path path = Paths.get(fileName); // To be consistent with fetchInfo do not following symbolic links to set archive, read only and hidden attributes. DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); try { view.setArchive(info.getAttribute(EFS.ATTRIBUTE_ARCHIVE)); view.setReadOnly(info.getAttribute(EFS.ATTRIBUTE_READ_ONLY)); view.setHidden(info.getAttribute(EFS.ATTRIBUTE_HIDDEN)); } catch (IOException e) { return false; } return true; } }
dosView.setHidden(dosAttributes.isHidden()); dosView.setSystem(dosAttributes.isSystem()); dosView.setReadOnly(dosAttributes.isReadOnly());
targetDosAttrs.setArchive(sourceDosAttrs.isArchive()); targetDosAttrs.setHidden(sourceDosAttrs.isHidden()); targetDosAttrs.setReadOnly(sourceDosAttrs.isReadOnly()); targetDosAttrs.setSystem(sourceDosAttrs.isSystem());
targetDosAttrs.setArchive(sourceDosAttrs.isArchive()); targetDosAttrs.setHidden(sourceDosAttrs.isHidden()); targetDosAttrs.setReadOnly(sourceDosAttrs.isReadOnly()); targetDosAttrs.setSystem(sourceDosAttrs.isSystem());
targetDosAttrs.setArchive(sourceDosAttrs.isArchive()); targetDosAttrs.setHidden(sourceDosAttrs.isHidden()); targetDosAttrs.setReadOnly(sourceDosAttrs.isReadOnly()); targetDosAttrs.setSystem(sourceDosAttrs.isSystem());