Skip to content

Commit 7700595

Browse files
committed
Implement masking in FileType comparison on Unix
Fixes: #104900
1 parent e704e95 commit 7700595

File tree

1 file changed

+10
-1
lines changed
  • library/std/src/sys/unix

1 file changed

+10
-1
lines changed

library/std/src/sys/unix/fs.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,16 @@ pub struct FileTimes {
332332
modified: Option<SystemTime>,
333333
}
334334

335-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
335+
#[derive(Copy, Clone, Eq, Hash, Debug)]
336336
pub struct FileType {
337337
mode: mode_t,
338338
}
339339

340+
impl PartialEq for FileType {
341+
fn eq(&self, other: &Self) -> bool {
342+
self.masked() == other.masked()
343+
}
344+
}
340345
#[derive(Debug)]
341346
pub struct DirBuilder {
342347
mode: mode_t,
@@ -550,6 +555,10 @@ impl FileType {
550555
pub fn is(&self, mode: mode_t) -> bool {
551556
self.mode & libc::S_IFMT == mode
552557
}
558+
559+
fn masked(&self) -> mode_t {
560+
self.mode & libc::S_IFMT
561+
}
553562
}
554563

555564
impl FromInner<u32> for FilePermissions {

0 commit comments

Comments
 (0)