Java Code Examples for org.apache.hadoop.fs.permission.AclUtil#getAclFromPermAndEntries()

The following examples show how to use org.apache.hadoop.fs.permission.AclUtil#getAclFromPermAndEntries() . 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: AclCommands.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
protected void processPath(PathData item) throws IOException {
  out.println("# file: " + item);
  out.println("# owner: " + item.stat.getOwner());
  out.println("# group: " + item.stat.getGroup());
  FsPermission perm = item.stat.getPermission();
  if (perm.getStickyBit()) {
    out.println("# flags: --" +
      (perm.getOtherAction().implies(FsAction.EXECUTE) ? "t" : "T"));
  }

  AclStatus aclStatus = item.fs.getAclStatus(item.path);
  List<AclEntry> entries = perm.getAclBit() ? aclStatus.getEntries()
      : Collections.<AclEntry> emptyList();
  ScopedAclEntries scopedEntries = new ScopedAclEntries(
    AclUtil.getAclFromPermAndEntries(perm, entries));
  printAclEntriesForSingleScope(aclStatus, perm,
      scopedEntries.getAccessEntries());
  printAclEntriesForSingleScope(aclStatus, perm,
      scopedEntries.getDefaultEntries());
  out.println();
}
 
Example 2
Source File: AclCommands.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
protected void processPath(PathData item) throws IOException {
  out.println("# file: " + item);
  out.println("# owner: " + item.stat.getOwner());
  out.println("# group: " + item.stat.getGroup());
  FsPermission perm = item.stat.getPermission();
  if (perm.getStickyBit()) {
    out.println("# flags: --" +
      (perm.getOtherAction().implies(FsAction.EXECUTE) ? "t" : "T"));
  }

  AclStatus aclStatus = item.fs.getAclStatus(item.path);
  List<AclEntry> entries = perm.getAclBit() ? aclStatus.getEntries()
      : Collections.<AclEntry> emptyList();
  ScopedAclEntries scopedEntries = new ScopedAclEntries(
    AclUtil.getAclFromPermAndEntries(perm, entries));
  printAclEntriesForSingleScope(aclStatus, perm,
      scopedEntries.getAccessEntries());
  printAclEntriesForSingleScope(aclStatus, perm,
      scopedEntries.getDefaultEntries());
  out.println();
}
 
Example 3
Source File: CommandWithDestination.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Preserve the attributes of the source to the target.
 * The method calls {@link #shouldPreserve(FileAttribute)} to check what
 * attribute to preserve.
 * @param src source to preserve
 * @param target where to preserve attributes
 * @param preserveRawXAttrs true if raw.* xattrs should be preserved
 * @throws IOException if fails to preserve attributes
 */
protected void preserveAttributes(PathData src, PathData target,
    boolean preserveRawXAttrs)
    throws IOException {
  if (shouldPreserve(FileAttribute.TIMESTAMPS)) {
    target.fs.setTimes(
        target.path,
        src.stat.getModificationTime(),
        src.stat.getAccessTime());
  }
  if (shouldPreserve(FileAttribute.OWNERSHIP)) {
    target.fs.setOwner(
        target.path,
        src.stat.getOwner(),
        src.stat.getGroup());
  }
  if (shouldPreserve(FileAttribute.PERMISSION) ||
      shouldPreserve(FileAttribute.ACL)) {
    target.fs.setPermission(
        target.path,
        src.stat.getPermission());
  }
  if (shouldPreserve(FileAttribute.ACL)) {
    FsPermission perm = src.stat.getPermission();
    if (perm.getAclBit()) {
      List<AclEntry> srcEntries =
          src.fs.getAclStatus(src.path).getEntries();
      List<AclEntry> srcFullEntries =
          AclUtil.getAclFromPermAndEntries(perm, srcEntries);
      target.fs.setAcl(target.path, srcFullEntries);
    }
  }
  final boolean preserveXAttrs = shouldPreserve(FileAttribute.XATTR);
  if (preserveXAttrs || preserveRawXAttrs) {
    Map<String, byte[]> srcXAttrs = src.fs.getXAttrs(src.path);
    if (srcXAttrs != null) {
      Iterator<Entry<String, byte[]>> iter = srcXAttrs.entrySet().iterator();
      while (iter.hasNext()) {
        Entry<String, byte[]> entry = iter.next();
        final String xattrName = entry.getKey();
        if (xattrName.startsWith(RAW) || preserveXAttrs) {
          target.fs.setXAttr(target.path, entry.getKey(), entry.getValue());
        }
      }
    }
  }
}
 
Example 4
Source File: CommandWithDestination.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Preserve the attributes of the source to the target.
 * The method calls {@link #shouldPreserve(FileAttribute)} to check what
 * attribute to preserve.
 * @param src source to preserve
 * @param target where to preserve attributes
 * @param preserveRawXAttrs true if raw.* xattrs should be preserved
 * @throws IOException if fails to preserve attributes
 */
protected void preserveAttributes(PathData src, PathData target,
    boolean preserveRawXAttrs)
    throws IOException {
  if (shouldPreserve(FileAttribute.TIMESTAMPS)) {
    target.fs.setTimes(
        target.path,
        src.stat.getModificationTime(),
        src.stat.getAccessTime());
  }
  if (shouldPreserve(FileAttribute.OWNERSHIP)) {
    target.fs.setOwner(
        target.path,
        src.stat.getOwner(),
        src.stat.getGroup());
  }
  if (shouldPreserve(FileAttribute.PERMISSION) ||
      shouldPreserve(FileAttribute.ACL)) {
    target.fs.setPermission(
        target.path,
        src.stat.getPermission());
  }
  if (shouldPreserve(FileAttribute.ACL)) {
    FsPermission perm = src.stat.getPermission();
    if (perm.getAclBit()) {
      List<AclEntry> srcEntries =
          src.fs.getAclStatus(src.path).getEntries();
      List<AclEntry> srcFullEntries =
          AclUtil.getAclFromPermAndEntries(perm, srcEntries);
      target.fs.setAcl(target.path, srcFullEntries);
    }
  }
  final boolean preserveXAttrs = shouldPreserve(FileAttribute.XATTR);
  if (preserveXAttrs || preserveRawXAttrs) {
    Map<String, byte[]> srcXAttrs = src.fs.getXAttrs(src.path);
    if (srcXAttrs != null) {
      Iterator<Entry<String, byte[]>> iter = srcXAttrs.entrySet().iterator();
      while (iter.hasNext()) {
        Entry<String, byte[]> entry = iter.next();
        final String xattrName = entry.getKey();
        if (xattrName.startsWith(RAW) || preserveXAttrs) {
          target.fs.setXAttr(target.path, entry.getKey(), entry.getValue());
        }
      }
    }
  }
}
 
Example 5
Source File: DistCpUtils.java    From hadoop with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a file's full logical ACL.
 *
 * @param fileSystem FileSystem containing the file
 * @param fileStatus FileStatus of file
 * @return List containing full logical ACL
 * @throws IOException if there is an I/O error
 */
public static List<AclEntry> getAcl(FileSystem fileSystem,
    FileStatus fileStatus) throws IOException {
  List<AclEntry> entries = fileSystem.getAclStatus(fileStatus.getPath())
    .getEntries();
  return AclUtil.getAclFromPermAndEntries(fileStatus.getPermission(), entries);
}
 
Example 6
Source File: DistCpUtils.java    From big-c with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a file's full logical ACL.
 *
 * @param fileSystem FileSystem containing the file
 * @param fileStatus FileStatus of file
 * @return List containing full logical ACL
 * @throws IOException if there is an I/O error
 */
public static List<AclEntry> getAcl(FileSystem fileSystem,
    FileStatus fileStatus) throws IOException {
  List<AclEntry> entries = fileSystem.getAclStatus(fileStatus.getPath())
    .getEntries();
  return AclUtil.getAclFromPermAndEntries(fileStatus.getPermission(), entries);
}
 
Example 7
Source File: CopyListingFileStatus.java    From circus-train with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the full logical ACL.
 *
 * @return List<AclEntry> containing full logical ACL
 */
public List<AclEntry> getAclEntries() {
  return AclUtil
      .getAclFromPermAndEntries(getPermission(), aclEntries != null ? aclEntries : Collections.<AclEntry>emptyList());
}
 
Example 8
Source File: CopyListingFileStatus.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the full logical ACL.
 *
 * @return List containing full logical ACL
 */
public List<AclEntry> getAclEntries() {
  return AclUtil.getAclFromPermAndEntries(getPermission(),
    aclEntries != null ? aclEntries : Collections.<AclEntry>emptyList());
}
 
Example 9
Source File: CopyListingFileStatus.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the full logical ACL.
 *
 * @return List containing full logical ACL
 */
public List<AclEntry> getAclEntries() {
  return AclUtil.getAclFromPermAndEntries(getPermission(),
    aclEntries != null ? aclEntries : Collections.<AclEntry>emptyList());
}