Skip to content

Commit 7e39c98

Browse files
committed
fix(fs,unix): set_permissions might change permission of wrong file
1 parent 1b921f1 commit 7e39c98

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

compio-fs/src/file.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ impl File {
9595
/// Changes the permissions on the underlying file.
9696
#[cfg(unix)]
9797
pub async fn set_permissions(&self, perm: Permissions) -> io::Result<()> {
98+
use compio_driver::syscall;
9899
use std::os::unix::fs::PermissionsExt;
99100

100-
let fd = self.as_raw_fd() as _;
101+
let file = self.inner.try_clone()?;
101102
compio_runtime::spawn_blocking(move || {
102-
syscall!(libc::fchmod(fd, perm.mode() as libc::mode_t))?;
103+
syscall!(libc::fchmod(file.as_raw_fd(), perm.mode() as libc::mode_t))?;
103104
Ok(())
104105
})
105106
.await

compio-fs/src/metadata/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl Metadata {
147147
#[cfg(unix)]
148148
impl Metadata {
149149
/// Create from [`libc::statx`]
150-
pub fn from_stat(stat: libc::statx) -> Self {
150+
pub fn from_stat(stat: libc::stat) -> Self {
151151
Self(sys::Metadata::from_stat(stat))
152152
}
153153
}

0 commit comments

Comments
 (0)