Merge pull request #7287 from ThomasWaldmann/fix-get-item-uid-gid-win32

fix some uid/gid lookup code / tests for win32
This commit is contained in:
TW 2023-01-19 21:48:47 +01:00 committed by GitHub
commit ccbfc4ee95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 11 deletions

View File

@ -21,6 +21,9 @@ def uid2user(uid, default=None):
@lru_cache(maxsize=None) @lru_cache(maxsize=None)
def user2uid(user, default=None): def user2uid(user, default=None):
if not user:
# user is either None or the empty string
return default
return 0 return 0
@ -31,6 +34,9 @@ def gid2group(gid, default=None):
@lru_cache(maxsize=None) @lru_cache(maxsize=None)
def group2gid(group, default=None): def group2gid(group, default=None):
if not group:
# group is either None or the empty string
return default
return 0 return 0

View File

@ -14,7 +14,7 @@ from ..archive import BackupOSError, backup_io, backup_io_iter, get_item_uid_gid
from ..helpers import msgpack from ..helpers import msgpack
from ..item import Item, ArchiveItem from ..item import Item, ArchiveItem
from ..manifest import Manifest from ..manifest import Manifest
from ..platform import uid2user, gid2group from ..platform import uid2user, gid2group, is_win32
@pytest.fixture() @pytest.fixture()
@ -349,6 +349,11 @@ def test_get_item_uid_gid():
assert uid == 7 assert uid == 7
assert gid == 8 assert gid == 8
if not is_win32:
# due to the hack in borg.platform.windows user2uid / group2gid, these always return 0
# (no matter which username we ask for) and they never raise a KeyError (like e.g. for
# a non-existing user/group name). Thus, these tests can currently not succeed on win32.
# item metadata has valid uid/gid, but non-existing user/group names. # item metadata has valid uid/gid, but non-existing user/group names.
item = Item(path="filename", uid=9, gid=10, user="udoesnotexist", group="gdoesnotexist") item = Item(path="filename", uid=9, gid=10, user="udoesnotexist", group="gdoesnotexist")