Support actually removing git repositories from the filesystem and not
authorMagnus Hagander <magnus@hagander.net>
Thu, 12 Feb 2009 16:18:13 +0000 (17:18 +0100)
committerMagnus Hagander <magnus@hagander.net>
Thu, 12 Feb 2009 16:18:13 +0000 (17:18 +0100)
just the database.

gitdump.py

index 34d4301d51116fe50b118a79c1c20e3ba3887618..3acff7bc68e20e253a74b492d6a953b2483a054d 100644 (file)
@@ -1,3 +1,4 @@
+# vim: ai ts=4 sts=4 sw=4
 #!/usr/bin/env python
 
 """
@@ -39,10 +40,12 @@ class AuthorizedKeysDumper(object):
 
        def dumprepos(self):
                # FIXME: use a trigger to indicate if *anything at all* has changed
+               allrepos = {}
                curs = self.db.cursor()
                curs.execute("SELECT name,anonymous,web,description,initialclone,(SELECT min(first_name) FROM repository_permissions AS rp LEFT JOIN auth_user AS au ON au.username=rp.userid WHERE rp.level=2 AND rp.repository=r.repoid) FROM repositories AS r WHERE approved ORDER BY name")
                f = open("%s.tmp" % self.conf.get("paths", "gitweblist"), "w")
                for name, anon, web, description, initialclone, owner in curs:
+                       allrepos[name] = 1
                        # Check if this repository exists at all
                        if not os.path.isdir("%s/repos/%s" % (self.conf.get("paths", "githome"), name)):
                                # Does not exist, let's initialize a new one
@@ -92,6 +95,15 @@ class AuthorizedKeysDumper(object):
                os.chmod("%s.tmp" % self.conf.get("paths", "gitweblist"), 0644)
                os.rename("%s.tmp" % self.conf.get("paths", "gitweblist"), self.conf.get("paths", "gitweblist"))
 
+               # Now remove any repositories that have been deleted
+               for d in os.listdir("%s/repos/" % self.conf.get("paths", "githome")):
+                       if not allrepos.has_key(d):
+                               print "Removing repository %s" % d
+                               try:
+                                       shutil.rmtree("%s/repos/%s" % (self.conf.get("paths", "githome"), d))
+                               except Exception,e:
+                                       print "FAIL: unable to remove directory: %s" % e
+
 if __name__ == "__main__":
        c = ConfigParser.ConfigParser()
        c.read("pggit.settings")