From f86e3d704af40bf98a557e58f634b1c917019821 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sat, 8 Feb 2020 22:54:56 +0100 Subject: [PATCH] vfs: use None for unknown uid/gid This means we show '?' instead of 0 for unknown UIDs when numeric output is requested, as it was before. This also uncovered a forgotten bytes annotation for the "unknown" string ('?' should be b'?'). Somehow, this new behaviour (of printing 0 instead of ?) also got quite enshrined in the test suite, fix that too. And finally, on python 2, fuse doesn't accept None in the stat struct (but does on python 3, go figure). Fixes: f76c37383ddb ("Remove vfs (replaced by vfs2)") Signed-off-by: Johannes Berg Reviewed-by: Rob Browning --- cmd/fuse-cmd.py | 4 ++-- lib/bup/metadata.py | 8 +++++--- lib/bup/t/tvfs.py | 2 +- lib/bup/vfs.py | 3 ++- t/test-ls | 20 ++++++++++---------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/cmd/fuse-cmd.py b/cmd/fuse-cmd.py index dbc0cd1..2eb28fb 100755 --- a/cmd/fuse-cmd.py +++ b/cmd/fuse-cmd.py @@ -69,8 +69,8 @@ class BupFs(fuse.Fuse): # FIXME: do we want/need to do anything more with nlink? st = fuse.Stat(st_mode=meta.mode, st_nlink=1, st_size=meta.size) st.st_mode = meta.mode - st.st_uid = meta.uid - st.st_gid = meta.gid + st.st_uid = meta.uid or 0 + st.st_gid = meta.gid or 0 st.st_atime = max(0, xstat.fstime_floor_secs(meta.atime)) st.st_mtime = max(0, xstat.fstime_floor_secs(meta.mtime)) st.st_ctime = max(0, xstat.fstime_floor_secs(meta.ctime)) diff --git a/lib/bup/metadata.py b/lib/bup/metadata.py index 48b1a07..d5b4b4a 100644 --- a/lib/bup/metadata.py +++ b/lib/bup/metadata.py @@ -418,8 +418,10 @@ class Metadata: uid = gid = -1 # By default, do nothing. if is_superuser(): - uid = self.uid - gid = self.gid + if self.uid is not None: + uid = self.uid + if self.gid is not None: + gid = self.gid if not restore_numeric_ids: if self.uid != 0 and self.user: entry = pwd_from_name(self.user) @@ -1012,7 +1014,7 @@ def summary_bytes(meta, numeric_ids = False, classification = None, human_readable = False): """Return bytes containing the "ls -l" style listing for meta. Classification may be "all", "type", or None.""" - user_str = group_str = size_or_dev_str = '?' + user_str = group_str = size_or_dev_str = b'?' symlink_target = None if meta: name = meta.path diff --git a/lib/bup/t/tvfs.py b/lib/bup/t/tvfs.py index a2500f9..2563333 100644 --- a/lib/bup/t/tvfs.py +++ b/lib/bup/t/tvfs.py @@ -114,7 +114,7 @@ def run_augment_item_meta_tests(repo, wvpass(item is not file_item) wvpass(isinstance(meta, Metadata)) wvpasseq(vfs.default_file_mode, meta.mode) - wvpasseq((0, 0, 0, 0, 0), + wvpasseq((None, None, 0, 0, 0), (meta.uid, meta.gid, meta.atime, meta.mtime, meta.ctime)) wvpass(augmented.meta.size is None) wvpasseq(file_size, augmented_w_size.meta.size) diff --git a/lib/bup/vfs.py b/lib/bup/vfs.py index 8b4789c..934ff81 100644 --- a/lib/bup/vfs.py +++ b/lib/bup/vfs.py @@ -1112,7 +1112,8 @@ def augment_item_meta(repo, item, include_size=False): # m is mode meta = Metadata() meta.mode = m - meta.uid = meta.gid = meta.atime = meta.mtime = meta.ctime = 0 + meta.uid = meta.gid = None + meta.atime = meta.mtime = meta.ctime = 0 if S_ISLNK(m): if isinstance(item, FakeLink): target = item.target diff --git a/t/test-ls b/t/test-ls index fcff652..2912476 100755 --- a/t/test-ls +++ b/t/test-ls @@ -136,23 +136,23 @@ WVPASSEQ "$(WVPASS bup-ls -l / | tr -s ' ' ' ')" \ "drwx------ $user/$group 0 2009-10-03 23:48 src" WVPASSEQ "$(WVPASS bup-ls -lA / | tr -s ' ' ' ')" \ -"drwxr-xr-x 0/0 0 1970-01-01 00:00 .tag +"drwxr-xr-x ?/? 0 1970-01-01 00:00 .tag drwx------ $user/$group 0 2009-10-03 23:48 src" WVPASSEQ "$(WVPASS bup-ls -lAF / | tr -s ' ' ' ')" \ -"drwxr-xr-x 0/0 0 1970-01-01 00:00 .tag/ +"drwxr-xr-x ?/? 0 1970-01-01 00:00 .tag/ drwx------ $user/$group 0 2009-10-03 23:48 src/" WVPASSEQ "$(WVPASS bup-ls -la / | tr -s ' ' ' ')" \ -"drwxr-xr-x 0/0 0 1970-01-01 00:00 . -drwxr-xr-x 0/0 0 1970-01-01 00:00 .. -drwxr-xr-x 0/0 0 1970-01-01 00:00 .tag +"drwxr-xr-x ?/? 0 1970-01-01 00:00 . +drwxr-xr-x ?/? 0 1970-01-01 00:00 .. +drwxr-xr-x ?/? 0 1970-01-01 00:00 .tag drwx------ $user/$group 0 2009-10-03 23:48 src" WVPASSEQ "$(WVPASS bup-ls -laF / | tr -s ' ' ' ')" \ -"drwxr-xr-x 0/0 0 1970-01-01 00:00 ./ -drwxr-xr-x 0/0 0 1970-01-01 00:00 ../ -drwxr-xr-x 0/0 0 1970-01-01 00:00 .tag/ +"drwxr-xr-x ?/? 0 1970-01-01 00:00 ./ +drwxr-xr-x ?/? 0 1970-01-01 00:00 ../ +drwxr-xr-x ?/? 0 1970-01-01 00:00 .tag/ drwx------ $user/$group 0 2009-10-03 23:48 src/" socket_mode="$(WVPASS ls -l src/socket | cut -b -10)" || exit $? @@ -252,14 +252,14 @@ $socket_mode $uid/$gid 0 2009-10-03 23:48 socket $symlink_mode $uid/$gid $symlink_size $symlink_date symlink -> file" WVPASSEQ "$(bup-ls -ld "src/latest" | tr -s ' ' ' ')" \ -"lrwxr-xr-x 0/0 17 1970-01-01 00:00 src/latest -> 1977-09-05-125600" +"lrwxr-xr-x ?/? 17 1970-01-01 00:00 src/latest -> 1977-09-05-125600" WVSTART "$ls_cmd_desc (backup set - long)" WVPASSEQ "$(bup-ls -l --numeric-ids src | cut -d' ' -f 1-2)" \ "drwx------ $uid/$gid drwx------ $uid/$gid -lrwxr-xr-x 0/0" +lrwxr-xr-x ?/?" WVPASSEQ "$(bup-ls -ds "src/1977-09-05-125600" | tr -s ' ' ' ')" \ "$src_tree_hash src/1977-09-05-125600" -- 2.39.2