private BasicFileAttributes readAttributes() throws IOException { return Files.readAttributes( path, BasicFileAttributes.class, followLinks ? FOLLOW_LINKS : new LinkOption[] {NOFOLLOW_LINKS}); }
private BasicFileAttributes readAttributes() throws IOException { return Files.readAttributes( path, BasicFileAttributes.class, followLinks ? FOLLOW_LINKS : new LinkOption[] {NOFOLLOW_LINKS}); }
private BasicFileAttributes readAttributes() throws IOException { return Files.readAttributes( path, BasicFileAttributes.class, followLinks ? FOLLOW_LINKS : new LinkOption[] {NOFOLLOW_LINKS}); }
private BasicFileAttributes readAttributes() throws IOException { return Files.readAttributes( path, BasicFileAttributes.class, followLinks ? FOLLOW_LINKS : new LinkOption[] {NOFOLLOW_LINKS}); }
private Optional<BasicFileAttributes> getFileAttributes(File file) { try { return Optional.of(Files.readAttributes(file.toPath(), BasicFileAttributes.class)); } catch (IOException ex) { logger.log(Level.WARNING, "Failed to read attributes of file " + file + ". Reason: " + ex.getMessage()); logger.log(Level.FINER, "Details: ", ex); } return Optional.empty(); }
public static long getLastModified( File file ) throws IOException { BasicFileAttributes basicFileAttributes = Files.readAttributes( file.toPath(), BasicFileAttributes.class ); return basicFileAttributes.lastModifiedTime().toMillis(); }
public FileProps perform() { try { Path target = vertx.resolveFile(path).toPath(); BasicFileAttributes attrs; if (followLinks) { attrs = Files.readAttributes(target, BasicFileAttributes.class); } else { attrs = Files.readAttributes(target, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); } return new FilePropsImpl(attrs); } catch (IOException e) { throw new FileSystemException(e); } } };
private static void makeWritable(@Nonnull Path path) throws IOException { if (!Functions.isWindows()) { try { PosixFileAttributes attrs = Files.readAttributes(path, PosixFileAttributes.class); Set<PosixFilePermission> newPermissions = attrs.permissions(); newPermissions.add(PosixFilePermission.OWNER_WRITE); Files.setPosixFilePermissions(path, newPermissions); } catch (NoSuchFileException ignored) { return; } catch (UnsupportedOperationException ignored) { // PosixFileAttributes not supported, fall back to old IO. } } /* * We intentionally do not check the return code of setWritable, because if it * is false we prefer to rethrow the exception thrown by Files.deleteIfExists, * which will have a more useful message than something we make up here. */ path.toFile().setWritable(true); }
Assert.notNull(src, "Source Path must not be null"); Assert.notNull(dest, "Destination Path must not be null"); BasicFileAttributes srcAttr = Files.readAttributes(src, BasicFileAttributes.class);
/** * Gets local file's owner. * * @param filePath the file path * @return the owner of the local file */ public static String getLocalFileOwner(String filePath) throws IOException { PosixFileAttributes attr = Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class); return attr.owner().getName(); }
/** * Gets local file's group. * * @param filePath the file path * @return the group of the local file */ public static String getLocalFileGroup(String filePath) throws IOException { PosixFileAttributes attr = Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class); return attr.group().getName(); }
private boolean isHidden(Path path) throws IOException { if (SystemUtils.IS_OS_WINDOWS) { try { DosFileAttributes dosFileAttributes = Files.readAttributes(path, DosFileAttributes.class, LinkOption.NOFOLLOW_LINKS); return dosFileAttributes.isHidden(); } catch (UnsupportedOperationException e) { return path.toFile().isHidden(); } } else { return Files.isHidden(path); } } }
/** * Gets local file's permission mode. * * @param filePath the file path * @return the file mode in short, e.g. 0777 */ public static short getLocalFileMode(String filePath) throws IOException { Set<PosixFilePermission> permission = Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class).permissions(); return translatePosixPermissionToMode(permission); }
@Override public UfsFileStatus getFileStatus(String path) throws IOException { String tpath = stripPath(path); File file = new File(tpath); PosixFileAttributes attr = Files.readAttributes(Paths.get(file.getPath()), PosixFileAttributes.class); String contentHash = UnderFileSystemUtils.approximateContentHash(file.length(), file.lastModified()); return new UfsFileStatus(path, contentHash, file.length(), file.lastModified(), attr.owner().getName(), attr.group().getName(), FileUtils.translatePosixPermissionToMode(attr.permissions())); }
@Restricted(NoExternalUse.class) public static boolean isSymlink(@Nonnull Path path) { /* * Windows Directory Junctions are effectively the same as Linux symlinks to directories. * Unfortunately, the Java 7 NIO2 API function isSymbolicLink does not treat them as such. * It thinks of them as normal directories. To use the NIO2 API & treat it like a symlink, * you have to go through BasicFileAttributes and do the following check: * isSymbolicLink() || isOther() * The isOther() call will include Windows reparse points, of which a directory junction is. * It also includes includes devices, but reading the attributes of a device with NIO fails * or returns false for isOther(). (i.e. named pipes such as \\.\pipe\JenkinsTestPipe return * false for isOther(), and drives such as \\.\PhysicalDrive0 throw an exception when * calling readAttributes. */ try { BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); return attrs.isSymbolicLink() || (attrs instanceof DosFileAttributes && attrs.isOther()); } catch (IOException ignored) { return false; } }
@CheckForNull private static Object getFileKey(File fileInTempDir) throws IOException { Path path = Paths.get(fileInTempDir.toURI()); BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); return attrs.fileKey(); }
@CheckForNull private static Object getFileKey(Path path) throws IOException { BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); return attrs.fileKey(); } }
@CheckForNull private static Object getFileKey(Path path) throws IOException { BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); return attrs.fileKey(); } }
@Override public UfsDirectoryStatus getDirectoryStatus(String path) throws IOException { String tpath = stripPath(path); File file = new File(tpath); PosixFileAttributes attr = Files.readAttributes(Paths.get(file.getPath()), PosixFileAttributes.class); return new UfsDirectoryStatus(path, attr.owner().getName(), attr.group().getName(), FileUtils.translatePosixPermissionToMode(attr.permissions()), file.lastModified()); }
@Test public void testChownToOwnGroup() throws Exception { // Not supported in WindowsFileSystemProvider Assume.assumeFalse(Utils.isWindows()); String file1 = "some-file.dat"; createFileWithJunk(file1, 100); String fullPath = testDir + pathSep + file1; Path path = Paths.get(fullPath); GroupPrincipal group = Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS).group(); vertx.fileSystem().chown(fullPath, null, group.getName(), ar -> { deleteFile(file1); assertTrue(ar.succeeded()); testComplete(); }); await(); }