|
@@ -44,7 +44,9 @@ import java.nio.file.SimpleFileVisitor;
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
import java.nio.file.StandardOpenOption;
|
|
|
import java.nio.file.attribute.BasicFileAttributes;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
|
@@ -112,24 +114,6 @@ public class FsBlobContainer extends AbstractBlobContainer {
|
|
|
return unmodifiableMap(builder);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void deleteBlob(String blobName) throws IOException {
|
|
|
- Path blobPath = path.resolve(blobName);
|
|
|
- if (Files.isDirectory(blobPath)) {
|
|
|
- // delete directory recursively as long as it is empty (only contains empty directories),
|
|
|
- // which is the reason we aren't deleting any files, only the directories on the post-visit
|
|
|
- Files.walkFileTree(blobPath, new SimpleFileVisitor<>() {
|
|
|
- @Override
|
|
|
- public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
|
|
- Files.delete(dir);
|
|
|
- return FileVisitResult.CONTINUE;
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- Files.delete(blobPath);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public DeleteResult delete() throws IOException {
|
|
|
final AtomicLong filesDeleted = new AtomicLong(0L);
|
|
@@ -153,6 +137,11 @@ public class FsBlobContainer extends AbstractBlobContainer {
|
|
|
return new DeleteResult(filesDeleted.get(), bytesDeleted.get());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void deleteBlobsIgnoringIfNotExists(List<String> blobNames) throws IOException {
|
|
|
+ IOUtils.rm(blobNames.stream().map(path::resolve).toArray(Path[]::new));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public InputStream readBlob(String name) throws IOException {
|
|
|
final Path resolvedPath = path.resolve(name);
|
|
@@ -166,7 +155,7 @@ public class FsBlobContainer extends AbstractBlobContainer {
|
|
|
@Override
|
|
|
public void writeBlob(String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws IOException {
|
|
|
if (failIfAlreadyExists == false) {
|
|
|
- deleteBlobIgnoringIfNotExists(blobName);
|
|
|
+ deleteBlobsIgnoringIfNotExists(Collections.singletonList(blobName));
|
|
|
}
|
|
|
final Path file = path.resolve(blobName);
|
|
|
try (OutputStream outputStream = Files.newOutputStream(file, StandardOpenOption.CREATE_NEW)) {
|
|
@@ -189,7 +178,7 @@ public class FsBlobContainer extends AbstractBlobContainer {
|
|
|
moveBlobAtomic(tempBlob, blobName, failIfAlreadyExists);
|
|
|
} catch (IOException ex) {
|
|
|
try {
|
|
|
- deleteBlobIgnoringIfNotExists(tempBlob);
|
|
|
+ deleteBlobsIgnoringIfNotExists(Collections.singletonList(tempBlob));
|
|
|
} catch (IOException e) {
|
|
|
ex.addSuppressed(e);
|
|
|
}
|
|
@@ -209,7 +198,7 @@ public class FsBlobContainer extends AbstractBlobContainer {
|
|
|
if (failIfAlreadyExists) {
|
|
|
throw new FileAlreadyExistsException("blob [" + targetBlobPath + "] already exists, cannot overwrite");
|
|
|
} else {
|
|
|
- deleteBlobIgnoringIfNotExists(targetBlobName);
|
|
|
+ deleteBlobsIgnoringIfNotExists(Collections.singletonList(targetBlobName));
|
|
|
}
|
|
|
}
|
|
|
Files.move(sourceBlobPath, targetBlobPath, StandardCopyOption.ATOMIC_MOVE);
|