Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
syncthing doesn't honor umask #1339
I'm using syncthing 0.10.21 on archlinux and debian (3 machines). I'm syncing some folders, shared between local users. For those folders, I want to:
So I tried to set the syncthing umask to
I checked that this umask is actually applied to the syncthing process with gdb and
I didn't look at the code to investigate more yet. Do you have any idea?
I have a very similar use case where I'm syncing windows and linux machines, and (1) permissions should be ignored, but (2) the umask should be respected on the linux systems (files should be group-writeable, i.e. umask 0002).
Anyway, I've had a look at the syncthing code, and I've identified the main parts of the code that are involved. As a matter of fact, syncthing currently does respect umask settings. Any golang system call to create new files or directories will respect the umask on unix-like systems. The actual problem is that new files are created with 0644 permissions and directories with 0755. If you set 'ignore permissions' on a share, these default permissions are not altered anymore after the initial file creation. Since the umask by definition only takes away permissions, the group-write bit will therefore never be set.
I've managed to compile a syncthing version that produces the correct behavior (at least for my current setup) by setting default permissions to 0666 and 0777 for new files and directories, respectively. The unix umask then automatically takes care of taking away the inappropriate permission bits (i.e. making the files and directories not world-writeable etc). If you want, I can share this commit? (Still need to do some cleaning up.) So far I've only tested this on windows and linux (arch) on shares where the permissions are ignored.
It turned out to be more tricky than I originally thought. When I tested my original fix with servers having different combinations of ignorePermisions, I ran into problems. I've got it fixed now; or at least for the combinations of OSes and ignorePermissions settings that I tried.
I'm by no means an expert on the syncthing code (or Go as a matter of fact), but I think the problem is a bug in the current ignorePermissions implementation.
However, what is happening in the code (at least to my limited knowledge) is:
I will do 2 pull requests, if that is ok:
Note, however, that the two pull requests are needed to completely close/fix this issue.