* @throws InvalidPathException if the source path is a prefix of the destination
*/
public boolean _rename(int fileId, TachyonURI dstPath, long opTimeMs)
throws FileDoesNotExistException, InvalidPathException {
synchronized (mRootLock) {
TachyonURI srcPath = getPath(fileId);
if (srcPath.equals(dstPath)) {
return true;
}
if (srcPath.isRoot() || dstPath.isRoot()) {
return false;
}
String[] srcComponents = CommonUtils.getPathComponents(srcPath.toString());
String[] dstComponents = CommonUtils.getPathComponents(dstPath.toString());
// We can't rename a path to one of its subpaths, so we check for that, by making sure
// srcComponents isn't a prefix of dstComponents.
if (srcComponents.length < dstComponents.length) {
boolean isPrefix = true;
for (int prefixInd = 0; prefixInd < srcComponents.length; prefixInd ++) {
if (!srcComponents[prefixInd].equals(dstComponents[prefixInd])) {
isPrefix = false;
break;
}
}
if (isPrefix) {
throw new InvalidPathException("Failed to rename: " + srcPath + " is a prefix of "
+ dstPath);
}
}
TachyonURI srcParent = srcPath.getParent();
TachyonURI dstParent = dstPath.getParent();
// We traverse down to the source and destinations' parent paths
Inode srcParentInode = getInode(srcParent);
if (srcParentInode == null || !srcParentInode.isDirectory()) {
return false;