Skip to content

Copy ownership feature not working with directories and files in it #8399

Closed

Description

@dotslashx

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:

pictures/
├─ img1.jpg
├─ img2.jpg
├─ 2020/
│  ├─ img3.jpg
│  ├─ img4.jpg
├─ 2021/
│  ├─ img5.jpg
├─ 2022/
│  ├─ img6.jpg

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.

I am using version 1.20.2

Activity

  1. added
    bug
    needs-triage
    on Jun 20, 2022
  2. AudriusButkevicius commented on Jun 21, 2022

    @AudriusButkevicius
    Member

    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.

  3. dotslashx commented on Jun 21, 2022

    @dotslashx
    Author

    which should have ownership of the root

    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.

  4. AudriusButkevicius commented on Jun 21, 2022

    @AudriusButkevicius
    Member

    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.

  5. calmh commented on Jun 22, 2022

    @calmh
    Member

    Might be a timing thing... Certainly sounds like a bug to me. I'll investigate at some point. :)

  6. dotslashx commented on Jun 22, 2022

    @dotslashx
    Author

    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.

  7. agoeckner commented on Apr 30, 2023

    @agoeckner
    Contributor

    This issue still seems to occur when using the copyOwnershipFromParent option.

    Edit: I believe I've resolved the problem. Please see #8883.

  8. agoeckner commented on May 1, 2023

    @agoeckner
    Contributor

    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.

  9. acolomb commented on May 2, 2023

    @acolomb
    Member

    Should this be reopened, given the comment in #8883 (comment)?

  10. reopened this on May 2, 2023
  11. calmh commented on May 2, 2023

    @calmh
    Member

    I missed that it had some sort of closes-annotation, sorry.

  12. agoeckner commented on May 2, 2023

    @agoeckner
    Contributor

    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.

    Thoughts?

  13. calmh commented on May 2, 2023

    @calmh
    Member

    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.

  14. agoeckner commented on May 2, 2023

    @agoeckner
    Contributor

    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.

  15. removed
    needs-triage
    on Sep 25, 2023
  16. added theissue type on May 30, 2025
  17. siggsy commented on Oct 5, 2026

    @siggsy

    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

  18. siggsy commented on Oct 6, 2026

    @siggsy

    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.

  19. cyqsimon commented on Oct 17, 2026

    @cyqsimon

    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.

  20. added a commit that references this issue on Oct 18, 2026
    ab91974
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions