poldek: poldek/pm/pset/pset.c, poldek/poldek_util.h, poldek/pkgfetch.c, pol...

mis mis at pld-linux.org
Tue May 13 17:55:38 CEST 2008


Author: mis                          Date: Tue May 13 15:55:38 2008 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- copy packages from local repos too if --fetch to custom dir requested (#101)

---- Files affected:
poldek/poldek/pm/pset:
   pset.c (1.31 -> 1.32) 
poldek/poldek:
   poldek_util.h (1.7 -> 1.8) , pkgfetch.c (1.30 -> 1.31) , misc.c (1.63 -> 1.64) 

---- Diffs:

================================================================
Index: poldek/poldek/pm/pset/pset.c
diff -u poldek/poldek/pm/pset/pset.c:1.31 poldek/poldek/pm/pset/pset.c:1.32
--- poldek/poldek/pm/pset/pset.c:1.31	Sat Feb  2 22:49:05 2008
+++ poldek/poldek/pm/pset/pset.c	Tue May 13 17:55:32 2008
@@ -263,103 +263,6 @@
     free(db);
 }
 
-static void process_output(struct p_open_st *st, int verbose_level) 
-{
-    int endl = 1, nlines = 0;
-    
-    while (1) {
-        struct timeval to = { 0, 200000 };
-        fd_set fdset;
-        int rc;
-        
-        if (p_wait(st)) {
-            int yes = 1;
-            ioctl(st->fd, FIONBIO, &yes);
-        }
-        
-        FD_ZERO(&fdset);
-        FD_SET(st->fd, &fdset);
-        if ((rc = select(st->fd + 1, &fdset, NULL, NULL, &to)) < 0) {
-            if (errno == EAGAIN || errno == EINTR)
-                continue;
-            break;
-            
-        } else if (rc == 0) {
-            if (p_wait(st))
-                break;
-
-        } else if (rc > 0) {
-            char  buf[4096], *fmt = "_%s";
-            int   n, i;
-
-            if ((n = read(st->fd, buf, sizeof(buf) - 1)) <= 0)
-                break;
-            
-            buf[n] = '\0';
-            if (buf[n - 1] == '\n') {
-                buf[n - 1] = '\0'; /* deal with last_endlined -> move '\n' to fmt */
-                fmt = "_%s\n";
-            }
-            
-            msg_tty(verbose_level, fmt, buf);
-
-            /* logged to file? -> prefix lines with 'rpm: ' */                
-            for (i=0; i < n; i++) {
-                int c = buf[i];
-                
-                if (c == '\r')
-                    continue;
-                
-                if (c == '\n')
-                    endl = 1;
-                    
-                if (endl) {
-                    endl = 0;
-                    //if (nlines) 
-                    //    msg_f(0, "_\n");
-                    nlines++;
-                    msg_f(0, "cp: %c", c);
-                    continue;
-                }
-                msg_f(0, "_%c", c);
-            }
-        }
-    }
-    
-    return;
-}
-
-
-static int do_cp(const char *src, const char *dst)
-{
-    struct p_open_st pst;
-    unsigned p_open_flags = P_OPEN_KEEPSTDIN;
-    char *argv[5];
-    int n, ec;
-    
-    p_st_init(&pst);
-
-    n = 0;
-    argv[n++] = "cp";
-//    argv[n++] = "-v";
-    argv[n++] = (char*)src;
-    argv[n++] = (char*)dst;
-    argv[n++] = NULL;
-
-    if (p_open(&pst, p_open_flags, "/bin/cp", argv) == NULL) {
-        if (pst.errmsg) {
-            logn(LOGERR, "%s", pst.errmsg);
-            p_st_destroy(&pst);
-        }
-    }
-
-    process_output(&pst, 1);
-    if ((ec = p_close(&pst) != 0))
-        logn(LOGERR, "cp %s: %s", src, pst.errmsg ? pst.errmsg : "copying failed");
-
-    p_st_destroy(&pst);
-    return ec == 0;
-}
 
 /* remember! don't touch any member */
 struct psetdb_it {
@@ -611,7 +514,7 @@
         }
     } else {
         if (link(pkgpath, tspath) != 0) {
-            if (!do_cp(pkgpath, tspath))
+            if (!poldek_util_copy_file(pkgpath, tspath))
                 return 0;
         }
     }
@@ -807,7 +710,7 @@
             msgn_tty(1, "cp %s %s\n", n_basenam(path), dstpath);
             
             if (!ts->getop(ts, POLDEK_OP_JUSTDB)) {
-                if (!do_cp(path, dstpath)) {
+                if (!poldek_util_copy_file(path, dstpath)) {
                     rc = 0;
                     break;
                 }

================================================================
Index: poldek/poldek/poldek_util.h
diff -u poldek/poldek/poldek_util.h:1.7 poldek/poldek/poldek_util.h:1.8
--- poldek/poldek/poldek_util.h:1.7	Sun Aug 20 20:14:58 2006
+++ poldek/poldek/poldek_util.h	Tue May 13 17:55:33 2008
@@ -26,4 +26,6 @@
 
 const char *poldek_util_expand_env_vars(char *dest, int size, const char *str);
 
+int poldek_util_copy_file(const char *src, const char *dst);
+
 #endif

================================================================
Index: poldek/poldek/pkgfetch.c
diff -u poldek/poldek/pkgfetch.c:1.30 poldek/poldek/pkgfetch.c:1.31
--- poldek/poldek/pkgfetch.c:1.30	Sat Feb  2 22:49:04 2008
+++ poldek/poldek/pkgfetch.c	Tue May 13 17:55:33 2008
@@ -61,12 +61,12 @@
 }
 
 void packages_fetch_summary(struct pm_ctx *pmctx, const tn_array *pkgs,
-                            const char *destdir, int nosubdirs)
+                            const char *destdir, int is_destdir_custom)
 {
     long bytesget = 0, bytesdownload = 0, bytesused = 0;
     int i;
 
-    n_assert(nosubdirs == 0); /* not implemented */
+    n_assert(is_destdir_custom == 0); /* not implemented */
     for (i=0; i < n_array_size(pkgs); i++) {
         struct pkg  *pkg = n_array_nth(pkgs, i);
         char        path[PATH_MAX];
@@ -116,7 +116,7 @@
 }
 
 int packages_fetch(struct pm_ctx *pmctx,
-                   tn_array *pkgs, const char *destdir, int nosubdirs)
+                   tn_array *pkgs, const char *destdir, int is_destdir_custom)
 {
     int       i, nerr, urltype, ncdroms;
     tn_array  *urls = NULL, *packages = NULL;
@@ -165,11 +165,13 @@
                     nerr++;
                 }
             }
+            if (is_destdir_custom)
+                poldek_util_copy_file(path, destdir);
             continue;
         }
         
         
-        if (nosubdirs) {
+        if (is_destdir_custom) {
             snprintf(path, sizeof(path), "%s/%s", destdir, pkg_basename);
             
         } else {
@@ -236,7 +238,7 @@
         urls = n_hash_get(urls_h, pkgpath);
         packages = n_hash_get(pkgs_h, pkgpath);
         real_destdir = destdir;
-        if (nosubdirs == 0) {
+        if (is_destdir_custom == 0) {
             char buf[1024];
             
             vf_url_as_dirpath(buf, sizeof(buf), pkgpath);

================================================================
Index: poldek/poldek/misc.c
diff -u poldek/poldek/misc.c:1.63 poldek/poldek/misc.c:1.64
--- poldek/poldek/misc.c:1.63	Sun Feb 24 15:54:21 2008
+++ poldek/poldek/misc.c	Tue May 13 17:55:33 2008
@@ -36,6 +36,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/param.h>          /* for PATH_MAX */
+#include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <pwd.h>
@@ -78,11 +79,11 @@
 }
 
 static
-int mdigest(FILE *stream, unsigned char *md, int *md_size, int digest_type)
+int mdigest(FILE *stream, unsigned char *md, unsigned *md_size, int digest_type)
 {
     unsigned char buf[8*1024];
     EVP_MD_CTX ctx;
-    int n, nn = 0;
+    unsigned n, nn = 0;
 
 
     n_assert(md_size && *md_size);
@@ -743,3 +744,99 @@
     return getenv("POLDEK_TESTING") != NULL;
 }
 
+static void process_output(struct p_open_st *st, int verbose_level) 
+{
+    int endl = 1, nlines = 0;
+    
+    while (1) {
+        struct timeval to = { 0, 200000 };
+        fd_set fdset;
+        int rc;
+        
+        if (p_wait(st)) {
+            int yes = 1;
+            ioctl(st->fd, FIONBIO, &yes);
+        }
+        
+        FD_ZERO(&fdset);
+        FD_SET(st->fd, &fdset);
+        if ((rc = select(st->fd + 1, &fdset, NULL, NULL, &to)) < 0) {
+            if (errno == EAGAIN || errno == EINTR)
+                continue;
+            break;
+            
+        } else if (rc == 0) {
+            if (p_wait(st))
+                break;
+
+        } else if (rc > 0) {
+            char  buf[4096], *fmt = "_%s";
+            int   n, i;
+
+            if ((n = read(st->fd, buf, sizeof(buf) - 1)) <= 0)
+                break;
+            
+            buf[n] = '\0';
+            if (buf[n - 1] == '\n') {
+                buf[n - 1] = '\0'; /* deal with last_endlined -> move '\n' to fmt */
+                fmt = "_%s\n";
+            }
+            
+            msg_tty(verbose_level, fmt, buf);
+
+            /* logged to file? -> prefix lines with 'rpm: ' */                
+            for (i=0; i < n; i++) {
+                int c = buf[i];
+                
+                if (c == '\r')
+                    continue;
+                
+                if (c == '\n')
+                    endl = 1;
+                    
+                if (endl) {
+                    endl = 0;
+                    //if (nlines) 
+                    //    msg_f(0, "_\n");
+                    nlines++;
+                    msg_f(0, "cp: %c", c);
+                    continue;
+                }
+                msg_f(0, "_%c", c);
+            }
+        }
+    }
+    
+    return;
+}
+
+int poldek_util_copy_file(const char *src, const char *dst)
+{
+    struct p_open_st pst;
+    unsigned p_open_flags = P_OPEN_KEEPSTDIN;
+    char *argv[5];
+    int n, ec;
+    
+    p_st_init(&pst);
+
+    n = 0;
+    argv[n++] = "cp";
+//    argv[n++] = "-v";
+    argv[n++] = (char*)src;
+    argv[n++] = (char*)dst;
+    argv[n++] = NULL;
+
+    if (p_open(&pst, p_open_flags, "/bin/cp", argv) == NULL) {
+        if (pst.errmsg) {
+            logn(LOGERR, "%s", pst.errmsg);
+            p_st_destroy(&pst);
+        }
+    }
+
+    process_output(&pst, 1);
+    if ((ec = p_close(&pst) != 0))
+        logn(LOGERR, "cp %s: %s", src, pst.errmsg ? pst.errmsg : "copying failed");
+
+    p_st_destroy(&pst);
+    return ec == 0;
+}
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/pm/pset/pset.c?r1=1.31&r2=1.32&f=u
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/poldek_util.h?r1=1.7&r2=1.8&f=u
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/pkgfetch.c?r1=1.30&r2=1.31&f=u
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/misc.c?r1=1.63&r2=1.64&f=u



More information about the pld-cvs-commit mailing list