int _createFile(boolean recursive, TachyonURI path, boolean directory, long blockSizeByte,
long creationTimeMs) throws FileAlreadyExistException, InvalidPathException,
BlockInfoException, TachyonException {
if (path.isRoot()) {
LOG.info("FileAlreadyExistException: " + path);
throw new FileAlreadyExistException(path.toString());
}
if (!directory && blockSizeByte < 1) {
throw new BlockInfoException("Invalid block size " + blockSizeByte);
}
LOG.debug("createFile {}", CommonUtils.parametersToString(path));
String[] pathNames = CommonUtils.getPathComponents(path.toString());
String name = path.getName();
String[] parentPath = new String[pathNames.length - 1];
System.arraycopy(pathNames, 0, parentPath, 0, parentPath.length);
synchronized (mRootLock) {
Pair<Inode, Integer> inodeTraversal = traverseToInode(parentPath);
// pathIndex is the index into pathNames where we start filling in the path from the inode.
int pathIndex = parentPath.length;
if (!traversalSucceeded(inodeTraversal)) {
// Then the path component at errorInd k doesn't exist. If it's not recursive, we throw an
// exception here. Otherwise we add the remaining path components to the list of components
// to create.
if (!recursive) {
final String msg =
"File " + path + " creation failed. Component " + inodeTraversal.getSecond() + "("
+ parentPath[inodeTraversal.getSecond()] + ") does not exist";
LOG.info("InvalidPathException: " + msg);
throw new InvalidPathException(msg);
} else {
// We will start filling in the path from inodeTraversal.getSecond()
pathIndex = inodeTraversal.getSecond();
}
}
if (!inodeTraversal.getFirst().isDirectory()) {
throw new InvalidPathException("Could not traverse to parent folder of path " + path
+ ". Component " + pathNames[pathIndex - 1] + " is not a directory.");
}
InodeFolder currentInodeFolder = (InodeFolder) inodeTraversal.getFirst();
// Fill in the directories that were missing.
for (int k = pathIndex; k < parentPath.length; k ++) {
Inode dir =
new InodeFolder(pathNames[k], mInodeCounter.incrementAndGet(),
currentInodeFolder.getId(), creationTimeMs);
dir.setPinned(currentInodeFolder.isPinned());
currentInodeFolder.addChild(dir);
currentInodeFolder.setLastModificationTimeMs(creationTimeMs);
mFileIdToInodes.put(dir.getId(), dir);
currentInodeFolder = (InodeFolder) dir;
}
// Create the final path component. First we need to make sure that there isn't already a file
// here with that name. If there is an existing file that is a directory and we're creating a
// directory, we just return the existing directory's id.
Inode ret = currentInodeFolder.getChild(name);
if (ret != null) {
if (ret.isDirectory() && directory) {
return ret.getId();
}
LOG.info("FileAlreadyExistException: " + path);
throw new FileAlreadyExistException(path.toString());
}
if (directory) {
ret =
new InodeFolder(name, mInodeCounter.incrementAndGet(), currentInodeFolder.getId(),
creationTimeMs);