Skip to content

vfs/vfscache: use the remote name when reloading the cache - #9974

Open
Kurptas wants to merge 1 commit into
rclone:masterfrom
Kurptas:pr/walkfix
Open

Kurptas wants to merge 1 commit into
rclone:masterfrom
Kurptas:pr/walkfix

Conversation

@Kurptas

@Kurptas Kurptas commented Sep 25, 2026

Copy link
Copy Markdown

What this fixes

vfs/vfscache/cache.go walk() hands the OS-encoded cache-directory path to Cache.get() / reload(), whose contract (see the comments on get/newItem/Item, and New()'s own fromOSPath a few lines above) requires a remote name. So when an existing cache directory is re-walked (remount, cache reuse), items are created under an OS-encoded key that is not the remote name, and their cache/metadata files are looked up under a twice-encoded, non-existent path.

Consequences measured on Windows (WinFsp, SFTP remote, --vfs-cache-mode full):

  • A pending edit is silently dropped. Save a file with --vfs-write-back 1h, kill the mount while the item is dirty (its metadata file has Dirty=true and 13 B of data), remount the same --cache-dir: reload() finds nothing to resume, nothing is uploaded and the remote keeps the old (9 B) content. With this fix the edit is resumed and uploaded (13 B).
  • Cache accounting is wrong on the same path: vfs cache: cleaned: objects 1 (was 1) in use 0, to upload 0, total size 0 for a 6 B cached object, and the item is logged under its OS-encoded name (A‛:B.txt) instead of its remote name (A:B.txt).
  • It also affects names that the OS encoder merely rewrites (a literal fullwidth :/?, a trailing space): those get a ‛ (QuoteRune) prefix in the cache key.

Change

name = fromOSPath(name) in walk(), i.e. the same conversion New() already performs at cache.go. walk()'s only caller is reload(), which uses the name as a cache key and log prefix, and fromOSPath is the identity for names the OS encoding never changes (ASCII), so nothing else can be affected and no quoting semantics change.

Test

TestCacheReloadOSEncodedName (vfs/vfscache/cache_test.go): builds a cache, creates an item under a risky remote name, marks it dirty with the write-back pending, reopens the cache with WriteBack=0 and asserts (1) the reloaded item set is exactly [{name: <the remote name>}] and not an OS-encoded key, (2) get(name) finds it, (3) the pending edit reached the remote under the unchanged name.

Fails before this change for A:B.txt, A?B.txt and a trailing-space name (three different encoder rules), passes after; the ASCII row passes in both. The A‛B.txt row is skipped on purpose: the encoder is not invertible for names that already contain QuoteRune (OS.FromStandardName maps both A‛:B.txt and A‛‛:B.txt to the same value), so recovering those needs the remote name persisted in the item metadata — a separate, larger change.

go build, go vet, and go test ./vfs/... ./lib/encoder/... are clean.

walk() hands the OS encoded name of a cache file to Cache.get(), but that
is a remote (standard) encoded namespace: get/newItem/item all take remote
paths.  So on a cache reload items whose names the OS encoding changes (a
fullwidth colon, a trailing space, a literal quote rune, ...) were created
under the OS encoded name and their cache and metadata files were then
looked up under a twice encoded, and therefore missing, path.

The visible effect is that a pending write back for such a file is
silently dropped when the mount is restarted with a warm cache, and the
cache item is known by the wrong name (and accounted as 0 bytes).

Fix by converting the walked name back to remote encoding, as New() already
does for the cache parent path.  ASCII names are unaffected as the
conversion is the identity for them.

Add a regression test covering fullwidth and trailing space names plus an
ASCII control.
@Kurptas

Kurptas commented Oct 5, 2026

Copy link
Copy Markdown
Author

Rebased onto current master (branch is now 1 commit ahead) and fixed the gofmt complaint in vfs/vfscache/cache_test.go.

For the record, the other lint failure in the earlier run — backend/crypt/cipher.go:157: unexported-return (revive) — was upstream code, already fixed on master since. The linux/windows test failures in that same run were against the 2026-09-26 base.

Local checks after the rebase: go vet ./vfs/vfscache/ clean, go test ./vfs/vfscache/ -run TestCacheReloadOSEncodedName passes.

The workflow runs for this push are action_required (first-time contributor), so they need an approval before they execute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant