Commit Graph
20 Commits
Author SHA1 Message Date
BFlat b5014b993b Merge pull request #2095 from dotCooCoo/fix/cloud-local-create-removes-partial
craft-cloud-local: a Save As whose write fails leaves the name free
2026-11-26 10:32:58 +07:00
BFlat 169fb9746b Merge pull request #2094 from dotCooCoo/fix/cloud-local-conditional-write-lock
craft-cloud-local: two saves from one etag no longer both succeed
2026-11-26 10:31:27 +07:00
dotCooCoo 2e80b6722d craft-cloud-local: README qualifies the same-process save guarantee
Two saves made from the same etag in one process can both succeed when
the first save leaves the file with an unchanged etag. The Concurrent
saves section now says so and points at the paragraph that explains it.
2026-11-23 23:48:08 -08:00
FredApps fd1dc355a5 Consolidate cloud integration tests 2026-11-19 13:02:42 +01:00
dotCooCoo 7dd2394aa0 Merge #2094's branch into fix/cloud-local-create-removes-partial 2026-11-17 18:13:54 -08:00
dotCooCoo 228f5a4596 craft-cloud-local: the concurrent-save test always reaches the locked recheck
The second save now signals once its temporary file is written, before it takes WRITE_LOCK, and the test releases the first save only then. The second save therefore always passes its early check and is refused by the recheck under the lock, and the test fails when that recheck is removed.
2026-11-17 18:12:43 -08:00
dotCooCoo 26ec28f1be Merge #2094's branch into fix/cloud-local-create-removes-partial
Saves and Save As share one open_temp and one WRITE_LOCK: write_replacing takes its temporary file from open_temp and runs #2094's etag recheck under the lock that create_in_place also holds.
2026-11-17 17:50:00 -08:00
dotCooCoo fe2937eab5 craft-cloud-local: the README says where a save's etag check holds
A Job::Write rechecks the etag under a lock held through the rename, so
two saves from one etag cannot both succeed within one process. The
README now says so, says that a second process writing the same folder
is not covered, and says that two same-length saves on a filesystem with
coarse timestamps can leave the same etag.
2026-11-17 17:44:46 -08:00
aiongg 72df1059bf cloud docs: no links to private items, as the workspace docs check requires 2026-11-18 01:42:39 +00:00
dotCooCoo 3ad0b66d66 craft-cloud-local: a listing leaves out the temporary file of a stopped save
A save that stops between creating its temporary file and renaming it
leaves a `.craft-save-<pid>-<clock>-<n>.tmp` file in the folder. `list`
returned it as an ordinary file.

`temp_name` now builds every temporary name, and `is_temp_name` matches a
name only when `temp_name` gives exactly that name back. `list` skips a
regular file whose name matches, before it reads the file's metadata. A
folder or a link with such a name is still listed, and so is a file such as
`.craft-save-notes.tmp`. `confine_name` refuses a matching name for a new
file, so a Save As cannot create a file that the listing would leave out.
2026-11-17 14:17:26 -08:00
dotCooCoo 23a810ed37 craft-cloud-local: the in-place create syncs, and its cleanup keeps a concurrent save
On a filesystem without hard links, create wrote the file in place but
did not sync it, so a share that reports a full disk only at sync gave
a successful create for a file that did not land. When the write failed,
the cleanup removed whatever the name held, which could be a save made
from the partial file in the meantime.

The in-place file is now synced, and a failed sync is cleaned up like a
failed write. A process-wide lock is held from the in-place create until
the file is complete or removed, and write_replacing takes it for its
rename, so no save in this process replaces the file before the cleanup.
2026-11-17 12:19:52 -08:00
dotCooCoo 2b16c924c5 craft-cloud-local: a stale temporary file no longer fails a save
open_temp skips a temporary name that already exists and tries the next
one, and only removes a temporary file it opened itself. The names also
carry a clock part, so a file left by an earlier run with the same
process id does not match a run of them.
2026-11-17 11:48:19 -08:00
dotCooCoo 2e8ca40ca9 craft-cloud-local: a Save As whose write fails leaves the name free
create opened the new file with create_new and then wrote into it. When
the write failed part way (a full disk, a lost share), the partial file
stayed at the requested name, and the next Save As of that name was
refused with "already exists".

The bytes now go to a hidden temporary file, which is removed when its
write fails. The finished file takes the name with a hard link, which
fails when the name is taken, so two racing creates still cannot both
win. A taken name is refused before any bytes are written. On a
filesystem without hard links the file is created in place as before,
and removed when its write fails.

Temporary names no longer include the file's name, so a name near the
filesystem's length limit still fits.
2026-11-17 11:42:36 -08:00
dotCooCoo 6f9d7489f2 craft-cloud-local: two saves from one etag no longer both succeed
write checked the etag and then renamed its temporary file over the
target with nothing between them. Two Job::Write calls carrying the same
etag, each on its own thread, could both pass the check before either
renamed, so both reported success and the later rename replaced the
first save without a Conflict.

The temporary file is still written and synced first. The etag is then
checked again under a process-wide lock held through the rename and the
metadata read, so the second save gets Fault::Conflict and its temporary
file is removed.
2026-11-17 11:30:05 -08:00
William Dunn aa4647a777 craft-cloud-local: confine every path through a Dir capability, not a path string
benandez's re-review reproduced three escapes the first confinement fix still
left open. A dangling symlink: canonicalize reported it as missing, so the
old confine_to_root walked up to root and accepted it, and write created the
symlink's target for real, outside root. A check-then-use race: confine_to_root
checked one path string and a later fs::read or fs::write resolved that same
string again, a second lookup a concurrently swapped link could land in
between. A hard link: write truncated the shared inode in place, with nothing
in a canonicalized path to show that another name pointed at the same file
outside root.

list, read, write and create now resolve every already segment-checked
relative path through a cap_std::fs::Dir capability opened on root, instead
of joining an absolute OS path and handing it to plain std::fs. cap_std
resolves one path component at a time against real, already-open directory
handles, so a symlink or a Windows junction cannot walk resolution above
root, dangling or not, and there is no separate check with a window for the
directory tree to change underneath it: the one resolution is the open. This
is the same family of guarantee craft-font-store already depends on through
cap-primitives, which cap_std is built on.

write no longer truncates its target in place either way: it writes a new
sibling file and renames it over the target, so a hard link's directory
entry is replaced rather than its shared content being overwritten.

Per that review's non-blocking notes: a name that already exists on disk
with an ordinary ':' or '\' byte (macOS stores a typed '/' as ':') stays
reachable by list and read, since neither character is a path separator on
any platform's filesystem; the stricter refusal now applies only to a name
being chosen by Create. Create also goes back to bringing a fresh root into
existence, matching its behaviour before the first confinement fix. A
Windows reserved device name (CON, COM1, CONIN$, with or without an
extension) is refused in a chosen name on every platform.

Regression tests reproduce all three escapes (dangling symlink, swapped-link
race, hard link), plus the previously missing coverage: a link in the folder
a Create targets, and a write test that actually reaches disk instead of
being refused for an unrelated reason before confinement ever ran. Verified
by hand that each of the three new write-path tests fails against the
pre-fix pattern (an absolute OS path joined by string concatenation) before
trusting them.
2026-11-17 00:51:58 -05:00
William Dunn e5e9433413 craft-cloud-local: confine list, read, write and create to the configured root
FredApps' re-review found that resolve only split on slash and rejected a
segment equal to parent-dir, with no constraint on a Windows backslash, a
drive letter or UNC prefix, or a filesystem link, and that create joined
the Job::Create name onto the resolved folder with no validation of the
name at all.

Every path segment, and a Create name on its own, now goes through one
shared confine_segment check: accepted only when it parses as exactly one
Component::Normal equal to the original text, with a backslash or colon
refused outright first so a Windows-shaped escape cannot slip past a
Linux build's narrower native parser. A second shared check, confine_to_root,
canonicalises the nearest existing ancestor of a resolved path and
confirms it still sits under the canonicalised root, refusing a symlink or
a Windows junction that would otherwise redirect outside it. List, read,
write and create all run both checks before touching disk.

Regression tests cover the review's own examples (a parent segment, an
absolute path, the three Windows-shaped forms) for Create, the same
Windows-shaped escape for a List folder path, and a symlink (Unix) or
junction (Windows) placed inside the root for list, read and write, each
against a sibling sentinel file and directory that must stay untouched.
2026-11-16 23:48:02 -05:00
William Dunn c5e9e87309 craft-cloud-local: fix stale etag and racing create
Read now stats the file it just read. The returned entry reflects
that read. It no longer echoes the etag of the entry passed in. A
reload after a conflict used to carry the version that was just
refused into the next save, conflicting it again.

Create opens the file with exclusive creation. An exists check no
longer precedes a separate write. Two creates of the same name can no
longer both observe an empty slot and both report success. Regression
tests drive both fixes through craft_ui::cloud's public functions
against a real folder on disk.
2026-11-16 23:48:02 -05:00
William Dunn a170341225 craft-cloud-local test: name the opened-documents type
The current clippy warns on the inline Arc Mutex tuple type in the test harness. A named OpenedDocs alias carries the same meaning.
2026-11-16 23:48:00 -05:00
William Dunn 07d2747efc craft-cloud-local: collapse the etag conflict check into one let chain
The current clippy denies collapsible_if here. Behaviour is unchanged. A missing file still has nothing to conflict with.
2026-11-16 23:48:00 -05:00
William Dunn 8334fd3c83 craft-cloud: cut-down contract plus ui pages 2026-11-16 23:47:58 -05:00