Skip to content

Commit

Permalink
Replace libc file modes with cross-platform crate
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
  • Loading branch information
rydrman committed Jul 29, 2023
1 parent 2ee5b8c commit 23f2555
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/spfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ tokio-util = { version = "0.7.3", features = ["compat", "io"] }
tonic = "0.8"
tracing = { workspace = true }
ulid = "1.0"
unix_mode = "0.1.3"
url = { version = "2.2", features = ["serde"] }
uuid = { version = "1.1", features = ["v4"] }
walkdir = "2.3"
Expand Down
6 changes: 3 additions & 3 deletions crates/spfs/src/graph/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ impl Entry {
}

pub fn is_symlink(&self) -> bool {
(libc::S_IFMT & self.mode) == libc::S_IFLNK
unix_mode::is_symlink(self.mode)
}

pub fn is_dir(&self) -> bool {
(libc::S_IFMT & self.mode) == libc::S_IFDIR
unix_mode::is_dir(self.mode)
}

pub fn is_regular_file(&self) -> bool {
(libc::S_IFMT & self.mode) == libc::S_IFREG
unix_mode::is_file(self.mode)
}
}

Expand Down
7 changes: 2 additions & 5 deletions crates/spfs/src/storage/repository_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,15 @@ async fn test_commit_mode_fs(tmpdir: tempfile::TempDir) {
.expect("failed to render manifest");
let rendered_symlink = rendered_dir.join(symlink_path);
let rendered_mode = rendered_symlink.symlink_metadata().unwrap().mode();
assert!(
(libc::S_IFMT & rendered_mode) == libc::S_IFLNK,
"should be a symlink"
);
assert!(unix_mode::is_symlink(rendered_mode), "should be a symlink");

let symlink_entry = manifest
.get_path(symlink_path)
.expect("symlink not in manifest");
let symlink_blob = tmprepo.payloads.build_digest_path(&symlink_entry.object);
let blob_mode = symlink_blob.symlink_metadata().unwrap().mode();
assert!(
(libc::S_IFMT & blob_mode) != libc::S_IFLNK,
!unix_mode::is_symlink(blob_mode),
"stored blob should not be a symlink"
)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/spfs/src/tracking/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ impl PartialOrd for Entry {

impl<T> Entry<T> {
pub fn is_symlink(&self) -> bool {
(libc::S_IFMT & self.mode) == libc::S_IFLNK
unix_mode::is_symlink(self.mode)
}
pub fn is_dir(&self) -> bool {
(libc::S_IFMT & self.mode) == libc::S_IFDIR
unix_mode::is_dir(self.mode)
}
pub fn is_regular_file(&self) -> bool {
(libc::S_IFMT & self.mode) == libc::S_IFREG
unix_mode::is_file(self.mode)
}

pub fn iter_entries(&self) -> impl Iterator<Item = super::manifest::ManifestNode<'_, T>> {
Expand Down

0 comments on commit 23f2555

Please sign in to comment.