From 9dfc73b8a1303de53e6d7938fbfcca9dfcb08d61 Mon Sep 17 00:00:00 2001 From: idziubenko Date: Wed, 24 Nov 2021 09:33:50 +0300 Subject: [PATCH] now if repo's .git is damaged redownloads repo, but doesn't alter folder --- pym/update/update.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pym/update/update.py b/pym/update/update.py index 8c0e8a1..0f8a972 100644 --- a/pym/update/update.py +++ b/pym/update/update.py @@ -230,6 +230,8 @@ class Update(MethodsInterface): status = git.getStatusInfo(rpath) if not status or status['files']: need_update = True + + except GitError as e: need_update = True if need_update: @@ -431,8 +433,18 @@ class Update(MethodsInterface): cb_progress=self.setProgress, clean=check_status, notask=fallback_sync) - removeDir(rpath) - shutil.move(rpath_new, rpath) + if not isinstance(e, NotGitError): + removeDir(rpath) + shutil.move(rpath_new, rpath) + else: + #delete everything in rpath dir, but not rpath itself + for root, dirs, files in os.walk(rpath): + for f in files: + os.unlink(os.path.join(root, f)) + for d in dirs: + shutil.rmtree(os.path.join(root, d)) + for i in os.listdir(rpath_new): + shutil.move(os.path.join(rpath_new, i), rpath) except OSError as e: raise UpdateError(_("Failed to modify the " "{repname} repository").format(