jnr.posix.FileStat Java Examples

The following examples show how to use jnr.posix.FileStat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Common.java    From benchmarks with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("UseOfSystemOutOrSystemErr")
protected void reportSpaceUsed(final File dir, final String desc) {
  final File[] files = dir.listFiles();
  if (files == null) {
    return;
  }
  long bytes = 0;
  for (final File f : files) {
    if (f.isDirectory()) {
      throw new UnsupportedOperationException("impl created directory");
    }
    final FileStat stat = POSIX.stat(f.getAbsolutePath());
    bytes += stat.blocks() * S_BLKSIZE;
  }
  out.println("\nBytes\t" + desc + "\t" + bytes + "\t" + dir.getName());
}
 
Example #2
Source File: IOUtils.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
public static List<JnrDirent> jnrReaddir(POSIX posix, Path path) throws IOException {
  List<JnrDirent> dirents = new ArrayList<>();
  try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
    for (Path file : stream) {
      FileStat stat = jnrStatNullable(posix, file.toString());
      dirents.add(new JnrDirent(file.getFileName().toString(), stat));
    }
  }
  return dirents;
}
 
Example #3
Source File: IOUtils.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
public static FileStat jnrStatNullable(POSIX posix, String path) {
  try {
    return posix.stat(path);
  } catch (Exception e) {
    return null;
  }
}
 
Example #4
Source File: WatchmanFileWatcher.java    From mirror with Apache License 2.0 5 votes vote down vote up
private void putFile(Map<String, Object> file) {
  int mode = ((Number) file.get("mode")).intValue();
  long mtime = ((Number) file.get("mtime_ms")).longValue();
  Object name = file.get("name");
  if (!(name instanceof String)) {
    return; // ignore non-utf8 file names as they are likely corrupted
  }
  resetIfInterrupted(() -> {
    Update.Builder ub = Update
      .newBuilder()
      .setPath((String) name)
      .setDelete(!(boolean) file.get("exists"))
      .setModTime(mtime)
      .setDirectory(isFileStatType(mode, FileStat.S_IFDIR))
      .setExecutable(isExecutable(mode))
      .setLocal(true);
    readSymlinkTargetIfNeeded(ub, mode);
    setIgnoreStringIfNeeded(ub);
    clearModTimeIfADelete(ub);
    Update u = ub.build();
    if (log.isTraceEnabled()) {
      log.trace("Queueing: " + TextFormat.shortDebugString(u));
    }
    if (config != null && config.shouldDebug(ub.getPath())) {
      log.info("Queueing: " + TextFormat.shortDebugString(u));
    }
    queue.put(u);
  });
}
 
Example #5
Source File: JnrDirent.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
/** Creates a new jnr dirent with the given name */
public JnrDirent(String name, FileStat stat) {
  this.name = Preconditions.checkNotNull(name);
  this.stat = stat;
}
 
Example #6
Source File: JnrDirent.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
@Nullable
public FileStat getStat() {
  return stat;
}
 
Example #7
Source File: IOUtils.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
public static long jnrGetInode(POSIX posix, String path) {
  FileStat fs = posix.lstat(path);
  return fs.ino();
}
 
Example #8
Source File: WatchmanFileWatcher.java    From mirror with Apache License 2.0 4 votes vote down vote up
private void readSymlinkTargetIfNeeded(Update.Builder ub, int mode) {
  if (isFileStatType(mode, FileStat.S_IFLNK)) {
    readSymlinkTarget(ub);
  }
}
 
Example #9
Source File: WatchmanFileWatcher.java    From mirror with Apache License 2.0 4 votes vote down vote up
private static boolean isFileStatType(int mode, int mask) {
  return (mode & FileStat.S_IFMT) == mask;
}
 
Example #10
Source File: WatchmanFileWatcher.java    From mirror with Apache License 2.0 4 votes vote down vote up
private static boolean isExecutable(int mode) {
  return (mode & FileStat.S_IXUGO) != 0;
}
 
Example #11
Source File: NativeFileAccessUtils.java    From mirror with Apache License 2.0 4 votes vote down vote up
public static void setWritable(Path absolutePath) {
  FileStat s = posix.stat(absolutePath.toFile().toString());
  posix.chmod(absolutePath.toFile().toString(), s.mode() | Integer.parseInt("0700", 8));
}
 
Example #12
Source File: NativeFileSystemPosix.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public int getFileSystemBlockSize(Path path) {
    FileStat stat = posix.stat(path.toString());
    return Math.toIntExact(stat.blockSize());
}
 
Example #13
Source File: NativeFileSystemPosix.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public int getFileSystemBlockSize(int fd) {
    FileStat stat = posix.fstat(fd);
    return Math.toIntExact(stat.blockSize());
}
 
Example #14
Source File: NativeFileSystemPosix.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public long getSparseFileSize(int fd) {
    FileStat stat = posix.fstat(fd);
    return stat.blocks() * 512;
}