Skip to main content

append

Function append 

Source
pub async fn append(
    pool: &PgPool,
    vault: &Vault,
    actor: &Actor,
    id: Uuid,
    offset: u64,
    chunk: &[u8],
    max_chunk: u64,
) -> AppResult<UploadSession>
Expand description

Appends a chunk at offset (see check_chunk) and returns the updated session. The chunk is on disk before the new offset is confirmed, so an interruption at any point loses at most this chunk.

§Invariants

  • Permission: the actor’s own session (anybody else’s, or an expired one, is a 404).
  • Locks: the session row (FOR UPDATE), so concurrent chunks of one session are serialised.
  • Data: the chunk must start at the confirmed offset (409 otherwise) and stay within the announced size (400); a session whose content is already verified takes no more chunks (409). Each chunk renews the expiry.
  • Audit, notifications, webhooks: none.
  • Atomic: the chunk is written to the staging file before the offset is updated in the transaction; when the update fails, the offset stays and the chunk is sent again.