about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorArthur Carcano <arthur.carcano@ocamlpro.com>2022-11-25 17:47:00 +0100
committerArthur Carcano <arthur.carcano@ocamlpro.com>2022-11-25 18:15:59 +0100
commit77005950f09d2f9ba54962bf5adc3f2bc3a7213f (patch)
tree39fb4ef999872a5c9f116ddbe532f48cd20cacf5 /library/std/src
parente704e95250ff4e949214f390a88f21d08052bea1 (diff)
downloadrust-77005950f09d2f9ba54962bf5adc3f2bc3a7213f.tar.gz
rust-77005950f09d2f9ba54962bf5adc3f2bc3a7213f.zip
Implement masking in FileType comparison on Unix
Fixes: https://github.com/rust-lang/rust/issues/104900
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys/unix/fs.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs
index 37a49f2d78a..382204d6893 100644
--- a/library/std/src/sys/unix/fs.rs
+++ b/library/std/src/sys/unix/fs.rs
@@ -332,11 +332,16 @@ pub struct FileTimes {
     modified: Option<SystemTime>,
 }
 
-#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
+#[derive(Copy, Clone, Eq, Hash, Debug)]
 pub struct FileType {
     mode: mode_t,
 }
 
+impl PartialEq for FileType {
+    fn eq(&self, other: &Self) -> bool {
+        self.masked() == other.masked()
+    }
+}
 #[derive(Debug)]
 pub struct DirBuilder {
     mode: mode_t,
@@ -550,6 +555,10 @@ impl FileType {
     pub fn is(&self, mode: mode_t) -> bool {
         self.mode & libc::S_IFMT == mode
     }
+
+    fn masked(&self) -> mode_t {
+        self.mode & libc::S_IFMT
+    }
 }
 
 impl FromInner<u32> for FilePermissions {