private long getInode(File file) throws IOException { long inode = (long) Files.getAttribute(file.toPath(), "unix:ino"); return inode; }
private static boolean isPipe(FileSystem fs, FileStatus file) { if (fs instanceof DistributedFileSystem) { return false; // Shortcut for HDFS. } int mode = 0; Object pathToLog = file.getPath(); try { java.nio.file.Path realPath = Paths.get(file.getPath().toUri()); pathToLog = realPath; mode = (Integer)Files.getAttribute(realPath, "unix:mode"); } catch (FileSystemNotFoundException t) { return false; // Probably not a local filesystem; no need to check. } catch (UnsupportedOperationException | IOException | SecurityException | IllegalArgumentException t) { LOG.info("Failed to check mode for " + pathToLog + ": " + t.getMessage() + " (" + t.getClass() + ")"); return false; } return (mode & S_IFIFO) != 0; }
private static boolean isPipe(FileSystem fs, FileStatus file) { if (fs instanceof DistributedFileSystem) { return false; // Shortcut for HDFS. } int mode = 0; Object pathToLog = file.getPath(); try { java.nio.file.Path realPath = Paths.get(file.getPath().toUri()); pathToLog = realPath; mode = (Integer)Files.getAttribute(realPath, "unix:mode"); } catch (FileSystemNotFoundException t) { return false; // Probably not a local filesystem; no need to check. } catch (UnsupportedOperationException | IOException | SecurityException | IllegalArgumentException t) { LOG.info("Failed to check mode for " + pathToLog + ": " + t.getMessage() + " (" + t.getClass() + ")"); return false; } return (mode & S_IFIFO) != 0; }
public static Memory filegroup(Environment env, TraceInfo trace, String path) { Path file = Paths.get(path); try { int attribute = (int) Files.getAttribute(file, "unix:gid"); return LongMemory.valueOf(attribute); } catch (IOException | SecurityException e) { env.warning(trace, e.getMessage()); return Memory.FALSE; } catch (UnsupportedOperationException e) { return Memory.FALSE; } }
public static Memory fileowner(Environment env, TraceInfo trace, String path) { Path file = Paths.get(path); try { int attribute = (int) Files.getAttribute(file, "unix:uid"); return LongMemory.valueOf(attribute); } catch (IOException | SecurityException e) { env.warning(trace, e.getMessage()); return Memory.FALSE; } catch (UnsupportedOperationException e) { return Memory.FALSE; } }
public static Memory fileperms(Environment env, TraceInfo trace, String path) { Path file = Paths.get(path); try { int attribute = (int) Files.getAttribute(file, "unix:mode"); return LongMemory.valueOf(attribute); } catch (IOException | SecurityException e) { env.warning(trace, e.getMessage()); return Memory.FALSE; } catch (UnsupportedOperationException e) { return Memory.FALSE; } }
private int getUnixFileMode(final String pathAsString) { final Path path = Paths.get(pathAsString); if (this.forcedFileMode != null) { return this.getModeValue(path); } try { return (int) Files.getAttribute(path, "unix:mode"); } catch (IOException | UnsupportedOperationException e) { // fallback for non-posix environments int mode = DEFAULT_FILE_MODE; if (Files.isDirectory(path)) { mode = DEFAULT_DIR_MODE; } else if (Files.isExecutable(path)) { mode |= 0111; // equiv to +x for user/group/others } return mode; } }
@NotNull protected DockerClientConfig tryConfiguration(String dockerHost) { Path dockerSocketFile = Paths.get(DOCKER_SOCK_PATH); Integer mode; try { mode = (Integer) Files.getAttribute(dockerSocketFile, "unix:mode"); } catch (IOException e) { throw new InvalidConfigurationException("Could not find unix domain socket", e); } if ((mode & 0xc000) != SOCKET_FILE_MODE_MASK) { throw new InvalidConfigurationException("Found docker unix domain socket but file mode was not as expected (expected: srwxr-xr-x). This problem is possibly due to occurrence of this issue in the past: https://github.com/docker/docker/issues/13121"); } config = DefaultDockerClientConfig.createDefaultConfigBuilder() .withDockerHost(dockerHost) .withDockerTlsVerify(false) .build(); client = getClientForConfig(config); final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT)); ping(client, timeout); return config; }
final Path path = Paths.get(DIR, "rollingtest.log"); if (Files.exists(path) && createOnDemand) { Assert.fail(String.format("Unexpected file: %s (%s bytes)", path, Files.getAttribute(path, "size")));
Paths.get(lock.getAbsolutePath() + ".lnk"), //$NON-NLS-1$ lockPath); Integer nlink = (Integer) (Files.getAttribute(lockPath, "unix:nlink")); //$NON-NLS-1$ if (nlink > 2) {
try { link = Files.createLink(Paths.get(uniqueLinkPath(file)), path); Integer nlink = (Integer) (Files.getAttribute(path, "unix:nlink")); //$NON-NLS-1$ if (nlink.intValue() > 2) {
public int getMode() throws IOException { if (mode == -1) { Path p = Paths.get(this.path); this.mode = (Integer) Files.getAttribute(p, "unix:mode"); } return this.mode; }
/** * * @return returns the group owner id * @throws IOException */ public int getGroup_id() throws IOException { if (group_id == -1) { Path p = Paths.get(this.path); this.group_id = (Integer) Files.getAttribute(p, "unix:gid"); } return group_id; }
/** * * @return the file owner id * @throws IOException */ public int getOwner_id() throws IOException { if (owner_id == -1) { Path p = Paths.get(this.path); this.owner_id = (Integer) Files.getAttribute(p, "unix:uid"); } return owner_id; }
@Override public boolean matches(final Path path) { try { final Boolean hidden = (Boolean) Files.getAttribute(path, "dos:hidden"); return hidden != null && Boolean.TRUE.equals(hidden); } catch (IOException e) { return false; } } }
private long getInode(File file) throws IOException { long inode = (long) Files.getAttribute(file.toPath(), "unix:ino"); return inode; }
/** * Get the length of a file. * * @param file file to measure * @return file length * @throws IOException if an I/O error occurs * @throws IllegalArgumentException if {@code file} is null */ public static long getLength(final File file) throws IOException { Preconditions.checkArgument(file != null, "null file"); return (Long)Files.getAttribute(file.toPath(), "size"); }
@Test @Category( Attributes.class ) public void testGetUnsupportedAttributeThrows() throws IOException { assertThatThrownBy( () -> Files.getAttribute( fileTA(), "whoaa:freeze" ) ).isInstanceOf( UnsupportedOperationException.class ); }
@Test(expected = UnsupportedOperationException.class) public void getAttribute() throws IOException { Files.getAttribute(fs.getPath("file"), "basic", (LinkOption) null); }
@Test @Category( Attributes.class ) @SuppressWarnings( "PMD.JUnitTestsShouldIncludeAssert" ) public void testGetUnsupportedAttributeThrows2() throws IOException { description.getAttributeDescriptions().forEach( ad -> assertThatThrownBy( () -> Files.getAttribute( getFile(), ad.getName() + ":areallystupidname" ) ). isInstanceOf( IllegalArgumentException.class ) ); }