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
Some unsafe chown(at) code can be removed by rustix #12041
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?
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.
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.
Activity
[-]Some unsafe chwown(at) can be removed by rustix[/-][+]Some unsafe chown(at) code can be removed by rustix[/+]ksgk1 commentedon Apr 30, 2026
I am currently looking into this and I read on The man page that:
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?ksgk1 commentedon May 1, 2026
I created a PR: #12107 for those changes.
ksgk1 commentedon May 1, 2026
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()returnstruemeaning that the path exists. When I callrustix::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.
oech3 commentedon Oct 18, 2026
#15509 (comment)
perms: use rustix for ownership changes
perms: use rustix for ownership changes
perms: use rustix for ownership changes
perms: use rustix for ownership changes