Skip to main content

Module attach

Module attach 

Source
Expand description

Attachments: files on a part or on one of its revisions.

§Where the bytes are

<data>/blobs/<first two hex>/<sha256> — content-addressed, so the same file attached twice (to two parts, or carried to a new revision) is stored once. An upload streams into <data>/blobs/tmp/ while it is hashed and counted against the size limit, and is never held in memory whole; it is moved to its content address inside the store’s write lock, in the same change that adds its reference. A blob is removed inside the write lock too, by the change that drops its last reference, so an upload and a delete of the same content can never cross.

§The rules

  • A PART attachment follows the part, like sourcing: any author may add or remove one at any time, released revisions or not.
  • A REVISION attachment is frozen with the revision: it is added or removed only while the revision is in work and nobody else holds its lock. A new revision starts with references to the same files.
  • Download is for anyone signed in. A small list of media types that a browser renders without running anything (raster images and PDF) may be shown inline; everything else is served as a download. The page’s Content-Security-Policy and nosniff stay on every response.

Structs§

BlobsHeld
Blob removals of the store at a root held while it lives; the held ones are made by BlobsHeld::release.
Describe
What the uploader says about a file.
Located
Where an attachment hangs, found by its id.
Staged
An upload that has been written, hashed and counted, and waits in the staging directory for its reference. Dropping it removes the file, so an upload that is refused or abandoned leaves nothing behind.
Upload
Hashes and counts an upload as it streams to the staging directory.

Constants§

INLINE_TYPES
Media types a browser may show inline: they render without script. SVG is an image that can carry script, so it is NOT here.
KINDS
The kinds an attachment may be filed as.

Functions§

attachment_writable
blob_path
Where the blob with this hash lives.
blob_root
The blob directory under a data directory.
clean_media_type
A media type in type/subtype form, lower case, parameters dropped; else application/octet-stream.
clean_name
A file name that is safe to store and to put in a Content-Disposition: the last path segment, no control characters or quotes, not empty.
inline_ok
Whether a response may show this type inline.
is_sha256
Whether text is a hex SHA-256 — the only thing ever joined to a blob path.
locate
Find an attachment by id anywhere in the store.
locate_scoped
Resolve a file in a particular part/revision; carried attachments can share ids.
place
Move a staged upload to its content address, unless that blob is already there. Inside the write lock, in the change that adds its reference.
referenced
Every blob the store references: attachments, revision thumbnails (crate::thumbnail), and every version of every workspace file (crate::workspace), instructions player data (crate::player), and the tools library’s pictures (crate::tools).
remove_if_unreferenced
Remove the blob sha256 if nothing in state references it any more. Called inside the write lock by the change that dropped a reference. While the store’s own backup copies blobs, the removal waits for it.
staging_dir
Where uploads stream to before they have a name.