diff --git a/Filesystem-Case-Sensitivity.md b/Filesystem-Case-Sensitivity.md new file mode 100644 index 0000000..4a7c045 --- /dev/null +++ b/Filesystem-Case-Sensitivity.md @@ -0,0 +1,95 @@ +The intention is to collect/reference all relevant information relating to the "Filesystem Case Sensitivity Problem"™ + +# What is the problem? + +The issue goes way back and most of it is spelled out in + +https://github.com/syncthing/syncthing/issues/1787 + +It's also a frequent cause for support requests: + +https://forum.syncthing.net/search?q=case%20rename + +One typical effect is, that if locally a file `foo` exists and we want to sync `Foo` from a remote, the following error occurs: + +``` +file modified but not rescanned; will try again later +``` + +That's because in db we don't have anything for `Foo`, however when stating `Foo` on disk it will say `Foo` exists because it looks at the pre-existing `foo`. We scan again, see that `foo` is there as expected, and the same thing happens again when syncing. +A few examples: https://forum.syncthing.net/search?q=case%20sensitive%20modified%20later + +# Solution attempts/proposals + +Some old discussions: + +https://forum.syncthing.net/t/case-insensitive-renames-how-to-solve/3073 + +## Be case insensitive + +https://github.com/syncthing/syncthing/issues/2739 + +https://forum.syncthing.net/t/implementing-case-insensitivity/12384 + +A very short explanation not doing it justice: +In the key-value storage, save files with a canonical, lower-case key, and save the real filename in the value. Thus behave case-insensitively, but case-preserving. Should be configurable, such that unixers can keep the good old simple case-senstitive behaviour. +This affects virtually every stage of Syncthing and no attempt at doing it came to full fruition until now unfortunately. + +## "Detect real case"-proposal + +Brought up in https://github.com/syncthing/syncthing/issues/1787#issuecomment-640621832 + +The basic premise is to leave the db alone, and add a way to detect and use the "real case" of a filename on disk. A universal solution is to use listdir/readdirfilenames for path components. + +### Scanner + +Walking a filesystem already does report the real names. Case problems arise because of the second scanner step where deletions are detected by stating filenames as present in the db. The proposal here is to avoid that second step by directly comparing db contents while walking the filesystem, i.e. do https://github.com/syncthing/syncthing/pull/4584 again (PR status is merged, but was reverted later). +This means after a scan, all filenames in the db correspond to the real case on disk, regardless of the scenario (e.g. picks up case only renames on windows). This does not require any special treatment for windows and is beneficial to other systems as well, as we will do just one iteration instead of the two now. + +### Puller + +Puller doesn't work in filesystem order, so we can't walk the filesystem at the same time as pulling like with the scanner. Here we need to get case right between the filename that we currently pull and what's on disk. The simplest option would be to list dir contents for every path component and look for a case insensitive match. Improving on that a bit is https://github.com/syncthing/syncthing/pull/6717 by using windows `FindFirstFile` syscall (obviously windows only though). Being able to detect a case difference still leaves the question of what to do with the ability, see 2 below. + +### Open questions + +1. Cross-compatibility/config + +Options: + +(a) Enable case check everywhere, with an opt-out config (aka user promises that their system is case sensitive). + +(b) Detect case sensitivity automatically (i.e. no config) by creating two case-conflicting files and observing the outcome. + +(c) Detect the filesystem in use and make conclusions on case-sensitivity from that. + +(d) Use the above detection mechanism to choose a default value for the config, but still allow the user to override that. + +For (a): That means on linux by default "case conflicts" (which aren't conflicts there) would lead the effects discussed in 2.. That's probably going to create lots of clamour by linux-people about breaking their perfectly normal workflow for compatibility with generally inferior systems. + +2. What to do when detecting case conflicts? + +(a) Make it a sync error, thus the user will have to fix the problem on a case-sensitive peer - just like with invalid filenames on windows currently. + +(b) Create "case-conflicts" just like the current concurrent modification conflicts. I.e. with existing `foo.txt` and to be pulled `Foo.txt`, you end up with something like `Foo.case-conflict-*timestamp*-*dev*.txt". + +(c) Choose one of the names automatically pure case-only conflicts (i.e. same content and permission). + +3. How to detect correct case? + +(a) listdir based methods +Works everywhere, might be inefficient. Efficiency could be improved by caching listdir results. + +(b) System specific solutions +windows: FindFirstFile (works). macos: F_GETPATH option for fcntl (untested). Nothing known on linux/unix. + +Hopefully (a) with some smartness is fast enough, so we can just use `os` and not deal with low-level system calls. + +### Code + + - https://github.com/syncthing/syncthing/pull/4584 + +Old PR walking the filesystem and db at the same time while scanning, to immediately detect removed items without needing to stat db contents later on. + + - https://github.com/syncthing/syncthing/pull/6717 + +Utility function and tests to get the real case on windows using FindFirstFile \ No newline at end of file