Skip to content

Commit

Permalink
#56: Add retry of clone (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karina5005 authored Sep 8, 2023
1 parent 920420b commit 2f35c0d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions backup_github/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import shutil
import subprocess
import time
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -107,6 +108,13 @@ def __save_repo_content(self, repository, dir):
)
try:
subprocess_handle(subprocess.call, ["git", "clone", "--bare", repo_url])
if not os.path.exists(f"{repository}.git"):
time.sleep(10)
subprocess_handle(
subprocess.call, ["git", "clone", "--bare", repo_url]
)
if not os.path.exists(f"{repository}.git"):
raise subprocess.CalledProcessError
except subprocess.CalledProcessError:
shutil.rmtree(f"{dir}/{repository}")
logging.error(f"Repository {repository} backup error, will be skipped")
Expand Down
9 changes: 7 additions & 2 deletions backup_github/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ def subprocess_handle(func, args):
except subprocess.CalledProcessError as e:
logging.error("Subprocess call error")
logging.error("exit code: {}".format(e.returncode))
logging.error("stdout: {}".format(e.output.decode(sys.getfilesystemencoding())))
logging.error("stderr: {}".format(e.stderr.decode(sys.getfilesystemencoding())))
if e.output:
logging.error(
"stdout: {}".format(e.output.decode(sys.getfilesystemencoding()))
)
logging.error(
"stderr: {}".format(e.stderr.decode(sys.getfilesystemencoding()))
)
raise e


Expand Down

0 comments on commit 2f35c0d

Please sign in to comment.