Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include the number of links to a file #377

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions crates/unftp-sbe-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ impl<User: UserDetail> StorageBackend<User> for Filesystem {
}
}

#[allow(unreachable_code)]
impl Metadata for Meta {
fn len(&self) -> u64 {
self.inner.len()
Expand All @@ -246,12 +247,58 @@ impl Metadata for Meta {
}

fn gid(&self) -> u32 {
#[cfg(target_os = "linux")]
{
use std::os::linux::fs::MetadataExt;

return self.inner.st_gid();
}

#[cfg(target_os = "unix")]
{
use std::os::unix::fs::MetadataExt;

return self.inner.gid();
}

0
}

fn uid(&self) -> u32 {
#[cfg(target_os = "linux")]
{
use std::os::linux::fs::MetadataExt;

return self.inner.st_uid();
}

#[cfg(target_os = "unix")]
{
use std::os::unix::fs::MetadataExt;

return self.inner.uid();
}

0
}

fn links(&self) -> u64 {
#[cfg(target_os = "linux")]
{
use std::os::linux::fs::MetadataExt;

return self.inner.st_nlink();
}

#[cfg(target_os = "unix")]
{
use std::os::unix::fs::MetadataExt;

return self.inner.nlink();
}

1
}
}

#[cfg(test)]
Expand Down
8 changes: 7 additions & 1 deletion src/storage/storage_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ pub trait Metadata {
/// Returns the `uid` of the file.
fn uid(&self) -> u32;

/// Returns the number of links to the file. The default implementation always returns `1`
fn links(&self) -> u64 {
1
}

/// Returns the `permissions` of the file. The default implementation assumes unix permissions
/// and defaults to "rwxr-xr-x" (octal 7755)
fn permissions(&self) -> Permissions {
Expand Down Expand Up @@ -120,7 +125,7 @@ where
#[allow(clippy::write_literal)]
write!(
f,
"{filetype}{permissions} {owner:>12} {group:>12} {size:#14} {modified:>12} {path}",
"{filetype}{permissions} {links:>12} {owner:>12} {group:>12} {size:#14} {modified:>12} {path}",
filetype = if self.metadata.is_dir() {
"d"
} else if self.metadata.is_symlink() {
Expand All @@ -129,6 +134,7 @@ where
"-"
},
permissions = perms,
links = self.metadata.links(),
owner = self.metadata.uid(),
group = self.metadata.gid(),
size = self.metadata.len(),
Expand Down