mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #726 from YunoHost/stupid-tar-leading-dot-issue
[fix] Stupid issue with files inside tar : foo is not the same as ./foo
This commit is contained in:
commit
5d88301cd4
1 changed files with 20 additions and 7 deletions
|
@ -1850,11 +1850,19 @@ class TarBackupMethod(BackupMethod):
|
|||
# Mount the tarball
|
||||
logger.debug(m18n.n("restore_extracting"))
|
||||
tar = tarfile.open(self._archive_file, "r:gz")
|
||||
tar.extract('info.json', path=self.work_dir)
|
||||
|
||||
try:
|
||||
if "info.json" in tar.getnames():
|
||||
leading_dot = ""
|
||||
tar.extract('info.json', path=self.work_dir)
|
||||
elif "./info.json" in tar.getnames():
|
||||
leading_dot = "./"
|
||||
tar.extract('./info.json', path=self.work_dir)
|
||||
|
||||
if "backup.csv" in tar.getnames():
|
||||
tar.extract('backup.csv', path=self.work_dir)
|
||||
except KeyError:
|
||||
elif "./backup.csv" in tar.getnames():
|
||||
tar.extract('./backup.csv', path=self.work_dir)
|
||||
else:
|
||||
# Old backup archive have no backup.csv file
|
||||
pass
|
||||
|
||||
|
@ -1876,12 +1884,12 @@ class TarBackupMethod(BackupMethod):
|
|||
system_part = system_part.replace("_", "/") + "/"
|
||||
subdir_and_files = [
|
||||
tarinfo for tarinfo in tar.getmembers()
|
||||
if tarinfo.name.startswith(system_part)
|
||||
if tarinfo.name.startswith(leading_dot+system_part)
|
||||
]
|
||||
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
||||
subdir_and_files = [
|
||||
tarinfo for tarinfo in tar.getmembers()
|
||||
if tarinfo.name.startswith("hooks/restore/")
|
||||
if tarinfo.name.startswith(leading_dot+"hooks/restore/")
|
||||
]
|
||||
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
||||
|
||||
|
@ -1889,7 +1897,7 @@ class TarBackupMethod(BackupMethod):
|
|||
for app in apps_targets:
|
||||
subdir_and_files = [
|
||||
tarinfo for tarinfo in tar.getmembers()
|
||||
if tarinfo.name.startswith("apps/" + app)
|
||||
if tarinfo.name.startswith(leading_dot+"apps/" + app)
|
||||
]
|
||||
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
||||
|
||||
|
@ -2230,7 +2238,12 @@ def backup_info(name, with_details=False, human_readable=False):
|
|||
tar = tarfile.open(archive_file, "r:gz")
|
||||
info_dir = info_file + '.d'
|
||||
try:
|
||||
tar.extract('info.json', path=info_dir)
|
||||
if "info.json" in tar.getnames():
|
||||
tar.extract('info.json', path=info_dir)
|
||||
elif "./info.json" in tar.getnames():
|
||||
tar.extract('./info.json', path=info_dir)
|
||||
else:
|
||||
raise KeyError
|
||||
except KeyError:
|
||||
logger.debug("unable to retrieve '%s' inside the archive",
|
||||
info_file, exc_info=1)
|
||||
|
|
Loading…
Add table
Reference in a new issue