Skip to content

Commit

Permalink
add rename internal
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinjia committed May 6, 2015
1 parent fc556f2 commit 834e0e9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions underfs/s3/src/main/java/tachyon/underfs/s3/S3UnderFileSystem.java
Expand Up @@ -220,13 +220,14 @@ public boolean rename(String src, String dst) throws IOException {
if (exists(dst)) {
if (!isFolder(dst)) {
LOG.error("Unable to rename " + src + " to " + dst + " because destination already "
+ "exists as a file");
+ "exists as a file.");
return false;
}
// Destination is a folder, move source into dst
if (!isFolder(src)) {
// Source is a file
S3Object obj = new S3Object(src);
String srcName = getKeyName(src);
renameInternal(src, dst);
}
}
if (isFolder(src)) {
Expand Down Expand Up @@ -377,6 +378,17 @@ private boolean mkdir(String key) {
}
}

private boolean renameInternal(String src, String dst) {
try {
S3Object obj = new S3Object(dst);
mClient.copyObject(mBucketName, src, mBucketName, obj, false);
return true;
} catch (ServiceException se) {
LOG.error("Failed to rename file " + src + " to " + dst);
return false;
}
}

/**
* Transforms JetS3t's Service Exceptions to IOExceptions
* @throws IOException
Expand Down

0 comments on commit 834e0e9

Please sign in to comment.