summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-01-29 08:14:39 +0100
committerqkzk <qu3nt1n@gmail.com>2023-01-29 08:14:39 +0100
commit1d37bc0e60f09c0eb4801f86db18d3df34e2ecf2 (patch)
treeafc23d653eff442f8cb162880e72deffc27b6e5c /src
parentc74b05821c808eb3f8db31cada7dcad1f744e442 (diff)
fix unknow uid/gid prevents file listing
Diffstat (limited to 'src')
-rw-r--r--src/fileinfo.rs34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/fileinfo.rs b/src/fileinfo.rs
index f9306d4..ddeaeea 100644
--- a/src/fileinfo.rs
+++ b/src/fileinfo.rs
@@ -552,25 +552,31 @@ fn convert_octal_mode(mode: usize) -> &'static str {
}
/// Reads the owner name and returns it as a string.
+/// If it's not possible to get the owner name (happens if the owner exists on a remote machine but not on host),
+/// it returns the uid as a `Result<String>`.
fn extract_owner(metadata: &Metadata, users_cache: &Rc<UsersCache>) -> FmResult<String> {
- Ok(users_cache
- .get_user_by_uid(metadata.uid())
- .ok_or_else(|| FmError::custom("extract owner", "Couldn't read uid"))?
- .name()
- .to_str()
- .ok_or_else(|| FmError::custom("extract owner", "Couldn't read owner name"))?
- .to_owned())
+ match users_cache.get_user_by_uid(metadata.uid()) {
+ Some(uid) => Ok(uid
+ .name()
+ .to_str()
+ .ok_or_else(|| FmError::custom("extract owner", "Couldn't parse owner name"))?
+ .to_owned()),
+ None => Ok(format!("{}", metadata.uid())),
+ }
}
/// Reads the group name and returns it as a string.
+/// If it's not possible to get the group name (happens if the group exists on a remote machine but not on host),
+/// it returns the gid as a `Result<String>`.
fn extract_group(metadata: &Metadata, users_cache: &Rc<UsersCache>) -> FmResult<String> {
- Ok(users_cache
- .get_group_by_gid(metadata.gid())
- .ok_or_else(|| FmError::custom("extract group", "Couldn't read gid"))?
- .name()
- .to_str()
- .ok_or_else(|| FmError::custom("extract group", "Couldn't read group name"))?
- .to_owned())
+ match users_cache.get_group_by_gid(metadata.gid()) {
+ Some(gid) => Ok(gid
+ .name()
+ .to_str()
+ .ok_or_else(|| FmError::custom("extract group", "Couldn't parse group name"))?
+ .to_owned()),
+ None => Ok(format!("{}", metadata.gid())),
+ }
}
/// Returns the file size.