Skip to content

Commit

Permalink
Attempt to fix dir moving again, fix hard deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Aug 13, 2023
1 parent 7986e00 commit 306fa09
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public boolean exists(final String path) {

@Override
public void deleteDirectory(final String path) {
this.s3Template.deleteObject(path);
final String sourceDirectory = path.replace(this.getRoot(), "");
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()));
}
}

@Override
Expand Down Expand Up @@ -99,17 +102,14 @@ 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().replace(this.getRoot(), "");
this.s3Client.copyObject(builder -> builder
.sourceBucket(this.config.bucket())
.sourceKey(sourceKey)
.sourceKey(object.key())
.destinationBucket(this.config.bucket())
.destinationKey(sourceKey.replace(sourceDirectory, destinationDirectory))
.destinationKey(object.key().replace(sourceDirectory, destinationDirectory))
);
}

for (final S3Object object : this.s3Client.listObjectsV2Paginator(builder -> builder.bucket(this.config.bucket()).prefix(sourceDirectory)).contents()) {
final String key = object.key().replace(this.getRoot(), "");
final String key = object.key();
this.s3Client.deleteObject(builder -> builder.bucket(this.config.bucket()).key(key));
}
} else {
Expand Down

0 comments on commit 306fa09

Please sign in to comment.