mirror of https://github.com/borgbackup/borg.git
mode, user/group id/name: minor code refactor, remove None values at transfer time, #6908
https://github.com/borgbackup/borg/issues/6908#issuecomment-1224910916
This commit is contained in:
parent
6e2419f3b2
commit
1a6b60f415
|
@ -1115,7 +1115,8 @@ class MetadataCollector:
|
|||
self.nobirthtime = nobirthtime
|
||||
|
||||
def stat_simple_attrs(self, st):
|
||||
attrs = dict(mode=st.st_mode, uid=st.st_uid, gid=st.st_gid)
|
||||
attrs = {}
|
||||
attrs["mode"] = st.st_mode
|
||||
# borg can work with archives only having mtime (very old borg archives do not have
|
||||
# atime/ctime). it can be useful to omit atime/ctime, if they change without the
|
||||
# file content changing - e.g. to get better metadata deduplication.
|
||||
|
@ -1127,6 +1128,8 @@ class MetadataCollector:
|
|||
if not self.nobirthtime and hasattr(st, "st_birthtime"):
|
||||
# sadly, there's no stat_result.st_birthtime_ns
|
||||
attrs["birthtime"] = safe_ns(int(st.st_birthtime * 10**9))
|
||||
attrs["uid"] = st.st_uid
|
||||
attrs["gid"] = st.st_gid
|
||||
if not self.numeric_ids:
|
||||
user = uid2user(st.st_uid)
|
||||
if user is not None:
|
||||
|
|
|
@ -87,8 +87,10 @@ def uid2user(uid, default=None):
|
|||
|
||||
@lru_cache(maxsize=None)
|
||||
def user2uid(user, default=None):
|
||||
if not user:
|
||||
return default
|
||||
try:
|
||||
return user and pwd.getpwnam(user).pw_uid
|
||||
return pwd.getpwnam(user).pw_uid
|
||||
except KeyError:
|
||||
return default
|
||||
|
||||
|
@ -103,8 +105,10 @@ def gid2group(gid, default=None):
|
|||
|
||||
@lru_cache(maxsize=None)
|
||||
def group2gid(group, default=None):
|
||||
if not group:
|
||||
return default
|
||||
try:
|
||||
return group and grp.getgrnam(group).gr_gid
|
||||
return grp.getgrnam(group).gr_gid
|
||||
except KeyError:
|
||||
return default
|
||||
|
||||
|
|
|
@ -93,6 +93,11 @@ class UpgraderFrom12To20:
|
|||
# - 'acl' remnants of bug in attic <= 0.13
|
||||
# - 'hardlink_master' (superseded by hlid)
|
||||
new_item_dict = {key: value for key, value in item.as_dict().items() if key in ITEM_KEY_WHITELIST}
|
||||
# remove some pointless entries older borg put in there:
|
||||
for key in "user", "group":
|
||||
if key in new_item_dict and new_item_dict[key] is None:
|
||||
del new_item_dict[key]
|
||||
assert not any(value is None for value in new_item_dict.values()), f"found None value in {new_item_dict}"
|
||||
new_item = Item(internal_dict=new_item_dict)
|
||||
new_item.get_size(memorize=True) # if not already present: compute+remember size for items with chunks
|
||||
assert all(key in new_item for key in REQUIRED_ITEM_KEYS)
|
||||
|
|
Loading…
Reference in New Issue