[Patch] createrepo --check option take two

Hans-Peter Jansen <[email protected]>
Newsgroups gmane.linux.rpm.metadata
Message-ID <[email protected]>
Hi Seth,

Here's a slightly reworked version of the --check option, it now checks 
the directory timestamp, containing the rpm, as it happened, that an 
older rpm appeared today in one of my rsyned suse update repos (due to 
some internal lags), which didn't triggered the rebuild, then.. 

As a nice plus, the number of stats are greatly decreased, if a dir in 
the repo is not up to date (not that it matters, compared to the 
following repo rebuild...). 

Do you think, it's worth to include it upstream now?

	Pete

_______________________________________________
Rpm-metadata mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/rpm-metadata
createrepo-check-option-v2.diff (text/x-diff, 5.4 KB)
--- genpkgmetadata.py	2005-05-24 11:31:35.035759189 +0200
+++ genpkgmetadata.py	2005-05-24 11:37:51.518579254 +0200
@@ -48,6 +48,7 @@
      -x, --exclude = files globs to exclude, can be specified multiple times
      -q, --quiet = run quietly
      -g, --groupfile <filename> to point to for group information (precreated)
+     -c, --check = don't recreate repo metadata, if timestamps are up to date
      -v, --verbose = run verbosely
      -s, --checksum = md5 or sha - select type of checksum to use (default: sha)
      -h, --help = show this help
@@ -131,6 +132,7 @@
     cmds['excludes'] = []
     cmds['baseurl'] = None
     cmds['groupfile'] = None
+    cmds['check'] = 0
     cmds['sumtype'] = 'sha'
     cmds['pretty'] = 0
 #    cmds['updategroupsonly'] = 0
@@ -138,9 +140,9 @@
     cmds['dir-pattern-match'] = ['.*bin\/.*', '^\/etc\/.*']
 
     try:
-        gopts, argsleft = getopt.getopt(args, 'phqVvg:s:x:u:', ['help', 'exclude=', 
+        gopts, argsleft = getopt.getopt(args, 'phqVvg:cs:x:u:', ['help', 'exclude=', 
                                             'quiet', 'verbose',
-                                            'baseurl=', 'groupfile=', 'checksum=',
+                                            'baseurl=', 'groupfile=', 'check', 'checksum=',
                                             'version', 'pretty'])
     except getopt.error, e:
         errorprint(_('Options Error: %s.') % e)
@@ -190,6 +192,8 @@
                     else:
                         errorprint(_('Error: groupfile %s cannot be found.' % a))
                         usage()
+            elif arg in ['-c', '--check']:
+                cmds['check'] = 1
             elif arg in ['-x', '--exclude']:
                 cmds['excludes'].append(a)
             elif arg in ['-p', '--pretty']:
@@ -210,15 +214,9 @@
         
     return cmds, directory
 
-def doPkgMetadata(cmds, ts):
+def doPkgMetadata(files, cmds, ts):
     """all the heavy lifting for the package metadata"""
-
-    # rpms we're going to be dealing with
-    files = []
-    files = getFileList('./', '.rpm', files)
-    files = trimRpms(files, cmds['excludes'])
     pkgcount = len(files)
-    
     # setup the base metadata doc
     basedoc = libxml2.newDoc("1.0")
     baseroot =  basedoc.newChild(None, "metadata", None)
@@ -407,15 +405,57 @@
                     errorprint(_('error in must be able to write to metadata files:\n  -> %s') % filepath)
                     os.chdir(curdir)
                     usage()
-                    
+
+
+    # rpms we're going to be dealing with
+    rpmfiles = []
+    rpmfiles = getFileList('./', '.rpm', rpmfiles)
+    rpmfiles = trimRpms(rpmfiles, cmds['excludes'])
+
+
+    # check, if the repo metadata is up to date
+    if cmds['check']:
+        repots = 0
+        # find oldest metadata file
+        for filename in ['primaryfile', 'filelistsfile', 'otherfile', 'repomdfile', 'groupfile']:
+            if not cmds[filename]:  # groupfile may not used
+                continue
+            filepath = os.path.join(cmds['finaldir'], cmds[filename])
+            if not os.path.exists(filepath):
+                # some files don't exist: redo metadata
+                repots = 0
+                break
+            ts = os.path.getmtime(filepath)
+            if repots < ts:
+                repots = ts
+        if repots:
+            # any rpm newer then oldest metadata file?
+            for filename in rpmfiles:
+                # check also the mtime of the dir, where the rpm resides to
+                # avoid a false positive, if an older rpm is mirrored lately
+                ts = os.path.getmtime(filename)
+                dirts = os.path.getmtime(os.path.dirname(filename))
+                if ts > repots or dirts > repots:
+                    repots = 0
+                    break
+            if repots:
+                # we're done
+                if not cmds['quiet']:
+                    print _('Repo metadata is up to date')
+                os.chdir(curdir)
+                return
+
+
     ts = rpm.TransactionSet()
     try:
-        doPkgMetadata(cmds, ts)
+        doPkgMetadata(rpmfiles, cmds, ts)
     except:
         # always clean up your messes
         os.chdir(curdir)
         raise
-    
+
+    del rpmfiles
+
     try:
         doRepoMetadata(cmds)
     except:
--- ChangeLog	2005-05-24 11:31:35.036759244 +0200
+++ ChangeLog	2005-05-24 11:40:13.808468035 +0200
@@ -1,3 +1,15 @@
+2005-05-24 11:38  Hans-Peter Jansen <[email protected]>
+
+	* genpkgmetadata.py:
+	-c option checks also the mtime of the dir containing the rpm
+	to avoid false positives, if an older rpm is mirrored lately.
+
+2005-05-12 11:31  Hans-Peter Jansen <[email protected]>
+
+	* genpkgmetadata.py, docs/createrepo.8:
+	-c, --check option added to short cut metadata creation, if 
+	filestamps are up to date.
+
 2005-01-18 02:14  skvidal
 
 	* Makefile, docs/Makefile: 
--- docs/createrepo.8	2005-05-24 11:31:35.035759189 +0200
+++ docs/createrepo.8	2005-05-24 11:32:24.715506440 +0200
@@ -1,4 +1,4 @@
-.TH "createrepo" "8" "2005 Jan 2" "Seth Vidal" ""
+.TH "createrepo" "8" "2005 May 12" "Seth Vidal" ""
 
 .SH "NAME"
 createrepo \- Create repomd (xml-rpm-metadata) repository
@@ -22,6 +22,8 @@
 A precreated xml filename to point to for group information.
 .br
 See examples section below for further explanation.
+.IP "\fB\-c --check\fP"
+Don't recreate repo metadata, if timestamps are up to date.
 .IP "\fB\-v --verbose\fP"
 Run verbosely.
 .IP "\fB\-s --checksum\fP <type>"
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.