Re: replacing os.chdir calls with basedir config option

Dennis Gregorovic <[email protected]>
Newsgroups gmane.linux.rpm.metadata
Message-ID <[email protected]>
On Fri, 2005-11-11 at 08:44 -0500, Dennis Gregorovic wrote:
> I've started using createrepo as a library instead of a standalone app.
> The only issue that I've run into so far is that the os.chdir() calls
> can cause problems, especially if you have multiple threads using
> createrepo in parallel.
> 
> Attached is a patch that removes the os.chdir() calls and introduces a
> 'basedir' config option, settable with --basedir and defaulting to
> os.getcwd().
> 
> Thoughts?
> 
> -- Dennis

Oops... the last patch was just for genpkgmetadata.py.  Here's the one
for dumpMetadata.py.

-- Dennis

_______________________________________________
Rpm-metadata mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/rpm-metadata
createrepo-basedir2.patch (text/x-patch, 2.5 KB)
Index: dumpMetadata.py
===================================================================
RCS file: /cvsroot/metadata/cvs-root/generate/dumpMetadata.py,v
retrieving revision 1.32
diff -w -u -r1.32 dumpMetadata.py
--- dumpMetadata.py	2 Nov 2005 20:23:56 -0000	1.32
+++ dumpMetadata.py	11 Nov 2005 13:46:09 -0000
@@ -212,19 +212,16 @@
     """each rpm is one object, you pass it an rpm file
        it opens the file, and pulls the information out in bite-sized chunks :)
     """
-    def __init__(self, ts, filename, options):
+    def __init__(self, ts, basedir, filename, options):
         try:
-            stats = os.stat(filename)
+            stats = os.stat(os.path.join(basedir, filename))
             self.size = stats[6]
             self.mtime = stats[8]
             del stats
-        except OSError, e:
-            raise MDError, "Error Stat'ing file %s" % filename
-        
         self.options = options
         self.localurl = options['baseurl']
         self.relativepath = filename
-        fd = returnFD(filename)
+            fd = returnFD(os.path.join(basedir, filename))
         self.hdr = returnHdr(ts, fd)
         os.lseek(fd, 0, 0)
         fo = os.fdopen(fd, 'rb')
@@ -232,6 +229,9 @@
         fo.seek(0)
         (self.rangestart, self.rangeend) = byteranges(fo)
         fo.close()
+        except OSError, e:
+            raise MDError, "Error operating on file %s %s %s" % (os.getcwd(), basedir, filename)
+
         del fo
         del fd
         
@@ -737,11 +737,11 @@
     
     
     for (file, ftype) in workfiles:
-        zfo = _gzipOpen(os.path.join(cmds['tempdir'], file))
+        zfo = _gzipOpen(os.path.join(cmds['basedir'], cmds['tempdir'], file))
         uncsum = getChecksum(sumtype, zfo)
         zfo.close()
-        csum = getChecksum(sumtype, os.path.join(cmds['tempdir'], file))
-        timestamp = os.stat(os.path.join(cmds['tempdir'], file))[8]
+        csum = getChecksum(sumtype, os.path.join(cmds['basedir'], cmds['tempdir'], file))
+        timestamp = os.stat(os.path.join(cmds['basedir'], cmds['tempdir'], file))[8]
         data = node.newChild(None, 'data', None)
         data.newProp('type', ftype)
         location = data.newChild(None, 'location', None)
@@ -760,7 +760,7 @@
         timestamp = os.stat(grpfile)[8]
         sfile = os.path.basename(grpfile)
         fo = open(grpfile, 'r')
-        output = open(os.path.join(cmds['tempdir'], sfile), 'w')
+        output = open(os.path.join(cmds['basedir'], cmds['tempdir'], sfile), 'w')
         output.write(fo.read())
         output.close()
         fo.seek(0)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.