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); } }
DosFileAttributes dosAttributes = Files.readAttributes(target, DosFileAttributes.class, linkOptions); DosFileAttributeView dosView = Files.getFileAttributeView(target, DosFileAttributeView.class, linkOptions); dosView.setArchive(dosAttributes.isArchive()); dosView.setHidden(dosAttributes.isHidden()); dosView.setSystem(dosAttributes.isSystem()); dosView.setReadOnly(dosAttributes.isReadOnly());
@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; } }
DosFileAttributeView attrs = Files.getFileAttributeView( file, DosFileAttributeView.class); attrs.setSystem(true); attrs.setHidden(true); attrs.setReadOnly(true);
Path path = Paths.get("your/folder"); DosFileAttributeView attr = Files.getFileAttributeView(path, DosFileAttributeView.class); attr.setHidden(true);
public DosFileAttributes getDosFileAttributes() throws IOException { if (this.dosFileAttributes == null) { this.dosFileAttributes = this.entry.getFileAttributeView(DosFileAttributeView.class).readAttributes(); } return this.dosFileAttributes; }
@Override public void writeAttribute(Object value, MemoryEntry entry) throws IOException { entry.getFileAttributeView(DosFileAttributeView.class).setArchive((Boolean) value); }
@Override public void writeAttribute(Object value, MemoryEntry entry) throws IOException { entry.getFileAttributeView(DosFileAttributeView.class).setSystem((Boolean) value); }
if (dosAttrs != null) { DosFileAttributes sourceDosAttrs = dosAttrs .readAttributes(); DosFileAttributeView targetDosAttrs = Files .getFileAttributeView(targetDir, DosFileAttributeView.class); targetDosAttrs.setArchive(sourceDosAttrs.isArchive()); targetDosAttrs.setHidden(sourceDosAttrs.isHidden()); targetDosAttrs.setReadOnly(sourceDosAttrs.isReadOnly()); targetDosAttrs.setSystem(sourceDosAttrs.isSystem());
@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 void writeAttribute(Object value, MemoryEntry entry) throws IOException { entry.getFileAttributeView(DosFileAttributeView.class).setHidden((Boolean) value); }
// import as necessary from java.nio.file and java.io DosFileAttributeView view = input.getFileAttributeView(DosFileAttributeView.class); //Check if the system supports this view if (view != null) { DosFileAttributes attributes = view.readAttributes(); // skip any file already marked as an archive if (!attributes.isArchive()) { myObject.process(input) attributes.setArchive(true) } }
DosFileAttributeView.class); if (dosAttrs != null) { DosFileAttributes sourceDosAttrs = dosAttrs.readAttributes(); DosFileAttributeView targetDosAttrs = Files.getFileAttributeView(targetDir, DosFileAttributeView.class); targetDosAttrs.setArchive(sourceDosAttrs.isArchive()); targetDosAttrs.setHidden(sourceDosAttrs.isHidden()); targetDosAttrs.setReadOnly(sourceDosAttrs.isReadOnly()); targetDosAttrs.setSystem(sourceDosAttrs.isSystem());
@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; } }
final Path path = Paths.get(thename); final DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class); view.setReadOnly(true);
@Test @Category( { Windows.class, DosAttributesT.class, Writable.class } ) public void testWindowsIsHidden() throws IOException { assertThat( Files.isHidden( fileTA() ) ).isFalse(); Files.getFileAttributeView( absTA(), DosFileAttributeView.class ).setHidden( true ); assertThat( Files.isHidden( fileTA() ) ).isTrue(); Files.setAttribute( absTA(), "dos:hidden", false ); assertThat( Files.isHidden( fileTA() ) ).isFalse(); }
public static void checkReadOnly(File file) throws IOException { // This logic check if the file attribute was mark as read only because File#setReadOnly is platform dependent (JDK-6728842) Path repositoryPath = file.toPath(); FileStore fileStore = Files.getFileStore(repositoryPath); if (fileStore.supportsFileAttributeView(DosFileAttributeView.class)) { DosFileAttributeView fileAttributeView = Files.getFileAttributeView(repositoryPath, DosFileAttributeView.class); if (fileAttributeView.readAttributes().isReadOnly()) { throw new IOException("File is not writable"); } } }
if (dosAttrs != null) { DosFileAttributes sourceDosAttrs = dosAttrs .readAttributes(); DosFileAttributeView targetDosAttrs = Files .getFileAttributeView(targetDir, DosFileAttributeView.class); targetDosAttrs.setArchive(sourceDosAttrs.isArchive()); targetDosAttrs.setHidden(sourceDosAttrs.isHidden()); targetDosAttrs.setReadOnly(sourceDosAttrs.isReadOnly()); targetDosAttrs.setSystem(sourceDosAttrs.isSystem());
@Override public void writeAttribute(Object value, MemoryEntry entry) throws IOException { entry.getFileAttributeView(DosFileAttributeView.class).setReadOnly((Boolean) value); }
public RWAttributesBuilder addDos() { attributes( "dos", DosFileAttributeView.class, DosFileAttributes.class ). attribute( "hidden", DosFileAttributes::isHidden, BiConsumerE.u( ( v, b ) -> v.setHidden( (Boolean) b ) ) ). attribute( "readonly", DosFileAttributes::isReadOnly ). attribute( "system", DosFileAttributes::isSystem ). attribute( "archive", DosFileAttributes::isArchive ); return this; }