extras-buildsys/server Repo.py,1.16.2.4,1.16.2.5

Daniel Williams (dcbw) fedora-extras-commits at redhat.com
Fri Jun 2 14:59:25 UTC 2006


Author: dcbw

Update of /cvs/fedora/extras-buildsys/server
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv32274/server

Modified Files:
      Tag: STABLE_0_4
	Repo.py 
Log Message:
2006-06-02  Dan Williams  <dcbw at redhat.com>

    Patch from Michael Schwendt <bugs.michael at gmx.net>
    * server/Repo.py
        - (_update_repo): use lockfiles for repo directories to allow
            coordination with external scripts that manipulate repodirs




Index: Repo.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/server/Repo.py,v
retrieving revision 1.16.2.4
retrieving revision 1.16.2.5
diff -u -r1.16.2.4 -r1.16.2.5
--- Repo.py	17 May 2006 14:01:46 -0000	1.16.2.4
+++ Repo.py	2 Jun 2006 14:59:17 -0000	1.16.2.5
@@ -25,6 +25,9 @@
 import EmailUtils
 from plague import DebugUtils
 
+# Lockfile used by external scripts to ensure mutual exclusion
+# from concurrent access to the repository's directory
+REPO_LOCKFILE_NAME = ".repo-update.lock"
 
 class Repo(threading.Thread):
     """ Represents an on-disk repository of RPMs and manages updates to the repo. """
@@ -41,6 +44,7 @@
         self._repodir = os.path.join(repodir, target_str)
         if not os.path.exists(self._repodir):
             os.makedirs(self._repodir)
+        self._lockfile_path = os.path.join(self._repodir, REPO_LOCKFILE_NAME)
 
         self._repo_cache_dir = os.path.join(repodir, "cache", target_str)
         if not os.path.exists(self._repo_cache_dir):
@@ -89,6 +93,25 @@
 
     def _update_repo(self):
         """ Copy new RPMS to each repo, and update each repo at the end """
+        target_string = self._target_cfg.target_string()
+        lockfile = None
+        locked = False
+
+        # Try to open the lockfile, creating it if it doesn't exist
+        try:
+            lockfile = open(self._lockfile_path, 'w')
+        except OSError, (errno, strerr):
+            print "Repo Error (%s): opening lockfile %s failed.  Output: (errno %d) '%s'" % (target_string,
+                    self._lockfile_path, errno, strerr)
+
+        if lockfile:
+            try:
+                rc = fcntl.flock(lockfile, fcntl.LOCK_EX)
+                locked = True
+            except IOError, (errno, strerr):
+                print "Repo Error (%s): locking repodir with %s failed.  Output: (errno %d) '%s'" % (target_string,
+                        self._lockfile_path, errno, strerr)
+
         for buildjob in self._repo_additions:
             # Ensure all the files are accessible
             success = True
@@ -120,7 +143,15 @@
 
         (s, o) = commands.getstatusoutput('/usr/bin/createrepo -q -c %s -x "*.src.rpm" -x "*-debuginfo-*" %s' % (self._repo_cache_dir, self._repodir))
         if s != 0:
-            print "Error: createrepo failed with exit status %d!  Output: '%s'" % (s, o)
+            print "Repo Error (%s): createrepo failed with exit status %d!  Output: '%s'" % (target_string, s, o)
+
+        # Unlock repo lockfile
+        if lockfile and locked:
+            fcntl.flock(lockfile, fcntl.LOCK_UN)
+        if lockfile:
+            lockfile.close()
+
+        del target_string
 
     def _run_repo_script(self):
         target_str = self._target_cfg.target_string()




More information about the scm-commits mailing list