Skip to content

Some unsafe chown(at) code can be removed by rustix #12041

Open

Activity

  1. changed the title [-]Some unsafe chwown(at) can be removed by rustix[/-] [+]Some unsafe chown(at) code can be removed by rustix[/+] on Apr 27, 2026
  2. ksgk1 commented on Apr 30, 2026

    @ksgk1
    Contributor

    I am currently looking into this and I read on The man page that:

    chown() changes the ownership of the file specified by path,
    which is dereferenced if it is a symbolic link.

    lchown() is like chown(), but does not dereference symbolic
    links.

    Which would be from my understanding of the rustix implementation, that it does not have the follow option directly. So my idea was, to use canonicalize() to follow the symlink. Would that be a good solution?

    My other question is regarding safety, if the canonicalization fails, what kind of error should I return? Is IOError::last_os_error() the way to go in that case?

  3. ksgk1 commented on May 1, 2026

    @ksgk1
    Contributor

    I created a PR: #12107 for those changes.

  4. ksgk1 commented on May 1, 2026

    @ksgk1
    Contributor

    There are some issues in my code apparently. I had the test suit failing on main too, so I assumed my additions were not causing an issue. I will look into this.

    The test that fails is: https://github.com/ksgk1/coreutils/blob/replace-unsafe-chown-by-rustix-%2312041/tests/by-util/test_cp.rs#L3340

    I looked into it, and added some debug statements to my code, and noticed, that
    fs::exists(&final_path).is_ok() returns true meaning that the path exists. When I call rustix::fs::chown(final_path, ...) it returns with an "No such file or directory (os error 2)" error.

    I could not find an open issue on the rustix project, I would like to hear someone's opinion on this and then I can open an issue.

  5. oech3 commented on Oct 18, 2026

    @oech3
    ContributorAuthor
  6. reopened this on Oct 18, 2026
  7. added 4 commits that reference this issue on Oct 18, 2026
    353b123
    410428a
    7d5168d
    d4c3e8e
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions