Chown fails when path is a symlink
**Please ignore this, I think there is a blunder on my end with the paths!!!**
I have found an issue with the chown implementation I assume. I created the following minimal example:
```rust
use std::fs::{self, read_link};
use std::os::unix::fs::{MetadataExt, symlink};
use std::path::Path;
use rustix::fs::{Gid, Uid};
fn main() {
const BASE_DIR: &str = "./3.1415926535";
let file_path = format!("{BASE_DIR}/myfile.txt");
let link_path = format!("{BASE_DIR}/myfile.txt.link");
fs::remove_dir_all(BASE_DIR).unwrap();
fs::create_dir_all(BASE_DIR).unwrap();
let file = fs::File::create(&file_path).unwrap();
let path = Path::new(&file_path);
let link = Path::new(&link_path);
symlink(path, link).unwrap();
assert!(read_link(link).is_ok());
assert!(fs::exists(path).unwrap());
let uid = file.metadata().unwrap().uid();
let gid = file.metadata().unwrap().gid();
rustix::fs::chown(link, Some(Uid::from_raw(uid)), Some(Gid::from_raw(gid))).unwrap();
}
```
with the following dependencies
```toml
[dependencies]
rustix = { version = "1.1.4", features = ["all-apis"] }
```
Which will crash with:
```bash
thread 'main' (3031489) panicked at src/main.rs:24:81:
called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }
```
If the chown is invoked on the `path` it succeeds.
关闭于 2026-05-01 1 条评论