Fix stopping condition when deleting parent dirs

pull/719/head
Andrew Gaul 2024-12-01 22:48:29 -08:00
rodzic 7632e9cc3e
commit 9cc91bd014
1 zmienionych plików z 6 dodań i 4 usunięć

Wyświetl plik

@ -682,9 +682,10 @@ public abstract class AbstractNio2BlobStore extends BaseBlobStore {
@Override @Override
public final void removeBlob(String container, String key) { public final void removeBlob(String container, String key) {
try { try {
var path = root.resolve(container).resolve(key); var containerPath = root.resolve(container);
var path = containerPath.resolve(key);
Files.delete(path); Files.delete(path);
removeEmptyParentDirectories(path.getParent()); removeEmptyParentDirectories(containerPath, path.getParent());
} catch (NoSuchFileException nsfe) { } catch (NoSuchFileException nsfe) {
return; return;
} catch (IOException ioe) { } catch (IOException ioe) {
@ -1071,10 +1072,11 @@ public abstract class AbstractNio2BlobStore extends BaseBlobStore {
* AbstractNio2BlobStore implicitly creates directories when creating a key /a/b/c. * AbstractNio2BlobStore implicitly creates directories when creating a key /a/b/c.
* When removing /a/b/c, it must clean up /a and /a/b, unless a client explicitly created a subdirectory which has file attributes. * When removing /a/b/c, it must clean up /a and /a/b, unless a client explicitly created a subdirectory which has file attributes.
*/ */
private static void removeEmptyParentDirectories(Path path) throws IOException { private static void removeEmptyParentDirectories(Path containerPath, Path path) throws IOException {
logger.debug("removing empty parents: {}", path);
while (true) { while (true) {
var parent = path.getParent(); var parent = path.getParent();
if (parent == null || parent.equals(path.getRoot())) { if (parent == null || path.equals(containerPath)) {
break; break;
} }
var view = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class); var view = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class);