#10895·syncthing

`Failed to rename while normalizating UTF8 encoding` leaves user files renamed to `<name>.tmp` (normalization-insensitive FS / Android FUSE with caseSensitiveFS=false)

Author: Triangle-GitHubCreated Sep 24, 2026Updated Sep 24, 2026

What happened?

Adding a folder that already contained a file whose name is stored in NFD form made the scanner rename the file to <name>.tmp and then fail to rename it back:

WRN Failed to rename while normalizating UTF8 encoding; please rename temp file manually
    (from="Bärchen (한글)(漢字).mp3.tmp" to="Bärchen (한글)(漢字).mp3" error="file does not exist" log.pkg=scanner)

The file is left on disk as Bärchen (한글)(漢字).mp3.tmp. That warning is the only trace: there is no rollback, no retry and no persistent state, so it never heals on later scans. Because applyNormalization() returns tempPath, the mangled name is what gets indexed — and, unless the user happens to ignore *.tmp, what gets propagated to every peer.

Expected: the file ends up under its NFC name; if the rename cannot be completed, the operation should be rolled back and surfaced as a folder error — the user's file must not be left renamed as a side effect.

Steps to reproduce

  1. On the device, create a file whose name is NFD-normalized, e.g. Bärchen (한글)(漢字).mp3 where ä is a + U+0308 and the Hangul syllables are decomposed (한글).
  2. Add the parent directory as a Syncthing folder with default settings (or let an existing folder pick the file up via the watcher).
  3. Watch the log for the warning above — the file ends up named …mp3.tmp.

Evidence that this is not a filesystem limitation

The filesystem is normalization-insensitive (same class as ZFS, cf. #4649): lstat() of the NFC name succeeds and reports the same inode as the NFD name, while readdir() returns the stored (NFD) bytes.

Replaying exactly the same two rename calls in that same directory on that same device with plain os.rename() succeeds:

step 1: 'Bärchen … .mp3'      -> 'Bärchen … .mp3.tmp'   OK
step 2: 'Bärchen … .mp3.tmp'  -> 'Bärchen … .mp3'       OK

So the filesystem supports the sequence; the failure is in the Go path layer.

Where it appears to break

Because the folder is case-insensitive, the filesystem is wrapped in caseFilesystem. caseFilesystem.Rename() resolves both paths through its internal cache first and returns the lookup error verbatim:

go
oldcan, err := f.checkCase(oldpath)
if err != nil {
    return err                 // fs.ErrNotExist => "file does not exist"
}
newcan, err := f.checkCase(newpath)
if err != nil {
    // Case-only rename is ok
    e := &CaseConflictError{}
    if !errors.As(err, &e) || e.Real != oldpath {
        return err
    }
}

Step 2 is called with a temp name that the same process created moments earlier; checkCase() cannot resolve it and returns fs.ErrNotExist, so the underlying rename is never attempted. scanner.applyNormalization() (lib/scanner/walk.go) has no recovery for this — the comment there literally says "I don't ever expect this to happen" — it logs and returns tempPath.

Impact

  • A user's file is silently renamed to *.tmp: media players and other tools stop seeing it, and it looks like junk.
  • Not self-healing: the original name is lost, rescans don't fix it.
  • If *.tmp is not ignored, the mangled name is synced to every peer, i.e. a local bookkeeping failure propagates cluster-wide.
  • The same symptom has been reported for ZFS (linuxserver/docker-syncthing#77 — closed as stale, never diagnosed), which is precisely the filesystem class the temp-file dance was introduced for (cf. #4649).

Possible fixes

  1. Don't fail Rename() on a path the same process just created: refresh/resolve the case cache for the temp path (re-Lstat / re-list the parent) before step 2.
  2. Make the failure path safe: if step 2 fails, roll step 1 back and report a proper folder error — leave the file under its original name and give the user an actionable signal instead of a renamed file.
  3. Note that in this branch the file is already reachable under both names (lstat(normPath) + SameFile() succeeded), so failing to normalize is not critical for the data — it just shouldn't be able to damage the name.

Syncthing version

v2.1.5

Platform & operating system

Android 12, arm64 (core packaged in Syncthing-Fork); folder lives on Android's FUSE-backed emulated storage (/sdcard). Folder settings: autoNormalize=true (default), caseSensitiveFS=false (default for this filesystem), filesystemType=basic.

Browser version

N/A (no browser involved)

Relevant log output

WRN Failed to rename while normalizating UTF8 encoding; please rename temp file manually
    (from="Bärchen (한글)(漢字).mp3.tmp" to="Bärchen (한글)(漢字).mp3" error="file does not exist" log.pkg=scanner)

A folder with a few thousand files was scanned; only the files whose names were stored in NFD were affected, and the failure is deterministic for those files (one scan, one warning each).