Renaming caused file deletion bug.

Reproduce step:

  1. On PC, create a file named 1_2.md, wait until it synced to Android.
  2. On PC, rename the 1_2.md to 1-2.md, wait until it synced to Android.
  3. Wait a few seconds, the new 1-2.md on Android was deleted, and the deletion was synced to the PC.

This occurred today on my device, took me 4 hours to locate that the Syncthing Android caused the file lose. The above step can be 100% reproduce.

Renaming a file whose name contains _ to - will cause the deletion of this file. Really strange.

I don’t know if it’s the System or Syncthing Android caused this issue.

Is there more specific log I can get?


  • My phone: Android 11
  • Syncthing Android: 1.18.3
1 Like

Interesting. Can reproduce on a test device and grabbed some logs.

2021-11-10 10:55:31 folderconfiguration.go:109 basic /storage/emulated/0/Documents Stat . {0x400038e600} <nil>
2021-11-10 10:55:31 folderconfiguration.go:127 basic /storage/emulated/0/Documents Stat .stfolder {0x400038e9c0} <nil>
2021-11-10 10:55:31 folderconfiguration.go:109 basic /storage/emulated/0/Documents Stat . {0x400038f140} <nil>
2021-11-10 10:55:31 folderconfiguration.go:127 basic /storage/emulated/0/Documents Stat .stfolder {0x400038f200} <nil>
2021-11-10 10:55:31 ignore.go:385 basic /storage/emulated/0/Documents Open .stignore <nil> open /storage/emulated/0/Documents/.stignore: no such file or directory
2021-11-10 10:55:31 folder_sendrecv.go:696 basic /storage/emulated/0/Documents Lstat . {0x400038f380} <nil>
2021-11-10 10:55:31 folder_sendrecv.go:2048 basic /storage/emulated/0/Documents Lstat 1_2.txt {0x400038f440} <nil>
2021-11-10 10:55:31 folder_sendrecv.go:964 basic /storage/emulated/0/Documents Lstat 1-2.txt <nil> lstat /storage/emulated/0/Documents/1-2.txt: no such file or directory
2021-11-10 10:55:31 osutil.go:87 basic /storage/emulated/0/Documents Stat . {0x400038f5c0} <nil>
2021-11-10 10:55:31 basic /storage/emulated/0/Documents Watch: Ignoring .syncthing.1-2.txt.tmp
2021-11-10 10:55:31 basic /storage/emulated/0/Documents Watch: Sending 1_2.txt remove
2021-11-10 10:55:31 osutil.go:33 basic /storage/emulated/0/Documents Rename 1_2.txt .syncthing.1-2.txt.tmp <nil>
2021-11-10 10:55:31 folder_sendrecv.go:1578 basic /storage/emulated/0/Documents Lstat 1-2.txt <nil> lstat /storage/emulated/0/Documents/1-2.txt: no such file or directory
2021-11-10 10:55:31 osutil.go:87 basic /storage/emulated/0/Documents Stat . {0x400281e180} <nil>
2021-11-10 10:55:31 basic /storage/emulated/0/Documents Watch: Sending 1-2.txt non-remove
2021-11-10 10:55:31 basic /storage/emulated/0/Documents Watch: Ignoring .syncthing.1-2.txt.tmp
2021-11-10 10:55:31 osutil.go:33 basic /storage/emulated/0/Documents Rename .syncthing.1-2.txt.tmp 1-2.txt <nil>
2021-11-10 10:55:31 basic /storage/emulated/0/Documents Watch: Sending 1-2.txt non-remove
2021-11-10 10:55:31 basic /storage/emulated/0/Documents Watch: Sending 1-2.txt non-remove
2021-11-10 10:55:31 folder_sendrecv.go:1612 basic /storage/emulated/0/Documents Chtimes 1-2.txt 2021-11-10 10:54:45.604080975 +0100 CET 2021-11-10 10:54:45.604080975 +0100 CET <nil>
2021-11-10 10:55:31 folder_sendrecv.go:1685 basic /storage/emulated/0/Documents Open . {{0x40006ee1a8 .} 0x4000bce330} <nil>
2021-11-10 10:55:46 basic /storage/emulated/0/Documents Watch: Sending 1-2.txt remove
2021-11-10 10:55:56 folderconfiguration.go:109 basic /storage/emulated/0/Documents Stat . {0x4000c5a0c0} <nil>
2021-11-10 10:55:56 folderconfiguration.go:127 basic /storage/emulated/0/Documents Stat .stfolder {0x4000c5a180} <nil>
2021-11-10 10:55:56 ignore.go:385 basic /storage/emulated/0/Documents Open .stignore <nil> open /storage/emulated/0/Documents/.stignore: no such file or directory
2021-11-10 10:55:56 walk.go:230 basic /storage/emulated/0/Documents Walk 1-2.txt 0x572b8f84d0 <nil>
2021-11-10 10:55:56 osutil.go:134 basic /storage/emulated/0/Documents Lstat 1-2.txt <nil> lstat /storage/emulated/0/Documents/1-2.txt: no such file or directory
2021-11-10 10:55:56 folderconfiguration.go:109 basic /storage/emulated/0/Documents Stat . {0x400281e600} <nil>
2021-11-10 10:55:56 folderconfiguration.go:127 basic /storage/emulated/0/Documents Stat .stfolder {0x400281e6c0} <nil>
2021-11-10 10:55:56 folder.go:330 basic /data/user/0/com.nutomic.syncthingandroid/files/index-v0.14.0.db Usage . {107827363840 115282542592} <nil>

Essentially, we did the rename (via a temp file…) and then 15s later get a filesystem notification that the file was removed, and when we look for it again it’s indeed gone.

1 Like

I can’t find any reasonable explanation for it, but it appears to happen when a file is renamed so that the only change is from an underscore to a dash, like test_atest-a. If there are any other changes as well, it’s fine. If the dash-underscore change is in the other direction, it’s fine. If I shut down Syncthing after rename but before the disappearance (which happens about 15s after the rename), then the file is not disappeared. So it certainly looks like it’s Syncthing who’s the culprit.

And it doesn’t happen in my emulator where I could have done some better troubleshooting :man_shrugging:

1 Like

I also tried the Syncthing installed from Termux.

Termux is a open source terminal app on Android.

pkg install syncthing

In the Termux version, if I rename the test_atest-a from PC, then both the old file and the new file will be kept on Android (and then sync back to PC). Weird more.

2 Likes

Wait. You get both variants? Freaky.

What about Catfriend’s fork? https://github.com/Catfriend1/syncthing-android

1 Like

Same result on the fork app. The renamed file was deleted.

2 Likes

I’m running into a similar issue, except it’s not just renaming between - and _. General renaming will randomly trigger file deletions, moving files to different folders can also trigger random deletions. If it’s a folder that doesn’t get a lot of files changing, things usually are okay. But I have a notes folder that I access using the Obsidian note-taking app, and because its for personal notes, files get renamed and moved around quite frequently. I’ve been having random deletions in that folder often. What I’m noticing is that if I rename or move a file, the resulting file ends up trashed on Android specifically. I believe that this is the case because the file will still exist on Android with a .trashed- prefix to the name. With the latest round of deletions affecting hundreds of files, I’m at my wits end and would love some help.