Problem
For an existing folder, if using #include patterns.txt to load more patterns, I simply ensure that file exists. However, when adding a new folder to syncthing, this file does not exist yet. Using #include patterns.txt will cause the folder to complain about this and stop syncing.
Background
As implied, rather than putting ignore patterns like desktop.ini directly inside .stignore, instead I create a file such as patterns.txt with the above and load it using #include patterns.txt. This is for portability purposes - it’s easier to update only one file and reference it rather than edit .stignore all the time, especially when it is long.
Previous workaround
One can pre-create the folder, and pre-create patterns.txt, so that it is available when adding it through syncthing. However this requires manual intervention outside of the web GUI, which is difficult for someone using syncthing on a headless server who uses mostly the web GUI.
My solution
- Following the above, use a single folder, such as
.stignore.dto store any pattern files to#include - Pattern files can use any filename, I use
.txtso they are openable in text editors - For existing folders, the contents of
.stignoremay be as such:
#include /.stignore.d/patterns.txt
(/.stignore.d/... rather than .stignore.d/... - this ensures that no unnecessary folders are traversed by the watcher to look for patterns.txt)
- Key step - on new folders, add the folders with the following
/.stignore.d
*
This tells syncthing to only sync this folder and ignore everything else. The bonus is that even if this folder, or any pattern files within do not exist (yet), syncthing will not complain. This opens up a lot of possibilities.
- On other devices, create this folder, and place pattern files within (if not done already). The contents of
.stignore.dand no other files will now be synced to the new device. - On the new device, modify
#stignoreto use the patterns:
/.stignore.d
#include /.stignore.d/patterns.txt <- add this line
*
The file needs to exist at this point otherwise syncthing will complain, but that’s the point of the previous step - pull the pattern files from other devices.
- Now, remove the
*at the end, to resume normal syncing of other files.
/.stignore.d
#include /.stignore.d/patterns.txt
Result
For me, this solves two problems I face when adding folders to a new device
- I do not need to worry about pre-creating the patterns file
- I do not need to “first sync, then ignore” - this guarantees that when the pattern file is loaded during step (6), the folder is empty.
A practical example - let’s say a folder contains movies and photos. Other devices sync both, this new device should sync only photos. If I sync the folder first, then add patterns later, I’ll end up with both, and need to remove movies after ignoring it. This way, movies is never synced at all.