Skip to content

Commit a46e109

Browse files
committed
if there is only a metadata file, delete it.
1 parent 0b93113 commit a46e109

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/java/com/lowtuna/jsonblob/core/BlobDataDirectoryCleaner.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ protected boolean handleDirectory(File directory, int depth, Collection<String>
8181
return false;
8282
}
8383

84+
if (directory.listFiles().length == 1) {
85+
if (directory.listFiles()[0].getName().startsWith(FileSystemJsonBlobManager.BLOB_METADATA_FILE_NAME)) {
86+
log.info("{} has only a metadata file, so it's being deleted", directory.getAbsolutePath());
87+
directory.delete();
88+
return false;
89+
}
90+
}
91+
8492
boolean process = true;
8593
if (isDataDir(directory.getAbsolutePath())) {
8694
String[] dateParts = directory.getAbsolutePath().replace(dataDirectoryPath.toFile().getAbsolutePath(), "").split("/", 4);

src/main/java/com/lowtuna/jsonblob/core/FileSystemJsonBlobManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
*/
4646
@Slf4j
4747
public class FileSystemJsonBlobManager implements JsonBlobManager, Runnable, Managed {
48+
public static final String BLOB_METADATA_FILE_NAME = "blobMetadata";
49+
4850
private static final DateTimeFormatter DIRECTORY_FORMAT = DateTimeFormat.forPattern("yyyy/MM/dd");
4951

5052
@GuardedBy("lastAccessedLock")
@@ -91,7 +93,7 @@ File getMetaDataFile(String blobId) {
9193
}
9294

9395
File getMetaDataFile(File blobDirectory) {
94-
return new File(blobDirectory, "blobMetadata" + ".json.gz");
96+
return new File(blobDirectory, BLOB_METADATA_FILE_NAME + ".json.gz");
9597
}
9698

9799
Optional<DateTime> resolveTimestamp(String blobId) {

0 commit comments

Comments
 (0)