Java Code Examples for org.apache.hadoop.fs.FileStatus#getPermission()

The following examples show how to use org.apache.hadoop.fs.FileStatus#getPermission() . 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: DistCp.java    From RDFS with Apache License 2.0 6 votes vote down vote up
private FSDataOutputStream create(Path f, Reporter reporter,
    FileStatus srcstat) throws IOException {
  if (destFileSys.exists(f)) {
    destFileSys.delete(f, false);
  }
  if (!preserve_status) {
    return destFileSys.create(f, true, sizeBuf, reporter);
  }

  FsPermission permission = preserved.contains(FileAttribute.PERMISSION)?
      srcstat.getPermission(): null;
  short replication = preserved.contains(FileAttribute.REPLICATION)?
      srcstat.getReplication(): destFileSys.getDefaultReplication();
  long blockSize = preserved.contains(FileAttribute.BLOCK_SIZE)?
      srcstat.getBlockSize(): destFileSys.getDefaultBlockSize();
  return destFileSys.create(f, permission, true, sizeBuf, replication,
      blockSize, reporter);
}
 
Example 2
Source File: TestHttpFSFileSystemLocalFileSystem.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
protected void testSetPermission() throws Exception {
  if (Path.WINDOWS) {
    FileSystem fs = FileSystem.get(getProxiedFSConf());
    Path path = new Path(getProxiedFSTestDir(), "foodir");
    fs.mkdirs(path);

    fs = getHttpFSFileSystem();
    FsPermission permission1 = new FsPermission(FsAction.READ_WRITE, FsAction.NONE, FsAction.NONE);
    fs.setPermission(path, permission1);
    fs.close();

    fs = FileSystem.get(getProxiedFSConf());
    FileStatus status1 = fs.getFileStatus(path);
    fs.close();
    FsPermission permission2 = status1.getPermission();
    Assert.assertEquals(permission2, permission1);

    // sticky bit not supported on Windows with local file system, so the
    // subclass skips that part of the test
  } else {
    super.testSetPermission();
  }
}
 
Example 3
Source File: FileSystemRule.java    From tajo with Apache License 2.0 6 votes vote down vote up
private void canAccessToPath(FileStatus fsStatus, FsAction action) throws Exception {
  FsPermission permission = fsStatus.getPermission();
  UserGroupInformation userGroupInformation = UserGroupInformation.getCurrentUser();
  String userName = userGroupInformation.getShortUserName();
  List<String> groupList = Arrays.asList(userGroupInformation.getGroupNames());
  
  if (userName.equals(fsStatus.getOwner())) {
    if (permission.getUserAction().implies(action)) {
      return;
    }
  } else if (groupList.contains(fsStatus.getGroup())) {
    if (permission.getGroupAction().implies(action)) {
      return;
    }
  } else {
    if (permission.getOtherAction().implies(action)) {
      return;
    }
  }
  throw new AccessControlException(String.format(
      "Permission denied: user=%s, path=\"%s\":%s:%s:%s%s", userName, fsStatus.getPath(),
      fsStatus.getOwner(), fsStatus.getGroup(), fsStatus.isDirectory() ? "d" : "-", permission));
}
 
Example 4
Source File: MrsImageInfo.java    From mrgeo with Apache License 2.0 6 votes vote down vote up
private void printFileInfo(final Path pfile, PrintStream out) throws IOException
{
  // TODO: The following is HDFS-sepcific; needs to be re-factored
  final FileSystem fs = pfile.getFileSystem(config);
  final FileStatus stat = fs.getFileStatus(pfile);

  out.print("    date: " +
      DateTimeFormat.shortDateTime().print(stat.getModificationTime()));
  out.println("  size: " + human(stat.getLen()));

  final FsPermission p = stat.getPermission();

  if (debug)
  {
    out.print("    ");
    out.print(stat.isDir() ? "d" : "f");
    out.print(" u: " + stat.getOwner() + " (" +
        p.getUserAction().toString().toLowerCase() + ")");
    out.print(" g: " + stat.getGroup() + " (" +
        p.getGroupAction().toString().toLowerCase() + ")");
    out.print(" o: " + "(" + p.getOtherAction().toString().toLowerCase() + ")");

    out.print(" blk: " + human(stat.getBlockSize()));
    out.println(" repl: " + stat.getReplication());
  }
}
 
Example 5
Source File: DistCp.java    From RDFS with Apache License 2.0 6 votes vote down vote up
private FSDataOutputStream create(Path f, Reporter reporter,
    FileStatus srcstat) throws IOException {
  if (destFileSys.exists(f)) {
    destFileSys.delete(f, false);
  }
  if (!preserve_status) {
    return destFileSys.create(f, true, sizeBuf, reporter);
  }

  FsPermission permission = preserved.contains(FileAttribute.PERMISSION)?
      srcstat.getPermission(): null;
  short replication = preserved.contains(FileAttribute.REPLICATION)?
      srcstat.getReplication(): destFileSys.getDefaultReplication();
  long blockSize = preserved.contains(FileAttribute.BLOCK_SIZE)?
      srcstat.getBlockSize(): destFileSys.getDefaultBlockSize();
  return destFileSys.create(f, permission, true, sizeBuf, replication,
      blockSize, reporter);
}
 
Example 6
Source File: TestDistCacheEmulation.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Validate private/public distributed cache files.
 * 
 * @param filesSizesExpected
 *          list of sizes of expected dist cache files
 * @param distCacheDir
 *          the distributed cache dir to be validated
 * @throws IOException
 * @throws FileNotFoundException
 */
private void validateDistCacheFiles(List<Long> filesSizesExpected, Path distCacheDir)
    throws FileNotFoundException, IOException {
  // RemoteIterator<LocatedFileStatus> iter =
  FileStatus[] statuses = GridmixTestUtils.dfs.listStatus(distCacheDir);
  int numFiles = filesSizesExpected.size();
  assertEquals("Number of files under distributed cache dir is wrong.",
      numFiles, statuses.length);
  for (int i = 0; i < numFiles; i++) {
    FileStatus stat = statuses[i];
    assertTrue("File size of distributed cache file "
        + stat.getPath().toUri().getPath() + " is wrong.",
        filesSizesExpected.remove(stat.getLen()));

    FsPermission perm = stat.getPermission();
    assertEquals("Wrong permissions for distributed cache file "
        + stat.getPath().toUri().getPath(), new FsPermission(
        GenerateDistCacheData.GRIDMIX_DISTCACHE_FILE_PERM), perm);
  }
}
 
Example 7
Source File: TestPermission.java    From big-c with Apache License 2.0 5 votes vote down vote up
static FsPermission checkPermission(FileSystem fs,
    String path, FsPermission expected) throws IOException {
  FileStatus s = fs.getFileStatus(new Path(path));
  LOG.info(s.getPath() + ": " + s.isDirectory() + " " + s.getPermission()
      + ":" + s.getOwner() + ":" + s.getGroup());
  if (expected != null) {
    assertEquals(expected, s.getPermission());
    assertEquals(expected.toShort(), s.getPermission().toShort());
  }
  return s.getPermission();
}
 
Example 8
Source File: ChmodParser.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Apply permission against specified file and determine what the
 * new mode would be
 * @param file File against which to apply mode
 * @return File's new mode if applied.
 */
public short applyNewPermission(FileStatus file) {
  FsPermission perms = file.getPermission();
  int existing = perms.toShort();
  boolean exeOk = file.isDirectory() || (existing & 0111) != 0;
  
  return (short)combineModes(existing, exeOk);
}
 
Example 9
Source File: ContainerFileSystem.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Transform remote file status to local.
 */
private static FileStatus transform(FileStatus input, String containerName) {
  return new FileStatus(input.getLen(),
          input.isDirectory(),
          input.getReplication(),
          input.getBlockSize(),
          input.getModificationTime(),
          input.getAccessTime(),
          input.getPermission(),
          input.getOwner(),
          input.getGroup(),
          transform(input.getPath(), containerName));
}
 
Example 10
Source File: RemoteNodeFileSystem.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a Hadoop {@link FileStatus} instance into a protobuf
 * {@link DFSProtos.FileStatus}
 *
 * @param status
 *          the Hadoop status instance to convert
 * @return a protobuf status instance
 * @throws IOException
 */
static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException {
  DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder();

  builder
    .setLength(status.getLen())
    .setIsDirectory(status.isDirectory())
    .setBlockReplication(status.getReplication())
    .setBlockSize(status.getBlockSize())
    .setModificationTime(status.getModificationTime())
    .setAccessTime(status.getAccessTime());

  // Handling potential null values
  if (status.getPath() != null) {
    builder = builder.setPath(status.getPath().toUri().getPath());
  }
  if (status.getPermission() != null) {
    builder = builder.setPermission(status.getPermission().toExtendedShort());
  }
  if (status.getOwner() != null) {
    builder = builder.setOwner(status.getOwner());
  }
  if (status.getGroup() != null) {
    builder = builder.setGroup(status.getGroup());
  }
  if (status.isSymlink()) {
    builder = builder.setSymlink(status.getSymlink().toString());
  }

  return builder.build();
}
 
Example 11
Source File: InstrumentedFileSystemUtils.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Replace the scheme of the input {@link FileStatus} if it matches the string to replace.
 */
public static FileStatus replaceScheme(FileStatus st, String replace, String replacement) {
  if (replace != null && replace.equals(replacement)) {
    return st;
  }
  try {
    return new FileStatus(st.getLen(), st.isDir(), st.getReplication(), st.getBlockSize(), st.getModificationTime(),
        st.getAccessTime(), st.getPermission(), st.getOwner(), st.getGroup(), st.isSymlink() ? st.getSymlink() : null,
        replaceScheme(st.getPath(), replace, replacement));
  } catch (IOException ioe) {
    throw new RuntimeException(ioe);
  }
}
 
Example 12
Source File: JavaKeyStoreProvider.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
protected void stashOriginalFilePermissions() throws IOException {
  // save off permissions in case we need to
  // rewrite the keystore in flush()
  FileStatus s = fs.getFileStatus(getPath());
  permissions = s.getPermission();
}
 
Example 13
Source File: ClientDistributedCacheManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Checks for a given path whether the Other permissions on it 
 * imply the permission in the passed FsAction
 * @param fs
 * @param path
 * @param action
 * @return true if the path in the uri is visible to all, false otherwise
 * @throws IOException
 */
private static boolean checkPermissionOfOther(FileSystem fs, Path path,
    FsAction action, Map<URI, FileStatus> statCache) throws IOException {
  FileStatus status = getFileStatus(fs, path.toUri(), statCache);
  FsPermission perms = status.getPermission();
  FsAction otherAction = perms.getOtherAction();
  if (otherAction.implies(action)) {
    return true;
  }
  return false;
}
 
Example 14
Source File: TestPermission.java    From hadoop with Apache License 2.0 5 votes vote down vote up
static FsPermission checkPermission(FileSystem fs,
    String path, FsPermission expected) throws IOException {
  FileStatus s = fs.getFileStatus(new Path(path));
  LOG.info(s.getPath() + ": " + s.isDirectory() + " " + s.getPermission()
      + ":" + s.getOwner() + ":" + s.getGroup());
  if (expected != null) {
    assertEquals(expected, s.getPermission());
    assertEquals(expected.toShort(), s.getPermission().toShort());
  }
  return s.getPermission();
}
 
Example 15
Source File: FileStatusEntity.java    From eagle with Apache License 2.0 5 votes vote down vote up
public FileStatusEntity(FileStatus status) throws IOException {
    //this.path = status.getPath();
    this.length = status.getLen();
    this.isdir = status.isDirectory();
    this.block_replication = status.getReplication();
    this.blocksize = status.getBlockSize();
    this.modification_time = status.getModificationTime();
    this.access_time = status.getAccessTime();
    this.permission = status.getPermission();
    this.owner = status.getOwner();
    this.group = status.getGroup();
    if(status.isSymlink()) {
        this.symlink = status.getSymlink();
    }
}
 
Example 16
Source File: JavaKeyStoreProvider.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
protected void stashOriginalFilePermissions() throws IOException {
  // save off permissions in case we need to
  // rewrite the keystore in flush()
  FileStatus s = fs.getFileStatus(getPath());
  permissions = s.getPermission();
}
 
Example 17
Source File: TestDistCh.java    From hadoop with Apache License 2.0 4 votes vote down vote up
ChPermissionStatus(FileStatus filestatus, String owner, String group, String permission) {
  super("".equals(owner)? filestatus.getOwner(): owner, 
      "".equals(group)? filestatus.getGroup(): group,
      "".equals(permission)? filestatus.getPermission(): new FsPermission(Short.parseShort(permission, 8)));
  defaultPerm = permission == null || "".equals(permission);
}
 
Example 18
Source File: TestDistCh.java    From big-c with Apache License 2.0 4 votes vote down vote up
ChPermissionStatus(FileStatus filestatus, String owner, String group, String permission) {
  super("".equals(owner)? filestatus.getOwner(): owner, 
      "".equals(group)? filestatus.getGroup(): group,
      "".equals(permission)? filestatus.getPermission(): new FsPermission(Short.parseShort(permission, 8)));
  defaultPerm = permission == null || "".equals(permission);
}
 
Example 19
Source File: TestDistCh.java    From hadoop-gpu with Apache License 2.0 4 votes vote down vote up
ChPermissionStatus(FileStatus filestatus, String owner, String group, String permission) {
  super("".equals(owner)? filestatus.getOwner(): owner, 
      "".equals(group)? filestatus.getGroup(): group,
      "".equals(permission)? filestatus.getPermission(): new FsPermission(Short.parseShort(permission, 8)));
}
 
Example 20
Source File: FSDownload.java    From hadoop with Apache License 2.0 3 votes vote down vote up
/**
 * Checks for a given path whether the Other permissions on it 
 * imply the permission in the passed FsAction
 * @param fs
 * @param path
 * @param action
 * @return true if the path in the uri is visible to all, false otherwise
 * @throws IOException
 */
private static boolean checkPermissionOfOther(FileSystem fs, Path path,
    FsAction action, LoadingCache<Path,Future<FileStatus>> statCache)
    throws IOException {
  FileStatus status = getFileStatus(fs, path, statCache);
  FsPermission perms = status.getPermission();
  FsAction otherAction = perms.getOtherAction();
  return otherAction.implies(action);
}