Files
ToastyFS/web/DESIGN.txt
T
Claude 4bcee9a617 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
2025-12-03 19:49:48 +00:00

65 lines
2.4 KiB
Plaintext

The web interface allows working with the file system cluster using
basic HTTP requests. There are many ways to interface with a file system
using HTTP (like WebDAV), but for the firsts versions of ToastyFS I
opted for some custom minimal semantics. Here are they.
GET
If the path refers to a directory, the listing of its direct children
is returned as a newline-separated list of relative paths. Children
that are directories have ending slashes, while files don't:
image.jpg
Documents/
notes.txt
If the path refers to a file, its contents are returned. Note that
Range requests are not supported.
Returns 200 on success, 404 if the file/directory doesn't exist, else 5xx.
HEAD
Works like GET but doesn't return the content (The Content-Length is
set as if the payload was being send).
PUT
The server considers the resource being uploaded as a directory if the
path ends with a slash, and as a file otherwise:
photos/ directory
image.jpg file
If the path refers to a directory and no file/directory exists at that
path, a new one is created and status 201 is returned. If a directory
existd already, statis 204 is returned. If a file existed already status
??? (TODO) is returned. If the payload the request is not empty, the
operation fails with code 400.
If the path refers to a file, the file is automatically created if it
doesn't exist, then the specified contents are written to it, replacing
the entire file content (HTTP PUT semantics). This is implemented using
two flags:
- TOASTY_WRITE_CREATE_IF_MISSING: Creates file if it doesn't exist
- TOASTY_WRITE_TRUNCATE_AFTER: Truncates file after the write, discarding
any data beyond the uploaded content
Files are created with a default chunk size of 4096 bytes.
If a file or directory already existed at that path, it is overwritten
unless the header "X-ToastyFS-Overwrite: no" is sent.
(TODO error codes)
DELETE
Deletes the given file or directory. Returns 204 on success, 404 if
no file or directory existed at that path, else returns 5xx.
-----------
cases:
PUT file / unused path -> OK
PUT file / file exists -> overwrite?
PUT file / directory exists
PUT directory / unused path -> OK
PUT directory / file exists
PUT directory / directory exists
Idea: Use patch on the parent directory to rename
-----------