Skip to content

Commit

Permalink
Maybe possibly work now
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Aug 13, 2023
1 parent f0ee75d commit 7986e00
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public void moveFile(final String oldPath, final String newPath) throws IOExcept

@Override
public void move(final String oldPath, final String newPath) throws IOException {
System.out.println(oldPath + " -> " + newPath);
if (!oldPath.startsWith(this.getRoot()) && newPath.startsWith(this.getRoot())) {
// upload from file to s3
this.write(Files.newInputStream(Path.of(oldPath)), newPath, null);
Expand All @@ -100,8 +99,7 @@ public void move(final String oldPath, final String newPath) throws IOException
final String sourceDirectory = oldPath.replace(this.getRoot(), "");
final String destinationDirectory = newPath.replace(this.getRoot(), "");
for (final S3Object object : this.s3Client.listObjectsV2Paginator(builder -> builder.bucket(this.config.bucket()).prefix(sourceDirectory)).contents()) {
final String sourceKey = object.key();
System.out.println(sourceKey + " -> " + sourceKey.replace(sourceDirectory, destinationDirectory));
final String sourceKey = object.key().replace(this.getRoot(), "");
this.s3Client.copyObject(builder -> builder
.sourceBucket(this.config.bucket())
.sourceKey(sourceKey)
Expand All @@ -111,7 +109,8 @@ public void move(final String oldPath, final String newPath) throws IOException
}

for (final S3Object object : this.s3Client.listObjectsV2Paginator(builder -> builder.bucket(this.config.bucket()).prefix(sourceDirectory)).contents()) {
this.s3Client.deleteObject(builder -> builder.bucket(this.config.bucket()).key(object.key()));
final String key = object.key().replace(this.getRoot(), "");
this.s3Client.deleteObject(builder -> builder.bucket(this.config.bucket()).key(key));
}
} else {
throw new UnsupportedOperationException("cant move " + oldPath + " to " + newPath);
Expand Down

0 comments on commit 7986e00

Please sign in to comment.