poldek: poldek/pkgdir/dir/dir.c, poldek/pkgdir/source.c - added pk...

mis mis at pld-linux.org
Fri Jun 22 00:27:01 CEST 2007


Author: mis                          Date: Thu Jun 21 22:27:01 2007 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- added pkg_uinf loading on demand for dir indexes

---- Files affected:
poldek/poldek/pkgdir/dir:
   dir.c (1.26 -> 1.27) 
poldek/poldek/pkgdir:
   source.c (1.40 -> 1.41) 

---- Diffs:

================================================================
Index: poldek/poldek/pkgdir/dir/dir.c
diff -u poldek/poldek/pkgdir/dir/dir.c:1.26 poldek/poldek/pkgdir/dir/dir.c:1.27
--- poldek/poldek/pkgdir/dir/dir.c:1.26	Sun Aug 20 20:14:58 2006
+++ poldek/poldek/pkgdir/dir/dir.c	Fri Jun 22 00:26:56 2007
@@ -129,6 +129,54 @@
     }
 }
 
+static int is_rpmfile(const char *path, struct stat *fst) 
+{
+    struct stat st;
+    
+    if (stat(path, &st) != 0) {
+        logn(LOGERR, "stat %s: %m", path);
+        return 0;
+    }
+
+    if (!S_ISREG(st.st_mode)) {
+        logn(LOGERR, "%s: not a file", path);
+        return 0;
+    }
+
+    if (fst)
+        *fst = st;
+
+    return 1;
+}
+
+
+static 
+struct pkguinf *load_pkguinf(tn_alloc *na, const struct pkg *pkg,
+                             void *ptr, tn_array *langs)
+{
+    struct pkguinf *pkgu = NULL;
+    char path[PATH_MAX];
+    Header h;
+
+    ptr = ptr;     /* unused pkgdir_data */
+    langs = langs; /* ignored, selective retrieving no supported */
+
+    snprintf(path, sizeof(path), "%s/%s", pkg->pkgdir->idxpath,
+             pkg_filename_s(pkg));
+
+    if (!is_rpmfile(path, NULL))
+        return NULL;
+    
+    if (!pm_rpmhdr_loadfile(path, &h)) {
+        logn(LOGWARN, "%s: read header failed", n_basenam(path));
+        return NULL;
+    }
+    
+    pkgu = pkguinf_ldrpmhdr(na, h);
+    
+    pm_rpmhdr_free(h);
+    return pkgu;
+}
 
 static
 int load_dir(struct pkgdir *pkgdir,
@@ -158,9 +206,7 @@
     while ((ent = readdir(dir))) {
         char path[PATH_MAX];
         struct pkg *pkg = NULL;
-        tn_array *pkg_langs;
         Header h = NULL;
-
         
         if (fnmatch("*.rpm", ent->d_name, 0) != 0) 
             continue;
@@ -169,13 +215,8 @@
         //    continue;
         
         snprintf(path, sizeof(path), "%s%s%s", dirpath, sepchr, ent->d_name);
-        
-        if (stat(path, &st) != 0) {
-            logn(LOGERR, "stat %s: %m", path);
-            continue;
-        }
-        
-        if (!S_ISREG(st.st_mode))
+
+        if (!is_rpmfile(path, &st))
             continue;
 
         if (mtime_index) {
@@ -187,9 +228,8 @@
                 remap_groupid(pkg, pkgroups, prev_pkgdir);
             }
         }
-        
 
-        if (pkg == NULL) {
+        if (pkg == NULL) {  /* mtime changed, but try compare content */
             if (!pm_rpmhdr_loadfile(path, &h)) {
                 logn(LOGWARN, "%s: read header failed, skipped", path);
                 continue;
@@ -197,7 +237,7 @@
             
             //if (rpmhdr_issource(h)) /* omit src.rpms */
             //    continue;
-
+            
             if (prev_pkgdir) {
                 pkg = search_in_prev(prev_pkgdir, h, ent->d_name, &st);
                 if (pkg) {
@@ -208,31 +248,45 @@
                 }
             }
         }
+
+        if (pkg == NULL) {  /* not exists in previous index */
+            char **langs;
             
-        
-        if (pkg == NULL) {      /* not in previous index */
             nnew++;
-            n_assert(h);
+            n_assert(h);        /* loaded in previous if block */
             msgn(3, "%s: loading header...", n_basenam(path));
-            pkg = pm_rpm_ldhdr(na, h, n_basenam(path), st.st_size,
-                               PKG_LDWHOLE);
-                
+            pkg = pm_rpm_ldhdr(na, h, n_basenam(path), st.st_size, PKG_LDWHOLE);
+            n_assert(pkg);
+            
+            pkg->load_pkguinf = load_pkguinf;
+
+            if ((langs = pm_rpmhdr_langs(h))) {
+                int i = 0;
+                while (langs[i])
+                    pkgdir__update_avlangs(pkgdir, langs[i++], 1);
+                free(langs);
+            }
+            pkg->groupid = pkgroup_idx_update_rpmhdr(pkgroups, h);
+            
+            n_assert((ldflags & PKGDIR_LD_DESC) == 0);
+            
             if (ldflags & PKGDIR_LD_DESC) {
+                tn_array *langs;
+                
                 pkg->pkg_pkguinf = pkguinf_ldrpmhdr(na, h);
                 pkg_set_ldpkguinf(pkg);
-                if ((pkg_langs = pkguinf_langs(pkg->pkg_pkguinf))) {
+                if ((langs = pkguinf_langs(pkg->pkg_pkguinf))) {
                     int i;
                         
-                    for (i=0; i < n_array_size(pkg_langs); i++)
+                    for (i=0; i < n_array_size(langs); i++)
                         pkgdir__update_avlangs(pkgdir,
-                                               n_array_nth(pkg_langs, i), 1);
+                                               n_array_nth(langs, i), 1);
                 }
             }
-            pkg->groupid = pkgroup_idx_update_rpmhdr(pkgroups, h);
         }
 
         if (h)
-            headerFree(h);
+            pm_rpmhdr_free(h);
             
         if (pkg) {
             pkg->fmtime = st.st_mtime;
@@ -244,7 +298,7 @@
             msg(1, "_%d..", n);
     }
 
-    /* if there are ones from prev_pkgdir then assume that
+    /* if there are packages from prev_pkgdir then assume that
        they provide all avlangs */
     
     if (prev_pkgdir && n_array_size(pkgs) - nnew > 0) { 

================================================================
Index: poldek/poldek/pkgdir/source.c
diff -u poldek/poldek/pkgdir/source.c:1.40 poldek/poldek/pkgdir/source.c:1.41
--- poldek/poldek/pkgdir/source.c:1.40	Fri May 12 01:47:38 2006
+++ poldek/poldek/pkgdir/source.c	Fri Jun 22 00:26:56 2007
@@ -1028,9 +1028,6 @@
         pkgdir->prev_pkgdir = pdir;
     }
 
-    if (source_is_type(src, "dir"))
-        ldflags |= PKGDIR_LD_DESC;
-    
     rc = 0;
     if (pkgdir_load(pkgdir, NULL, ldflags)) {
         n_assert((pkgdir->_ldflags & PKGDIR_LD_DOIGNORE) == 0);
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/poldek/poldek/pkgdir/dir/dir.c?r1=1.26&r2=1.27&f=u
    http://cvs.pld-linux.org/poldek/poldek/pkgdir/source.c?r1=1.40&r2=1.41&f=u



More information about the pld-cvs-commit mailing list