/** * This implementation checks whether the underlying file is marked as writable * (and corresponds to an actual file with content, not to a directory). * @see java.nio.file.Files#isWritable(Path) * @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...) */ @Override public boolean isWritable() { return (Files.isWritable(this.path) && !Files.isDirectory(this.path)); }
public boolean isWritable(Path path) { return Files.isWritable(path); }
/** * This implementation checks whether the underlying file is marked as writable * (and corresponds to an actual file with content, not to a directory). * @see java.io.File#canWrite() * @see java.io.File#isDirectory() */ @Override public boolean isWritable() { return (this.file != null ? this.file.canWrite() && !this.file.isDirectory() : Files.isWritable(this.filePath) && !Files.isDirectory(this.filePath)); }
public boolean isWritable(Path path) { return Files.isWritable(path); }
/** * This implementation checks whether the underlying file is marked as writable * (and corresponds to an actual file with content, not to a directory). * @see java.nio.file.Files#isWritable(Path) * @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...) */ @Override public boolean isWritable() { return (Files.isWritable(this.path) && !Files.isDirectory(this.path)); }
/** * This implementation checks whether the underlying file is marked as writable * (and corresponds to an actual file with content, not to a directory). * @see java.io.File#canWrite() * @see java.io.File#isDirectory() */ @Override public boolean isWritable() { return (this.file != null ? this.file.canWrite() && !this.file.isDirectory() : Files.isWritable(this.filePath) && !Files.isDirectory(this.filePath)); }
@Override public boolean testTargetCanCreate() { if (Files.isWritable(repoPath.getParent())) { logger.log(Level.INFO, "testTargetCanCreate: Can create target."); return true; } else { logger.log(Level.INFO, "testTargetCanCreate: Can NOT create target."); return false; } } }
@Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (!Files.isWritable(path)) { //When you try to delete the file on Windows and it is marked as read-only //it would fail unless this change path.toFile().setWritable(true); } Files.delete(path); return FileVisitResult.CONTINUE; }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!Files.isWritable(file)) { //When you try to delete the file on Windows and it is marked as read-only //it would fail unless this change file.toFile().setWritable(true); } Files.delete(file); return FileVisitResult.CONTINUE; }
private static void makeRemovable(@Nonnull Path path) throws IOException { if (!Files.isWritable(path)) { makeWritable(path); } /* on Unix both the file and the directory that contains it has to be writable for a file deletion to be successful. (Confirmed on Solaris 9) $ ls -la total 6 dr-xr-sr-x 2 hudson hudson 512 Apr 18 14:41 . dr-xr-sr-x 3 hudson hudson 512 Apr 17 19:36 .. -r--r--r-- 1 hudson hudson 469 Apr 17 19:36 manager.xml -rw-r--r-- 1 hudson hudson 0 Apr 18 14:41 x $ rm x rm: x not removed: Permission denied */ Optional<Path> maybeParent = Optional.ofNullable(path.getParent()).map(Path::normalize).filter(p -> !Files.isWritable(p)); if (maybeParent.isPresent()) { makeWritable(maybeParent.get()); } }
private File findLocalCacheDir() { try { String defaultCacheDir = m_configUtil.getDefaultLocalCacheDir(); Path path = Paths.get(defaultCacheDir); if (!Files.exists(path)) { Files.createDirectories(path); } if (Files.exists(path) && Files.isWritable(path)) { return new File(defaultCacheDir, CONFIG_DIR); } } catch (Throwable ex) { //ignore } return new File(ClassLoaderUtil.getClassPath(), CONFIG_DIR); }
/** * Checks if a storage directory path is accessible. * * @param path the given path * @return true if path exists, false otherwise */ public static boolean isStorageDirAccessible(String path) { Path filePath = Paths.get(path); return Files.exists(filePath) && Files.isReadable(filePath) && Files.isWritable(filePath) && Files.isExecutable(filePath); }
@Override public String validate(String value) { final Path path = FileSystems.getDefault().getPath(value); if (path == null && value != null) { return String.format("Path '%s' provided could not be located.", value); } final boolean isDir = Files.isDirectory(path); final boolean isWritable = Files.isWritable(path); if (!isDir) { return String.format("Path '%s' provided is not a directory.", value); } if (!isWritable) { return String.format("Path '%s' provided is not writable.", value); } return null; }
public static void checkWritableDirectory( Path directory ) throws FileSystemException { if ( !exists( directory ) ) { throw new NoSuchFileException( directory.toString() ); } if ( isRegularFile( directory ) ) { throw new FileSystemException( directory.toString() + ": Not a directory" ); } if ( !isWritable( directory ) ) { throw new AccessDeniedException( directory.toString() ); } }
private void repositoryWriter(String content, Path filePath) { if(Files.exists(filePath) && !Files.isWritable(filePath)){ log.error("Error file is not writable: " + filePath); return; } if(Files.notExists(filePath.getParent())) { try { Files.createDirectories(filePath.getParent()); } catch (IOException e) { log.error("Error creating the directory: " + filePath + " message: " + e.getMessage(), e); } } try { Path target = null; if(Files.exists(filePath)) { target = FileSystems.getDefault().getPath(filePath.getParent().toString(), "device.db.old"); Files.move(filePath, target); } Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE); if(target != null) Files.delete(target); } catch (IOException e) { log.error("Error writing the file: " + filePath + " message: " + e.getMessage(), e); } }
private void repositoryWriter(String content, Path filePath) { if(Files.exists(filePath) && !Files.isWritable(filePath)){ log.error("Error file is not writable: " + filePath); return; } if(Files.notExists(filePath.getParent())) { try { Files.createDirectories(filePath.getParent()); } catch (IOException e) { log.error("Error creating the directory: " + filePath + " message: " + e.getMessage(), e); } } try { Path target = null; if(Files.exists(filePath)) { target = FileSystems.getDefault().getPath(filePath.getParent().toString(), "group.db.old"); Files.move(filePath, target); } Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE); if(target != null) Files.delete(target); } catch (IOException e) { log.error("Error writing the file: " + filePath + " message: " + e.getMessage(), e); } }
private Set<File> performListing(final File directory, final FileFilter filter, final boolean recurseSubdirectories) { Path p = directory.toPath(); if (!Files.isWritable(p) || !Files.isReadable(p)) { throw new IllegalStateException("Directory '" + directory + "' does not have sufficient permissions (i.e., not writable and readable)"); } final Set<File> queue = new HashSet<>(); if (!directory.exists()) { return queue; } final File[] children = directory.listFiles(); if (children == null) { return queue; } for (final File child : children) { if (child.isDirectory()) { if (recurseSubdirectories) { queue.addAll(performListing(child, filter, recurseSubdirectories)); } } else if (filter.accept(child)) { queue.add(child); } } return queue; }
@Override public void purge() { // delete all content from repositories for (final Path path : containers.values()) { FileUtils.deleteFilesInDir(path.toFile(), null, LOG, true); } for (final Path path : containers.values()) { if (!Files.exists(path)) { throw new RepositoryPurgeException("File " + path.toFile().getAbsolutePath() + " does not exist"); } // Try up to 10 times to see if the directory is writable, in case another process (like a // virus scanner) has the directory temporarily locked boolean writable = false; for (int i = 0; i < 10; i++) { if (Files.isWritable(path)) { writable = true; break; } else { try { Thread.sleep(100L); } catch (final Exception e) { } } } if (!writable) { throw new RepositoryPurgeException("File " + path.toFile().getAbsolutePath() + " is not writable"); } } resourceClaimManager.purge(); }
checkState(tmpDir != null, "The temporary directory must not be null!"); final Path tmpPath = Paths.get(tmpDir); if (!Files.isDirectory(tmpPath) || !Files.isWritable(tmpPath)) { throw new IllegalStateException("Couldn't write to temporary directory: " + tmpPath.toAbsolutePath());
if ( Files.exists( lockFile ) ) if ( Files.isWritable( lockFile ) )