chiark / gitweb /
server: rely on rsync to delete files from git-mirror
authorHans-Christoph Steiner <hans@eds.org>
Tue, 11 Apr 2017 19:29:55 +0000 (21:29 +0200)
committerHans-Christoph Steiner <hans@eds.org>
Wed, 12 Apr 2017 13:04:04 +0000 (15:04 +0200)
Instead of each time deleting the whole local git-mirror repo, and
recreating it, this just deletes the .git/ dir, then lets the rsync in
_local_sync() handle deleting anything that should no longer be in the repo.

fdroidserver/server.py

index 5bd146610b155d345fc652a9d75ab09f5ad7b680..df8d5c80ddc0408f229fa57e82ffdeabb6454900 100644 (file)
@@ -227,24 +227,23 @@ def update_servergitmirrors(servergitmirrors, repo_section):
     import git
     # right now we support only 'repo' git-mirroring
     if repo_section == 'repo':
-        # create a new git-mirror folder
-        repo_dir = os.path.join('.', 'git-mirror/')
-
-        # remove if already present
-        if os.path.isdir(repo_dir):
-            shutil.rmtree(repo_dir)
+        git_mirror_path = 'git-mirror'
+        dotgit = os.path.join(git_mirror_path, '.git')
+        if not os.path.isdir(git_mirror_path):
+            os.mkdir(git_mirror_path)
+        elif os.path.isdir(dotgit):
+            shutil.rmtree(dotgit)
+
+        fdroid_repo_path = os.path.join(git_mirror_path, "fdroid")
+        _local_sync(repo_section, fdroid_repo_path)
 
-        repo = git.Repo.init(repo_dir)
+        repo = git.Repo.init(git_mirror_path)
 
         for mirror in servergitmirrors:
             hostname = re.sub(r'\W*\w+\W+(\w+).*', r'\1', mirror)
             repo.create_remote(hostname, mirror)
             logging.info('Mirroring to: ' + mirror)
 
-        # copy local 'repo' to 'git-mirror/fdroid/repo directory' with _local_sync
-        fdroid_repo_path = os.path.join(repo_dir, "fdroid")
-        _local_sync(repo_section, fdroid_repo_path)
-
         # sadly index.add don't allow the --all parameter
         repo.git.add(all=True)
         repo.index.commit("fdroidserver git-mirror")