Add TOASTY_WRITE_TRUNCATE_AFTER flag for HTTP PUT semantics
Adds support for truncating files after write operations, enabling proper HTTP PUT semantics where the entire file content should be replaced. Implementation: - Added TOASTY_WRITE_TRUNCATE_AFTER flag (0x02) to ToastyFS API - Updated file_tree_write() to accept truncate_after parameter: * When true, sets file size to exactly offset+length * Removes chunks beyond the new file size * Marks removed chunks for garbage collection - Metadata server extracts and passes truncate flag to file_tree_write() - WAL replay passes false for truncate_after (already handled in original write) - Web proxy PUT now uses both CREATE_IF_MISSING and TRUNCATE_AFTER flags - Updated documentation in PROTOCOL.txt, DESIGN.txt, and web/DESIGN.txt Benefits: - Proper HTTP PUT semantics (replace entire file content) - Efficient: single write operation truncates and updates file - Works with both sync and async APIs - Garbage collection automatically removes orphaned chunks
This commit is contained in:
+11
-6
@@ -58,6 +58,7 @@ typedef uint64_t ToastyVersionTag;
|
||||
|
||||
// Write operation flags
|
||||
#define TOASTY_WRITE_CREATE_IF_MISSING (1 << 0) // Create file if it doesn't exist
|
||||
#define TOASTY_WRITE_TRUNCATE_AFTER (1 << 1) // Truncate file after write offset+length
|
||||
|
||||
// Creates a directory at the specified path.
|
||||
// Returns 0 on success, -1 on error.
|
||||
@@ -129,9 +130,11 @@ int toasty_read(ToastyFS *toasty, ToastyString path, int off,
|
||||
//
|
||||
// For how vtag works, see toasty_read.
|
||||
//
|
||||
// The flags parameter can be set to TOASTY_WRITE_CREATE_IF_MISSING
|
||||
// to automatically create the file if it doesn't exist. A default
|
||||
// chunk size of 4096 bytes will be used for the created file.
|
||||
// The flags parameter accepts the following values:
|
||||
// - TOASTY_WRITE_CREATE_IF_MISSING: Automatically create the file if it
|
||||
// doesn't exist. A default chunk size of 4096 bytes will be used.
|
||||
// - TOASTY_WRITE_TRUNCATE_AFTER: Truncate the file after offset+len,
|
||||
// discarding any data beyond the write range. Useful for HTTP PUT semantics.
|
||||
int toasty_write(ToastyFS *toasty, ToastyString path, int off,
|
||||
void *src, int len, ToastyVersionTag *vtag, uint32_t flags);
|
||||
|
||||
@@ -185,9 +188,11 @@ ToastyHandle toasty_begin_read(ToastyFS *toasty, ToastyString path,
|
||||
// If vtag is not 0, the operation only succedes if the
|
||||
// tag matches the remote entity's.
|
||||
//
|
||||
// The flags parameter can be set to TOASTY_WRITE_CREATE_IF_MISSING
|
||||
// to automatically create the file if it doesn't exist. A default
|
||||
// chunk size of 4096 bytes will be used for the created file.
|
||||
// The flags parameter accepts the following values:
|
||||
// - TOASTY_WRITE_CREATE_IF_MISSING: Automatically create the file if it
|
||||
// doesn't exist. A default chunk size of 4096 bytes will be used.
|
||||
// - TOASTY_WRITE_TRUNCATE_AFTER: Truncate the file after offset+len,
|
||||
// discarding any data beyond the write range. Useful for HTTP PUT semantics.
|
||||
ToastyHandle toasty_begin_write(ToastyFS *toasty, ToastyString path,
|
||||
int off, void *src, int len, ToastyVersionTag vtag, uint32_t flags);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user