This commit is contained in:
ChrisTerBeke 2018-05-17 09:32:18 +02:00
parent fb40ea13cc
commit f00459e4cc

View file

@ -138,7 +138,8 @@ class Backup:
return extracted
def _extractArchive(self, archive: "ZipFile", target_path: str) -> bool:
@staticmethod
def _extractArchive(archive: "ZipFile", target_path: str) -> bool:
"""
Extract the whole archive to the given target path.
:param archive: The archive as ZipFile.
@ -147,7 +148,7 @@ class Backup:
"""
Logger.log("d", "Removing current data in location: %s", target_path)
try:
shutil.rmtree(target_path, onerror=self._onRemoveError)
shutil.rmtree(target_path)
except PermissionError as error:
# This happens if a file is already opened by another program, usually only the log file.
# For now we just ignore this as it doesn't harm the restore process.
@ -156,10 +157,3 @@ class Backup:
Logger.log("d", "Extracting backup to location: %s", target_path)
archive.extractall(target_path)
return True
@staticmethod
def _onRemoveError(*args):
import stat # needed for file stat
func, path, _ = args # onerror returns a tuple containing function, path and exception info
os.chmod(path, stat.S_IWRITE)
os.remove(path)