diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-03-03 07:32:10 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-03-03 07:33:01 +0200 |
commit | 671f13b29235abbfc7137571d596f5f784aa6b0b (patch) | |
tree | 13ee5561db96f38ff6e638ea165547945ff0e0f0 /src/fsentry.rs | |
parent | 0103bec1fb4f8290c78c35dfe832e88733ac6e16 (diff) | |
download | obnam2-671f13b29235abbfc7137571d596f5f784aa6b0b.tar.gz |
feat: store user and group who own each file
Actually, these aren't yet actually stored in the backup. That will
happen when there's a way to verify file metadata stored in the
backup. But this adds the code to look up the data during a backup so
that at least that part gets some exercise.
Diffstat (limited to 'src/fsentry.rs')
-rw-r--r-- | src/fsentry.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/fsentry.rs b/src/fsentry.rs index 570877a..28f7c61 100644 --- a/src/fsentry.rs +++ b/src/fsentry.rs @@ -37,6 +37,14 @@ pub struct FilesystemEntry { // The target of a symbolic link, if any. symlink_target: Option<PathBuf>, + + // User and group owning the file. We store them as both the + // numeric id and the textual name corresponding to the numeric id + // at the time of the backup. + uid: u32, + gid: u32, + user: String, + group: String, } #[derive(Debug, thiserror::Error)] @@ -67,6 +75,10 @@ impl FilesystemEntry { } else { None }; + + let uid = meta.st_uid(); + let gid = meta.st_gid(); + Ok(Self { path: path.to_path_buf().into_os_string().into_vec(), kind: FilesystemKind::from_file_type(meta.file_type()), @@ -77,6 +89,10 @@ impl FilesystemEntry { atime: meta.st_atime(), atime_ns: meta.st_atime_nsec(), symlink_target, + uid, + gid, + user: get_username(uid), + group: get_groupname(gid), }) } @@ -122,6 +138,20 @@ impl FilesystemEntry { } } +fn get_username(uid: u32) -> String { + match users::get_user_by_uid(uid) { + None => "".to_string(), + Some(user) => user.name().to_os_string().to_string_lossy().into_owned(), + } +} + +fn get_groupname(gid: u32) -> String { + match users::get_group_by_gid(gid) { + None => "".to_string(), + Some(group) => group.name().to_os_string().to_string_lossy().into_owned(), + } +} + /// Different types of file system entries. #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] pub enum FilesystemKind { |