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 | |
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.
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/fsentry.rs | 30 |
2 files changed, 31 insertions, 0 deletions
@@ -30,6 +30,7 @@ structopt = "0.3" tempfile = "3.1" thiserror = "1" tokio = { version = "0.2", features = ["macros"] } +users = "0.11" uuid = { version = "0.8", features = ["v4"] } walkdir = "2" warp = { version = "0.2", features = ["tls"] } 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 { |