Skip to content

Commit

Permalink
Fix parent directory creation in distcp-ng
Browse files Browse the repository at this point in the history
  • Loading branch information
pcadabam-zz committed Jan 29, 2016
1 parent 061c715 commit c9bbf00
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,8 @@ public void commit() throws IOException {

Iterator<OwnerAndPermission> ancestorOwnerAndPermissionIt = copyableFile.getAncestorsOwnerAndPermission() == null ?
Iterators.<OwnerAndPermission>emptyIterator() : copyableFile.getAncestorsOwnerAndPermission().iterator();
if (!ensureDirectoryExists(this.fs, outputFilePath.getParent(), ancestorOwnerAndPermissionIt)) {
throw new IOException(String.format("Could not create ancestors for %s", outputFilePath));
}

ensureDirectoryExists(this.fs, outputFilePath.getParent(), ancestorOwnerAndPermissionIt);

if (!this.fs.rename(stagingFilePath, outputFilePath)) {
// target exists
Expand All @@ -297,11 +296,11 @@ public void commit() throws IOException {
}
}

private boolean ensureDirectoryExists(FileSystem fs, Path path,
private void ensureDirectoryExists(FileSystem fs, Path path,
Iterator<OwnerAndPermission> ownerAndPermissionIterator) throws IOException {

if (fs.exists(path)) {
return true;
return;
}

if (ownerAndPermissionIterator.hasNext()) {
Expand All @@ -312,11 +311,13 @@ private boolean ensureDirectoryExists(FileSystem fs, Path path,
if (ownerAndPermission.getFsPermission() == null) {
// use default permissions
if (!fs.mkdirs(path)) {
return false;
// fs.mkdirs returns false if path already existed. Do not overwrite permissions
return;
}
} else {
if (!fs.mkdirs(path, addExecutePermissionToOwner(ownerAndPermission.getFsPermission()))) {
return false;
// fs.mkdirs returns false if path already existed. Do not overwrite permissions
return;
}
}
String group = ownerAndPermission.getGroup();
Expand All @@ -325,9 +326,8 @@ private boolean ensureDirectoryExists(FileSystem fs, Path path,
fs.setOwner(path, owner, group);
}
} else {
return fs.mkdirs(path);
fs.mkdirs(path);
}
return true;
}

@Override
Expand Down

0 comments on commit c9bbf00

Please sign in to comment.