Fixed issue causing "totalChunkCount" to exclude the metadata file in some cases.

ArbitraryDataFile now has a fileCount() method which returns the total number of files associated with that piece of data - i.e. chunks, metadata, and the complete file in cases where it isn't chunked.
This commit is contained in:
CalDescent 2023-03-03 10:42:43 +00:00
parent 64cd21b0dd
commit fa14568cb9
2 changed files with 17 additions and 1 deletions

View File

@ -612,6 +612,22 @@ public class ArbitraryDataFile {
return this.chunks.size();
}
public int fileCount() {
int fileCount = this.chunkCount();
if (fileCount == 0) {
// Transactions without any chunks can already be treated as a complete file
fileCount++;
}
if (this.getMetadataHash() != null) {
// Add the metadata file
fileCount++;
}
return fileCount;
}
public List<ArbitraryDataFileChunk> getChunks() {
return this.chunks;
}

View File

@ -193,7 +193,7 @@ public class ArbitraryTransactionUtils {
ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(digest, signature);
arbitraryDataFile.setMetadataHash(metadataHash);
return arbitraryDataFile.chunkCount() + 1; // +1 for the metadata file
return arbitraryDataFile.fileCount();
}
public static boolean isFileRecent(Path filePath, long now, long cleanupAfter) {