createrepo/__init__.py

[email protected] Fri, 20 Aug 2010 16:16:18 +0000 (UTC)
Newsgroups gmane.linux.rpm.metadata
Message-ID <[email protected]>
 createrepo/__init__.py |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

New commits:
commit f527bfe2b3daa2bcffd292cfc0eb7f9a4c5a179e
Author: Seth Vidal <[email protected]>
Date:   Fri Aug 20 12:12:36 2010 -0400

    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

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)