Skip to content

Commit

Permalink
Path PartialEq own implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin JEROME <[email protected]>
  • Loading branch information
qjerome committed Nov 10, 2023
1 parent 64513d7 commit 727d8e0
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion kunai-common/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub struct Metadata {
}

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, Eq)]
pub struct Path {
buffer: [u8; MAX_PATH_LEN],
len: u32,
Expand All @@ -121,6 +121,36 @@ pub struct Path {
pub error: Option<Error>,
}

impl PartialEq for Path {
fn eq(&self, other: &Self) -> bool {
let meta_eq = {
if self.metadata.is_none() && other.metadata.is_none() {
return true;
}

if let Some(sm) = self.metadata {
if let Some(om) = other.metadata {
// we don't consider atime (access time)
// as being relevant for path Eq checking
return sm.ino == om.ino
&& sm.sb_ino == om.sb_ino
&& sm.size == om.size
&& sm.mtime == om.mtime
&& sm.ctime == om.ctime;
}
}

false
};

self.buffer == other.buffer
&& self.len == other.len
&& self.depth == other.depth
&& self.real == other.real
&& meta_eq
}
}

impl Default for Path {
fn default() -> Self {
Path {
Expand Down

0 comments on commit 727d8e0

Please sign in to comment.