Skip to content

VaultMD / withFileMove

Function: withFileMove() ​

withFileMove(from, to, opts?): Promise<void>

Defined in: src/locked-file/move.ts:38

Move a vault file byte-for-byte from from to to, holding BOTH per-file locks (acquired in sorted key order, so opposing moves cannot deadlock). The destination is created exclusively — an occupied path throws rather than being clobbered — and if the source turns out to have changed under us the fresh destination is rolled back, so a failed move never leaves a duplicate.

Emits TWO CommitEvents on success: delete for from, then create for to. There is no dedicated move event — the pair describes the same observable end state.

Parameters ​

from ​

MoveTarget

Resolved source target — see MoveTarget.

to ​

MoveTarget

Resolved destination target — see MoveTarget.

opts? ​

Optional onCommit callback and cross-process lock config.

cross? ​

false | CrossLock

Cross-process lock config, or false (default) for in-process only.

onCommit? ​

(e) => void | Promise<void>

Optional callback invoked after the move commits, once per event.

Returns ​

Promise<void>

Throws ​

MdVaultError VALIDATION_ERROR if both keys are identical (the lock is serializing, not reentrant), NOT_FOUND if the source is absent, ALREADY_EXISTS if the destination is taken (ALLOWLIST_VIOLATION if a symlink takes it), MTIME_CONFLICT if the source changed under the move, or UNSAFE_MODE if the OS gives the destination a mode that gives the group or the others more access than the source's mode did.

Released under the MIT License.