You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Copy ownership feature not working with directories and files in it #8399
I am trying to setup an linux instance with copyOwnershipFromParent enabled but it seems to be a little broken. As for files at the base level of the synced directory the ownership is indeed being copied, but when a new directory and files inside it are to be synced it is not.
Take this directory structure as an example, pictures is the synced folder:
In this example only img1.jpg and img2.jpg has the expected ownership, directories and other files inherit owner and group from the user which started the instance and not from the parent directory.
That's exactly the case, they don't. Directories are created with the ownership of a syncthing user.
Lets say I run the syncthing instance as john and the owner of the pictures directory is bob. When a directory is to be synchronized from a remote device then the owner is john. Automatically all the files and nested directories and files inside are owned by john. It only happens with directories, when a file directly in pictures directory is to be synced, it has the expected owner bob.
Just looked into inotify logs and I don't seen any attrib events for the directories that are being synced, just the files. I could not find anything in the syncthing logs even after enabling all facilities. So either the chown is failing somewhere but I can't find it or it is simply not being called by some mistake.
Edit: I've run strace and it looks like the issue is chown not being called for directories but only for .tmp files which are later renamed.
Ah, there is a second problem where checkParent in folder_sendrecv.go creates an entire lineage of parent directories without setting their attributes.
I'm running into this now when attempting to sync a large folder for the first time. It seems that Syncthing tries to create files before their parent folders.
I missed that it had some sort of closes-annotation, sorry.
Ah, my bad.
Ah, there is a second problem where checkParent in folder_sendrecv.go creates an entire lineage of parent directories without setting their attributes.
I'm running into this now when attempting to sync a large folder for the first time. It seems that Syncthing tries to create files before their parent folders.
Regarding this, I'm not sure of the best solution. I see two options:
Create the entire folder lineage recursively, setting ownership as we go.
When receiving, place folders for which we don't yet have a parent on a queue, and then process them after the parent arrives.
My recollection is that directories are gathered at the beginning of a sync pass and handled before any files, and also that they would generally be sent before any files inside that directory. The only time something should be handled before its parent is when the parent is on the ignore list.
Obviously something about my recollection is incorrect, so I guess it needs investigation to see what actually happens.
My recollection is that directories are gathered at the beginning of a sync pass and handled before any files, and also that they would generally be sent before any files inside that directory.
On slow connections (such as mine) and large syncthing folders, this does not seem to hold true. It takes a while for the whole index state to be transferred, yet the receiver starts attempting to pull before it knows about the parent. That is my hunch, anyway.
edit: further, while child files inside the directory are indeed queued for after the parent folder, this is not true for child folders.
The sync process seems to struggle with race conditions (which I gather from glancing at the checkParent inner comment). Which makes me think. Do we even want to "copyOwnershipFromParent" or should we "copyOwnershipFromRoot". If there are issues when deleting folders on one device and creating files under the deleted folder on another device, how can we even know what the correct "parent ownership" even is? I believe that the best option here is to just check ownership of the parent of the root Folder that we are trying to sync.
While this is still being sorted out, I might add that changing "File Pull Order" from default "Random" to "Alphabetic" (or maybe "Oldest first") reduces the number of folders created by checkParent
What I ended up doing is just syncing to a /var/lib/syncthing/${id} folder and bind-mounting the folders to their appropriate places with x-mount.idmap option.
This option in my opinion should just be deprecated and removed.
Yeah I was planning to use copyOwnershipFromParent, and it came across my mind that it would be easy to screw up and/or overlook this particular ordering detail when handling nested files. And what do you know, my clanker independently identified exactly this problem. This is what it suggested and I'm inclined to agree:
A better upstream solution would be for Syncthing's checkParent() to apply ownership inheritance to every directory it creates through MkdirAll(). That would eliminate the dependency on processing order for this particular problem.
Activity
AudriusButkevicius commentedon Jun 21, 2022
Whats the owner of 2020 etc? Files would have same ownership as owner of that directory (which should have ownership of the root).
Note that this is only done once, so if you change the ownership after the directory is created, it will stay changed.
dotslashx commentedon Jun 21, 2022
That's exactly the case, they don't. Directories are created with the ownership of a syncthing user.
Lets say I run the syncthing instance as
johnand the owner of thepicturesdirectory isbob. When a directory is to be synchronized from a remote device then the owner isjohn. Automatically all the files and nested directories and files inside are owned byjohn. It only happens with directories, when a file directly inpicturesdirectory is to be synced, it has the expected ownerbob.AudriusButkevicius commentedon Jun 21, 2022
I guess you can enable fs debug logs and see whats happening.
Are you running as a user with special capabilities or as root?
Feels like the chown calls are failing and the problem is in permissions rather syncthing.
Feels like we should close this and move it to the forums.
I am not convinced its a bug yet.
calmh commentedon Jun 22, 2022
Might be a timing thing... Certainly sounds like a bug to me. I'll investigate at some point. :)
dotslashx commentedon Jun 22, 2022
Just looked into inotify logs and I don't seen any
attribevents for the directories that are being synced, just the files. I could not find anything in the syncthing logs even after enabling all facilities. So either the chown is failing somewhere but I can't find it or it is simply not being called by some mistake.Edit: I've run strace and it looks like the issue is
chownnot being called for directories but only for.tmpfiles which are later renamed.agoeckner commentedon Apr 30, 2023
This issue still seems to occur when using the
copyOwnershipFromParentoption.Edit: I believe I've resolved the problem. Please see #8883.
agoeckner commentedon May 1, 2023
Ah, there is a second problem where
checkParentinfolder_sendrecv.gocreates an entire lineage of parent directories without setting their attributes.I'm running into this now when attempting to sync a large folder for the first time. It seems that Syncthing tries to create files before their parent folders.
acolomb commentedon May 2, 2023
Should this be reopened, given the comment in #8883 (comment)?
calmh commentedon May 2, 2023
I missed that it had some sort of closes-annotation, sorry.
agoeckner commentedon May 2, 2023
Ah, my bad.
Regarding this, I'm not sure of the best solution. I see two options:
Thoughts?
calmh commentedon May 2, 2023
My recollection is that directories are gathered at the beginning of a sync pass and handled before any files, and also that they would generally be sent before any files inside that directory. The only time something should be handled before its parent is when the parent is on the ignore list.
Obviously something about my recollection is incorrect, so I guess it needs investigation to see what actually happens.
agoeckner commentedon May 2, 2023
On slow connections (such as mine) and large syncthing folders, this does not seem to hold true. It takes a while for the whole index state to be transferred, yet the receiver starts attempting to pull before it knows about the parent. That is my hunch, anyway.
edit: further, while child files inside the directory are indeed queued for after the parent folder, this is not true for child folders.
siggsy commentedon Oct 5, 2026
The sync process seems to struggle with race conditions (which I gather from glancing at the
checkParentinner comment). Which makes me think. Do we even want to "copyOwnershipFromParent" or should we "copyOwnershipFromRoot". If there are issues when deleting folders on one device and creating files under the deleted folder on another device, how can we even know what the correct "parent ownership" even is? I believe that the best option here is to just check ownership of the parent of the rootFolderthat we are trying to sync.While this is still being sorted out, I might add that changing "File Pull Order" from default "Random" to "Alphabetic" (or maybe "Oldest first") reduces the number of folders created by
checkParentsiggsy commentedon Oct 6, 2026
What I ended up doing is just syncing to a
/var/lib/syncthing/${id}folder and bind-mounting the folders to their appropriate places withx-mount.idmapoption.This option in my opinion should just be deprecated and removed.
cyqsimon commentedon Oct 17, 2026
Yeah I was planning to use
copyOwnershipFromParent, and it came across my mind that it would be easy to screw up and/or overlook this particular ordering detail when handling nested files. And what do you know, my clanker independently identified exactly this problem. This is what it suggested and I'm inclined to agree:fix(model): ensure parent ownership is copied properly (fixes syncthi…
chore(deps): update syncthing/syncthing docker tag to v2.1.7 (#13)