Java Code Examples for org.apache.hadoop.hdfs.DFSUtil#isValidName()

The following examples show how to use org.apache.hadoop.hdfs.DFSUtil#isValidName() . 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: FSDirStatAndListingOp.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Get the file info for a specific file.
 *
 * @param srcArg The string representation of the path to the file
 * @param resolveLink whether to throw UnresolvedLinkException
 *        if src refers to a symlink
 *
 * @return object containing information regarding the file
 *         or null if file not found
 */
static HdfsFileStatus getFileInfo(
    FSDirectory fsd, String srcArg, boolean resolveLink)
    throws IOException {
  String src = srcArg;
  if (!DFSUtil.isValidName(src)) {
    throw new InvalidPathException("Invalid file name: " + src);
  }
  FSPermissionChecker pc = fsd.getPermissionChecker();
  byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);
  src = fsd.resolvePath(pc, src, pathComponents);
  final INodesInPath iip = fsd.getINodesInPath(src, resolveLink);
  boolean isSuperUser = true;
  if (fsd.isPermissionEnabled()) {
    fsd.checkPermission(pc, iip, false, null, null, null, null, false);
    isSuperUser = pc.isSuperUser();
  }
  return getFileInfo(fsd, src, resolveLink,
      FSDirectory.isReservedRawName(srcArg), isSuperUser);
}
 
Example 2
Source File: FSDirStatAndListingOp.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Get the file info for a specific file.
 *
 * @param srcArg The string representation of the path to the file
 * @param resolveLink whether to throw UnresolvedLinkException
 *        if src refers to a symlink
 *
 * @return object containing information regarding the file
 *         or null if file not found
 */
static HdfsFileStatus getFileInfo(
    FSDirectory fsd, String srcArg, boolean resolveLink)
    throws IOException {
  String src = srcArg;
  if (!DFSUtil.isValidName(src)) {
    throw new InvalidPathException("Invalid file name: " + src);
  }
  FSPermissionChecker pc = fsd.getPermissionChecker();
  byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);
  src = fsd.resolvePath(pc, src, pathComponents);
  final INodesInPath iip = fsd.getINodesInPath(src, resolveLink);
  boolean isSuperUser = true;
  if (fsd.isPermissionEnabled()) {
    fsd.checkPermission(pc, iip, false, null, null, null, null, false);
    isSuperUser = pc.isSuperUser();
  }
  return getFileInfo(fsd, src, resolveLink,
      FSDirectory.isReservedRawName(srcArg), isSuperUser);
}
 
Example 3
Source File: FSNamesystem.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
private synchronized boolean renameToInternal(String src, String dst
    ) throws IOException {
  NameNode.stateChangeLog.debug("DIR* NameSystem.renameTo: " + src + " to " + dst);
  if (isInSafeMode())
    throw new SafeModeException("Cannot rename " + src, safeMode);
  if (!DFSUtil.isValidName(dst)) {
    throw new IOException("Invalid name: " + dst);
  }

  if (isPermissionEnabled) {
    //We should not be doing this.  This is move() not renameTo().
    //but for now,
    String actualdst = dir.isDir(dst)?
        dst + Path.SEPARATOR + new Path(src).getName(): dst;
    checkParentAccess(src, FsAction.WRITE);
    checkAncestorAccess(actualdst, FsAction.WRITE);
  }

  FileStatus dinfo = dir.getFileInfo(dst);
  if (dir.renameTo(src, dst)) {
    changeLease(src, dst, dinfo);     // update lease with new filename
    return true;
  }
  return false;
}
 
Example 4
Source File: WebHdfsFileSystem.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void setWorkingDirectory(final Path dir) {
  String result = makeAbsolute(dir).toUri().getPath();
  if (!DFSUtil.isValidName(result)) {
    throw new IllegalArgumentException("Invalid DFS directory name " + 
                                       result);
  }
  workingDir = makeAbsolute(dir);
}
 
Example 5
Source File: FSDirRenameOp.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Deprecated
static RenameOldResult renameToInt(
    FSDirectory fsd, final String srcArg, final String dstArg,
    boolean logRetryCache)
    throws IOException {
  String src = srcArg;
  String dst = dstArg;
  if (NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* NameSystem.renameTo: " + src +
        " to " + dst);
  }
  if (!DFSUtil.isValidName(dst)) {
    throw new IOException("Invalid name: " + dst);
  }
  FSPermissionChecker pc = fsd.getPermissionChecker();

  byte[][] srcComponents = FSDirectory.getPathComponentsForReservedPath(src);
  byte[][] dstComponents = FSDirectory.getPathComponentsForReservedPath(dst);
  HdfsFileStatus resultingStat = null;
  src = fsd.resolvePath(pc, src, srcComponents);
  dst = fsd.resolvePath(pc, dst, dstComponents);
  @SuppressWarnings("deprecation")
  final boolean status = renameTo(fsd, pc, src, dst, logRetryCache);
  if (status) {
    INodesInPath dstIIP = fsd.getINodesInPath(dst, false);
    resultingStat = fsd.getAuditFileInfo(dstIIP);
  }
  return new RenameOldResult(status, resultingStat);
}
 
Example 6
Source File: FSDirRenameOp.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * The new rename which has the POSIX semantic.
 */
static Map.Entry<BlocksMapUpdateInfo, HdfsFileStatus> renameToInt(
    FSDirectory fsd, final String srcArg, final String dstArg,
    boolean logRetryCache, Options.Rename... options)
    throws IOException {
  String src = srcArg;
  String dst = dstArg;
  if (NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* NameSystem.renameTo: with options -" +
        " " + src + " to " + dst);
  }
  if (!DFSUtil.isValidName(dst)) {
    throw new InvalidPathException("Invalid name: " + dst);
  }
  final FSPermissionChecker pc = fsd.getPermissionChecker();

  byte[][] srcComponents = FSDirectory.getPathComponentsForReservedPath(src);
  byte[][] dstComponents = FSDirectory.getPathComponentsForReservedPath(dst);
  BlocksMapUpdateInfo collectedBlocks = new BlocksMapUpdateInfo();
  src = fsd.resolvePath(pc, src, srcComponents);
  dst = fsd.resolvePath(pc, dst, dstComponents);
  renameTo(fsd, pc, src, dst, collectedBlocks, logRetryCache, options);
  INodesInPath dstIIP = fsd.getINodesInPath(dst, false);
  HdfsFileStatus resultingStat = fsd.getAuditFileInfo(dstIIP);

  return new AbstractMap.SimpleImmutableEntry<>(
      collectedBlocks, resultingStat);
}
 
Example 7
Source File: CacheManager.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static String validatePath(CacheDirectiveInfo directive)
    throws InvalidRequestException {
  if (directive.getPath() == null) {
    throw new InvalidRequestException("No path specified.");
  }
  String path = directive.getPath().toUri().getPath();
  if (!DFSUtil.isValidName(path)) {
    throw new InvalidRequestException("Invalid path '" + path + "'.");
  }
  return path;
}
 
Example 8
Source File: CacheRegistry.java    From nnproxy with Apache License 2.0 5 votes vote down vote up
private static String validatePath(CacheDirectiveInfo directive)
        throws InvalidRequestException {
    if (directive.getPath() == null) {
        throw new InvalidRequestException("No path specified.");
    }
    String path = directive.getPath().toUri().getPath();
    if (!DFSUtil.isValidName(path)) {
        throw new InvalidRequestException("Invalid path '" + path + "'.");
    }
    return path;
}
 
Example 9
Source File: WebHdfsFileSystem.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void setWorkingDirectory(final Path dir) {
  String result = makeAbsolute(dir).toUri().getPath();
  if (!DFSUtil.isValidName(result)) {
    throw new IllegalArgumentException("Invalid DFS directory name " + 
                                       result);
  }
  workingDir = makeAbsolute(dir);
}
 
Example 10
Source File: FSDirRenameOp.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Deprecated
static RenameOldResult renameToInt(
    FSDirectory fsd, final String srcArg, final String dstArg,
    boolean logRetryCache)
    throws IOException {
  String src = srcArg;
  String dst = dstArg;
  if (NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* NameSystem.renameTo: " + src +
        " to " + dst);
  }
  if (!DFSUtil.isValidName(dst)) {
    throw new IOException("Invalid name: " + dst);
  }
  FSPermissionChecker pc = fsd.getPermissionChecker();

  byte[][] srcComponents = FSDirectory.getPathComponentsForReservedPath(src);
  byte[][] dstComponents = FSDirectory.getPathComponentsForReservedPath(dst);
  HdfsFileStatus resultingStat = null;
  src = fsd.resolvePath(pc, src, srcComponents);
  dst = fsd.resolvePath(pc, dst, dstComponents);
  @SuppressWarnings("deprecation")
  final boolean status = renameTo(fsd, pc, src, dst, logRetryCache);
  if (status) {
    INodesInPath dstIIP = fsd.getINodesInPath(dst, false);
    resultingStat = fsd.getAuditFileInfo(dstIIP);
  }
  return new RenameOldResult(status, resultingStat);
}
 
Example 11
Source File: FSDirRenameOp.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * The new rename which has the POSIX semantic.
 */
static Map.Entry<BlocksMapUpdateInfo, HdfsFileStatus> renameToInt(
    FSDirectory fsd, final String srcArg, final String dstArg,
    boolean logRetryCache, Options.Rename... options)
    throws IOException {
  String src = srcArg;
  String dst = dstArg;
  if (NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* NameSystem.renameTo: with options -" +
        " " + src + " to " + dst);
  }
  if (!DFSUtil.isValidName(dst)) {
    throw new InvalidPathException("Invalid name: " + dst);
  }
  final FSPermissionChecker pc = fsd.getPermissionChecker();

  byte[][] srcComponents = FSDirectory.getPathComponentsForReservedPath(src);
  byte[][] dstComponents = FSDirectory.getPathComponentsForReservedPath(dst);
  BlocksMapUpdateInfo collectedBlocks = new BlocksMapUpdateInfo();
  src = fsd.resolvePath(pc, src, srcComponents);
  dst = fsd.resolvePath(pc, dst, dstComponents);
  renameTo(fsd, pc, src, dst, collectedBlocks, logRetryCache, options);
  INodesInPath dstIIP = fsd.getINodesInPath(dst, false);
  HdfsFileStatus resultingStat = fsd.getAuditFileInfo(dstIIP);

  return new AbstractMap.SimpleImmutableEntry<>(
      collectedBlocks, resultingStat);
}
 
Example 12
Source File: CacheManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static String validatePath(CacheDirectiveInfo directive)
    throws InvalidRequestException {
  if (directive.getPath() == null) {
    throw new InvalidRequestException("No path specified.");
  }
  String path = directive.getPath().toUri().getPath();
  if (!DFSUtil.isValidName(path)) {
    throw new InvalidRequestException("Invalid path '" + path + "'.");
  }
  return path;
}
 
Example 13
Source File: IgniteHadoopFileSystem.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void setWorkingDirectory(Path newPath) {
    if (newPath == null)
        workingDir = getHomeDirectory();
    else {
        Path fixedNewPath = fixRelativePart(newPath);

        String res = fixedNewPath.toUri().getPath();

        if (!DFSUtil.isValidName(res))
            throw new IllegalArgumentException("Invalid DFS directory name " + res);

        workingDir = fixedNewPath;
    }
}
 
Example 14
Source File: FSNamesystem.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * Create all the necessary directories
 */
private synchronized boolean mkdirsInternal(String src,
    PermissionStatus permissions) throws IOException {
  NameNode.stateChangeLog.debug("DIR* NameSystem.mkdirs: " + src);
  if (isPermissionEnabled) {
    checkTraverse(src);
  }
  if (dir.isDir(src)) {
    // all the users of mkdirs() are used to expect 'true' even if
    // a new directory is not created.
    return true;
  }
  if (isInSafeMode())
    throw new SafeModeException("Cannot create directory " + src, safeMode);
  if (!DFSUtil.isValidName(src)) {
    throw new IOException("Invalid directory name: " + src);
  }
  if (isPermissionEnabled) {
    checkAncestorAccess(src, FsAction.WRITE);
  }

  // validate that we have enough inodes. This is, at best, a 
  // heuristic because the mkdirs() operation migth need to 
  // create multiple inodes.
  checkFsObjectLimit();

  if (!dir.mkdirs(src, permissions, false, now())) {
    throw new IOException("Invalid directory name: " + src);
  }
  return true;
}
 
Example 15
Source File: FSDirSymlinkOp.java    From hadoop with Apache License 2.0 4 votes vote down vote up
static HdfsFileStatus createSymlinkInt(
    FSNamesystem fsn, String target, final String linkArg,
    PermissionStatus dirPerms, boolean createParent, boolean logRetryCache)
    throws IOException {
  FSDirectory fsd = fsn.getFSDirectory();
  String link = linkArg;
  if (!DFSUtil.isValidName(link)) {
    throw new InvalidPathException("Invalid link name: " + link);
  }
  if (FSDirectory.isReservedName(target) || target.isEmpty()) {
    throw new InvalidPathException("Invalid target name: " + target);
  }

  if (NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* NameSystem.createSymlink: target="
        + target + " link=" + link);
  }

  FSPermissionChecker pc = fsn.getPermissionChecker();
  byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(link);
  INodesInPath iip;
  fsd.writeLock();
  try {
    link = fsd.resolvePath(pc, link, pathComponents);
    iip = fsd.getINodesInPath4Write(link, false);
    if (!createParent) {
      fsd.verifyParentDir(iip, link);
    }
    if (!fsd.isValidToCreate(link, iip)) {
      throw new IOException(
          "failed to create link " + link +
              " either because the filename is invalid or the file exists");
    }
    if (fsd.isPermissionEnabled()) {
      fsd.checkAncestorAccess(pc, iip, FsAction.WRITE);
    }
    // validate that we have enough inodes.
    fsn.checkFsObjectLimit();

    // add symbolic link to namespace
    addSymlink(fsd, link, iip, target, dirPerms, createParent, logRetryCache);
  } finally {
    fsd.writeUnlock();
  }
  NameNode.getNameNodeMetrics().incrCreateSymlinkOps();
  return fsd.getAuditFileInfo(iip);
}
 
Example 16
Source File: FSDirSymlinkOp.java    From big-c with Apache License 2.0 4 votes vote down vote up
static HdfsFileStatus createSymlinkInt(
    FSNamesystem fsn, String target, final String linkArg,
    PermissionStatus dirPerms, boolean createParent, boolean logRetryCache)
    throws IOException {
  FSDirectory fsd = fsn.getFSDirectory();
  String link = linkArg;
  if (!DFSUtil.isValidName(link)) {
    throw new InvalidPathException("Invalid link name: " + link);
  }
  if (FSDirectory.isReservedName(target) || target.isEmpty()) {
    throw new InvalidPathException("Invalid target name: " + target);
  }

  if (NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* NameSystem.createSymlink: target="
        + target + " link=" + link);
  }

  FSPermissionChecker pc = fsn.getPermissionChecker();
  byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(link);
  INodesInPath iip;
  fsd.writeLock();
  try {
    link = fsd.resolvePath(pc, link, pathComponents);
    iip = fsd.getINodesInPath4Write(link, false);
    if (!createParent) {
      fsd.verifyParentDir(iip, link);
    }
    if (!fsd.isValidToCreate(link, iip)) {
      throw new IOException(
          "failed to create link " + link +
              " either because the filename is invalid or the file exists");
    }
    if (fsd.isPermissionEnabled()) {
      fsd.checkAncestorAccess(pc, iip, FsAction.WRITE);
    }
    // validate that we have enough inodes.
    fsn.checkFsObjectLimit();

    // add symbolic link to namespace
    addSymlink(fsd, link, iip, target, dirPerms, createParent, logRetryCache);
  } finally {
    fsd.writeUnlock();
  }
  NameNode.getNameNodeMetrics().incrCreateSymlinkOps();
  return fsd.getAuditFileInfo(iip);
}