Fix file size tracking to use actual written bytes

Previously, file_size was calculated as num_chunks * chunk_size, which
incorrectly treated the file size as the full capacity of all allocated
chunks. The actual file size should be the offset of the last byte
written plus 1.

Changes:
- Added file_size field to File structure to track actual file extent
- Initialize file_size to 0 when creating new files
- Update file_size in file_tree_write() based on write offset + length
- Modified file_tree_read() to use file_size instead of num_chunks * chunk_size
- Updated serialization/deserialization to handle file_size field

This ensures that actual_bytes calculations correctly reflect the true
file size, not just the allocated chunk capacity.
This commit is contained in:
Claude
2025-11-22 22:33:15 +00:00
parent f856bd0e05
commit 7b0b1acf61
2 changed files with 13 additions and 7 deletions
+1
View File
@@ -18,6 +18,7 @@ typedef struct Entity Entity;
typedef struct {
uint64_t chunk_size; // TODO: this should be an u32
uint64_t num_chunks; // TODO: and this too
uint64_t file_size; // Offset of last byte written + 1
SHA256 *chunks;
} File;