From f527bfe2b3daa2bcffd292cfc0eb7f9a4c5a179e Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Fri, 20 Aug 2010 12:12:36 -0400 Subject: [PATCH] handle broken locking on nfs target dirs better if database is true. - sqlite dbs don't like being made on locations without locking available. - if we know we're going to be creating dbs then we should attempt to lock before doing anything else and bail out nicely if we can't get an exclusive lock --- createrepo/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/createrepo/__init__.py b/createrepo/__init__.py index 120e1b0..e06da99 100644 --- a/createrepo/__init__.py +++ b/createrepo/__init__.py @@ -25,6 +25,8 @@ from bz2 import BZ2File from urlgrabber import grabber import tempfile import stat +import fcntl + from yum import misc, Errors, to_unicode from yum.sqlutils import executeSQL @@ -197,6 +199,18 @@ class MetaDataGenerator: if not checkAndMakeDir(temp_final): raise MDError, _('Cannot create/verify %s') % temp_final + if self.conf.database: + # do flock test on temp_final, temp_output + # if it fails raise MDError + for direc in [temp_final, temp_output]: + f = open(direc + '/locktest', 'w') + try: + fcntl.flock(f.fileno(), fcntl.LOCK_EX) + except (OSError, IOError), e: + raise MDError, _("Could not create exclusive lock in %s and sqlite database generation enabled. Is this path on nfs? Is your lockd running?") % direc + else: + os.unlink(direc + '/locktest') + if self.conf.deltas: temp_delta = os.path.join(self.conf.outputdir, self.conf.delta_relative) -- 2.34.1