extras-buildsys/server Repo.py,1.16.2.3.4.3,1.16.2.3.4.4
Michael Schwendt
mschwendt at fedoraproject.org
Thu Sep 4 20:24:56 UTC 2008
Author: mschwendt
Update of /cvs/fedora/extras-buildsys/server
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv17085/server
Modified Files:
Tag: Plague-0_4_5
Repo.py
Log Message:
fix server/Repo.py
Index: Repo.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/server/Repo.py,v
retrieving revision 1.16.2.3.4.3
retrieving revision 1.16.2.3.4.4
diff -u -r1.16.2.3.4.3 -r1.16.2.3.4.4
--- Repo.py 4 Sep 2008 02:14:20 -0000 1.16.2.3.4.3
+++ Repo.py 4 Sep 2008 20:24:55 -0000 1.16.2.3.4.4
@@ -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):
@@ -87,7 +91,27 @@
return True
return False
- def _update_repo(self, target_string):
+ def _update_repo_with_pushlock(self):
+ lockfile = None
+ try:
+ lockfile = open(self._lockfile_path, 'w')
+ rc = fcntl.flock(lockfile, fcntl.LOCK_EX)
+ except IOError, (errno, strerr):
+ target_str = self._target_cfg.target_string()
+ print "Repo Error (%s): opening lockfile %s failed. Output: (errno %d) '%s'" % (target_str, self._lockfile_path, errno, strerr)
+
+ try:
+ self._update_repo()
+ except:
+ if lockfile:
+ fcntl.flock(lockfile, fcntl.LOCK_UN)
+ lockfile.close()
+ raise
+ if lockfile:
+ fcntl.flock(lockfile, fcntl.LOCK_UN)
+ lockfile.close()
+
+ def _update_repo(self):
""" Copy new RPMS to each repo, and update each repo at the end """
for buildjob in self._repo_additions:
# Ensure all the files are accessible
@@ -201,7 +225,12 @@
if self._lock_count == 2:
target_str = self._target_cfg.target_string()
print "Repo '%s': updating repository metadata..." % target_str
- self._update_repo()
+ try:
+ self._update_repo_with_pushlock()
+ except IOError, (err, strerr):
+ print "Repo '%s': %s (%d)" % (target_str, strerr, err)
+ except OSError, e:
+ print "Repo '%s': %s" % (target_str, e)
print "Repo '%s': Done updating." % target_str
# If there's a repo script for this target, enter level 3
More information about the fedora-extras-commits
mailing list