Files
ToastyFS/web/DESIGN.txt
T
Claude 8160c5ac51 Add TOASTY_WRITE_CREATE_IF_MISSING flag for server-side file auto-creation
Adds support for automatically creating files when write operations target
non-existent files. This is essential for REST PUT operations which should
be able to create new resources.

Implementation:
- Added TOASTY_WRITE_CREATE_IF_MISSING flag to ToastyFS API header
- Updated toasty_write() and toasty_begin_write() to accept flags parameter
- Client sends write flags in MESSAGE_TYPE_WRITE message to metadata server
- Metadata server parses flags and handles file auto-creation atomically:
  * When write fails with FILETREE_NOENT and flag is set
  * Logs creation to WAL for crash consistency
  * Creates file with default 4096-byte chunk size
  * Retries write with newly created file's generation tag
- Updated web proxy PUT handler to use TOASTY_WRITE_CREATE_IF_MISSING
- Updated examples and simulation client for new API signature

Benefits:
- Works for both sync and async APIs
- Single round trip (atomic server-side operation)
- Prevents race conditions
- Proper WAL logging ensures crash consistency
2025-12-03 18:48:42 +00:00

62 lines
2.3 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. This is
implemented using the TOASTY_WRITE_CREATE_IF_MISSING flag which performs
file creation and write atomically on the metadata server. 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
-----------