Add symlink support to StashedUninstallPathSet

This commit is contained in:
Stéphane Bidoul (ACSONE) 2019-08-24 23:04:01 +02:00
parent 75a12ff423
commit db3320e462
No known key found for this signature in database
GPG Key ID: BCAB2555446B5B92
1 changed files with 5 additions and 3 deletions

View File

@ -267,14 +267,16 @@ class StashedUninstallPathSet(object):
def stash(self, path):
# type: (str) -> str
"""Stashes the directory or file and returns its new location.
Handle symlinks as files to avoid modifying the symlink targets.
"""
if os.path.isdir(path):
path_is_dir = os.path.isdir(path) and not os.path.islink(path)
if path_is_dir:
new_path = self._get_directory_stash(path)
else:
new_path = self._get_file_stash(path)
self._moves.append((path, new_path))
if os.path.isdir(path) and os.path.isdir(new_path):
if (path_is_dir and os.path.isdir(new_path)):
# If we're moving a directory, we need to
# remove the destination first or else it will be
# moved to inside the existing directory.
@ -301,7 +303,7 @@ class StashedUninstallPathSet(object):
for new_path, path in self._moves:
try:
logger.debug('Replacing %s from %s', new_path, path)
if os.path.isfile(new_path):
if os.path.isfile(new_path) or os.path.islink(new_path):
os.unlink(new_path)
elif os.path.isdir(new_path):
rmtree(new_path)