Skip to content

Commit 0f48443

Browse files
committed
fix(redox): improve error handling for unsupported safe traversal operations
1 parent 05d675b commit 0f48443

File tree

1 file changed

+56
-26
lines changed

1 file changed

+56
-26
lines changed

src/uucore/src/lib/features/safe_traversal.rs

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -120,35 +120,59 @@ pub struct DirFd {
120120
}
121121

122122
impl DirFd {
123-
#[cfg(target_os = "redox")]
124-
pub fn read_dir(&self) -> io::Result<Vec<OsString>> {
125-
Err(io::Error::new(io::ErrorKind::Other, "safe_traversal is not supported on Redox"))
126-
}
123+
#[cfg(target_os = "redox")]
124+
pub fn read_dir(&self) -> io::Result<Vec<OsString>> {
125+
Err(io::Error::new(
126+
io::ErrorKind::Other,
127+
"safe_traversal is not supported on Redox",
128+
))
129+
}
127130

128-
#[cfg(target_os = "redox")]
129-
pub fn unlink_at(&self, _name: &OsStr, _is_dir: bool) -> io::Result<()> {
130-
Err(io::Error::new(io::ErrorKind::Other, "safe_traversal is not supported on Redox"))
131-
}
131+
#[cfg(target_os = "redox")]
132+
pub fn unlink_at(&self, _name: &OsStr, _is_dir: bool) -> io::Result<()> {
133+
Err(io::Error::new(
134+
io::ErrorKind::Other,
135+
"safe_traversal is not supported on Redox",
136+
))
137+
}
132138

133-
#[cfg(target_os = "redox")]
134-
pub fn chown_at(&self, _name: &OsStr, _uid: Option<u32>, _gid: Option<u32>, _follow_symlinks: bool) -> io::Result<()> {
135-
Err(io::Error::new(io::ErrorKind::Other, "safe_traversal is not supported on Redox"))
136-
}
139+
#[cfg(target_os = "redox")]
140+
pub fn chown_at(
141+
&self,
142+
_name: &OsStr,
143+
_uid: Option<u32>,
144+
_gid: Option<u32>,
145+
_follow_symlinks: bool,
146+
) -> io::Result<()> {
147+
Err(io::Error::new(
148+
io::ErrorKind::Other,
149+
"safe_traversal is not supported on Redox",
150+
))
151+
}
137152

138-
#[cfg(target_os = "redox")]
139-
pub fn fchown(&self, _uid: Option<u32>, _gid: Option<u32>) -> io::Result<()> {
140-
Err(io::Error::new(io::ErrorKind::Other, "safe_traversal is not supported on Redox"))
141-
}
153+
#[cfg(target_os = "redox")]
154+
pub fn fchown(&self, _uid: Option<u32>, _gid: Option<u32>) -> io::Result<()> {
155+
Err(io::Error::new(
156+
io::ErrorKind::Other,
157+
"safe_traversal is not supported on Redox",
158+
))
159+
}
142160

143-
#[cfg(target_os = "redox")]
144-
pub fn chmod_at(&self, _name: &OsStr, _mode: u32, _follow_symlinks: bool) -> io::Result<()> {
145-
Err(io::Error::new(io::ErrorKind::Other, "safe_traversal is not supported on Redox"))
146-
}
161+
#[cfg(target_os = "redox")]
162+
pub fn chmod_at(&self, _name: &OsStr, _mode: u32, _follow_symlinks: bool) -> io::Result<()> {
163+
Err(io::Error::new(
164+
io::ErrorKind::Other,
165+
"safe_traversal is not supported on Redox",
166+
))
167+
}
147168

148-
#[cfg(target_os = "redox")]
149-
pub fn fchmod(&self, _mode: u32) -> io::Result<()> {
150-
Err(io::Error::new(io::ErrorKind::Other, "safe_traversal is not supported on Redox"))
151-
}
169+
#[cfg(target_os = "redox")]
170+
pub fn fchmod(&self, _mode: u32) -> io::Result<()> {
171+
Err(io::Error::new(
172+
io::ErrorKind::Other,
173+
"safe_traversal is not supported on Redox",
174+
))
175+
}
152176
/// Open a directory and return a file descriptor
153177
pub fn open(path: &Path) -> io::Result<Self> {
154178
#[cfg(not(target_os = "redox"))]
@@ -218,7 +242,10 @@ impl DirFd {
218242
}
219243
#[cfg(target_os = "redox")]
220244
pub fn stat_at(&self, _name: &OsStr, _follow_symlinks: bool) -> io::Result<()> {
221-
Err(io::Error::new(io::ErrorKind::Other, "safe_traversal is not supported on Redox"))
245+
Err(io::Error::new(
246+
io::ErrorKind::Other,
247+
"safe_traversal is not supported on Redox",
248+
))
222249
}
223250

224251
/// Get metadata for a file relative to this directory
@@ -242,7 +269,10 @@ impl DirFd {
242269
}
243270
#[cfg(target_os = "redox")]
244271
pub fn fstat(&self) -> io::Result<()> {
245-
Err(io::Error::new(io::ErrorKind::Other, "safe_traversal is not supported on Redox"))
272+
Err(io::Error::new(
273+
io::ErrorKind::Other,
274+
"safe_traversal is not supported on Redox",
275+
))
246276
}
247277

248278
/// Read directory entries

0 commit comments

Comments
 (0)