poldek: poldek/misc.h, poldek/misc.c, poldek/install/misc.c, polde...

mis mis at pld-linux.org
Sun Jun 24 22:38:18 CEST 2007


Author: mis                          Date: Sun Jun 24 20:38:18 2007 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- goodbye dead code

---- Files affected:
poldek/poldek:
   misc.h (1.34 -> 1.35) , misc.c (1.55 -> 1.56) 
poldek/poldek/install:
   misc.c (1.9 -> 1.10) 
poldek/poldek/pm/pset:
   pset.c (1.22 -> 1.23) 
poldek/poldek/pm/rpm:
   rpmdb_it.c (1.3 -> 1.4) 

---- Diffs:

================================================================
Index: poldek/poldek/misc.h
diff -u poldek/poldek/misc.h:1.34 poldek/poldek/misc.h:1.35
--- poldek/poldek/misc.h:1.34	Sat Nov  5 18:47:55 2005
+++ poldek/poldek/misc.h	Sun Jun 24 22:38:13 2007
@@ -22,8 +22,7 @@
 #define DIGEST_SIZE_MD5  32
 #define DIGEST_SIZE_SHA1 40
 
-int mhexdigest(FILE *stream, unsigned char *mdhex, int *mdhex_size, int digest_type);
-int mdigest(FILE *stream, unsigned char *md, int *md_size, int digest_type); 
+int mhexdigest(FILE *stream, unsigned char *mdhex, int *mdhex_size, int type);
 
 /*
   Returns $TMPDIR or "/tmp" if $TMPDIR isn't set.
@@ -31,10 +30,6 @@
 
 */
 char *setup_cachedir(const char *path);
-const char *tmpdir(void);
-
-
-void die(void);
 
 char *trimslash(char *path);
 char *next_token(char **str, char delim, int *toklen);
@@ -44,13 +39,6 @@
 int mk_dir_parents(const char *path, const char *dn);
 
 const char *abs_path(char *buf, int size, const char *path);
-
-void process_cmd_output(struct p_open_st *st, const char *prefix);
-int lockfile(const char *lockfile);
-pid_t readlockfile(const char *lockfile);
-
-int mklock(const char *dir);
-
 
 struct pkgmark_set;
 void packages_iinf_display(int verbose_l, const char *prefix, tn_array *pkgs,

================================================================
Index: poldek/poldek/misc.c
diff -u poldek/poldek/misc.c:1.55 poldek/poldek/misc.c:1.56
--- poldek/poldek/misc.c:1.55	Sun Aug 20 20:14:58 2006
+++ poldek/poldek/misc.c	Sun Jun 24 22:38:13 2007
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2000 - 2005 Pawel A. Gajda <mis at k2.net.pl>
+  Copyright (C) 2000 - 2007 Pawel A. Gajda <mis at pld-linux.org>
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2 as
@@ -57,8 +57,6 @@
 #include "pkg.h"
 #include "poldek_term.h"
 #include "pkgmisc.h"
-//static
-//int valid_dir(const char *envname, const char *dir);
 
 int bin2hex(char *hex, int hex_size, const unsigned char *bin, int bin_size)
 {
@@ -75,31 +73,7 @@
     return nn;
 }
 
-
-int mhexdigest(FILE *stream, unsigned char *mdhex, int *mdhex_size, int digest_type)
-{
-    unsigned char md[128];
-    int  md_size = sizeof(md);
-
-    
-    if (mdigest(stream, md, &md_size, digest_type)) {
-        int i, n = 0, nn = 0;
-        
-        for (i=0; i < md_size; i++) {
-            n = n_snprintf(mdhex + nn, *mdhex_size - nn, "%02x", md[i]);
-            nn += n;
-        }
-        *mdhex_size = nn;
-        
-    } else {
-        *mdhex = '\0';
-        *mdhex_size = 0;
-    }
-
-    return *mdhex_size;
-}
-
-
+static
 int mdigest(FILE *stream, unsigned char *md, int *md_size, int digest_type)
 {
     unsigned char buf[8*1024];
@@ -132,39 +106,30 @@
     return *md_size;
 }
 
-
-char *setup_cachedir(const char *path) 
+int mhexdigest(FILE *stream, unsigned char *mdhex, int *mdhex_size, int digest_type)
 {
-    struct passwd *pw;
-    char *dir, *default_dn = ".poldek-cache";
-
-    if (path) {
-        if (vf_valid_path(path) && poldek_util_is_rwxdir(path)) 
-            return n_strdup(path);
-        else 
-            logn(LOGWARN, _("%s: invalid cachedir path, "
-                            "fallback to default"), path);
-    }
-    
-    if ((dir = getenv("TMPDIR")) && vf_valid_path(dir))
-        return n_strdup(dir);
-    
-    if ((pw = getpwuid(getuid())) == NULL)
-        return n_strdup(tmpdir());
+    unsigned char md[128];
+    int  md_size = sizeof(md);
 
-    if (!poldek_util_is_rwxdir(pw->pw_dir))
-        return n_strdup(tmpdir());
     
-    if (vf_valid_path(pw->pw_dir) && mk_dir(pw->pw_dir, default_dn)) {
-        char path[PATH_MAX];
-        snprintf(path, sizeof(path), "%s/%s", pw->pw_dir, default_dn);
-        return n_strdup(path);
+    if (mdigest(stream, md, &md_size, digest_type)) {
+        int i, n = 0, nn = 0;
+        
+        for (i=0; i < md_size; i++) {
+            n = n_snprintf(mdhex + nn, *mdhex_size - nn, "%02x", md[i]);
+            nn += n;
+        }
+        *mdhex_size = nn;
+        
+    } else {
+        *mdhex = '\0';
+        *mdhex_size = 0;
     }
 
-    return n_strdup(tmpdir());
+    return *mdhex_size;
 }
 
-const char *tmpdir(void) 
+static const char *tmpdir(void) 
 {
     struct stat st;
     static char *tmpdir = NULL;
@@ -213,45 +178,37 @@
     return tmpdir;
 }
 
-#if 0                           /* not used */
-static
-int valid_dir(const char *envname, const char *dir) 
+
+char *setup_cachedir(const char *path) 
 {
-    struct stat st;
-    const char *p;
-    int rc = 1;
+    struct passwd *pw;
+    char *dir, *default_dn = ".poldek-cache";
 
-    
-    p = dir + 1;
-    while (*p) {
-        if (!isalnum(*p) && *p != '/' && *p != '-') {
-            logn(LOGWARN,
-                 _("%s (%s) contains non alphanumeric characters"),
-                 envname, dir);
-            rc = 0;
-            break;
-        }
-        p++;
+    if (path) {
+        if (vf_valid_path(path) && poldek_util_is_rwxdir(path)) 
+            return n_strdup(path);
+        else 
+            logn(LOGWARN, _("%s: invalid cachedir path, "
+                            "fallback to default"), path);
     }
     
-    if (rc) {
-        rc = 0;
-        if (stat(dir, &st) != 0)
-            logn(LOGERR, _("%s (%s): %m, using /tmp"), envname, dir);
-            
-        else if (!S_ISDIR(st.st_mode))
-            logn(LOGERR, _("%s (%s): not a directory"), envname, dir);
-            
-        else if ((st.st_mode & S_IRWXU) != S_IRWXU)
-            logn(LOGERR, _("%s (%s): permission denied"), envname, dir);
-            
-        else 
-            rc = 1;
+    if ((dir = getenv("TMPDIR")) && vf_valid_path(dir))
+        return n_strdup(dir);
+    
+    if ((pw = getpwuid(getuid())) == NULL)
+        return n_strdup(tmpdir());
+
+    if (!poldek_util_is_rwxdir(pw->pw_dir))
+        return n_strdup(tmpdir());
+    
+    if (vf_valid_path(pw->pw_dir) && mk_dir(pw->pw_dir, default_dn)) {
+        char path[PATH_MAX];
+        snprintf(path, sizeof(path), "%s/%s", pw->pw_dir, default_dn);
+        return n_strdup(path);
     }
 
-    return rc;
+    return n_strdup(tmpdir());
 }
-#endif
 
 char *trimslash(char *path) 
 {
@@ -320,89 +277,6 @@
     return stat(path, &st) == 0 && S_ISDIR(st.st_mode);
 }
 
-
-void die(void) 
-{
-    printf("Something wrong, something not quite right, die\n");
-    abort();
-}
-
-void process_cmd_output(struct p_open_st *st, const char *prefix) 
-{
-    int c, endl = 1, cnt = 0;
-    
-    if (prefix == NULL)
-        prefix = st->cmd;
-
-    setvbuf(st->stream, NULL, _IONBF, 0);
-    while ((c = fgetc(st->stream)) != EOF) {
-        
-        if (endl) {
-            msg(1, "_%s: ", prefix);
-            endl = 0;
-        }
-
-        msg(1, "_%c", c);
-        if (c == '\n' && cnt > 0)
-            endl = 1;
-        
-        cnt++;
-    }
-}
-
-int lockfile(const char *lockfile) 
-{
-    struct flock fl;
-    int    fd;
-    
-    
-    if ((fd = open(lockfile, O_RDWR | O_CREAT, 0644)) < 0) {
-        logn(LOGERR, "open %s: %m", lockfile);
-        return -1;
-    }
-
-    fl.l_type = F_WRLCK;
-    fl.l_whence = SEEK_SET;
-    fl.l_start = 0;
-    fl.l_len = 0;
-    
-    if (fcntl(fd, F_SETLK, &fl) == -1) {
-        if (errno == EAGAIN || errno == EACCES)
-            fd = 0;
-        else
-            logn(LOGERR, "fcntl %s: %m", lockfile);
-        
-    } else {
-        char buf[64];
-        
-        ftruncate(fd, 0);
-        snprintf(buf, sizeof(buf), "%d", getpid());
-        write(fd, buf, strlen(buf));
-    }
-    
-    return fd;
-}
-
-pid_t readlockfile(const char *lockfile) 
-{
-    char buf[256];
-    int fd, nread;
-    pid_t pid;
-    
-    fd = open(lockfile, O_RDONLY, 0444);
-    if(fd < 0) 
-        return -1;
-    
-    nread = read(fd, buf, sizeof(buf));
-    close(fd);
-
-    if (sscanf(buf, "%d", &pid) == 1)
-        return pid;
-    
-    return -1;
-}
-
-
 int mk_dir(const char *path, const char *dn) 
 {
     struct stat st;
@@ -460,32 +334,6 @@
     n_str_tokl_free(tl_save);
     return nerr == 0;
 }
-
-
-int mklock(const char *dir) 
-{
-    char path[PATH_MAX];
-    int rc;
-    
-    snprintf(path, sizeof(path), "%s/poldek..lck", dir);
-
-    rc = lockfile(path);
-    
-    if (rc == 0) {
-        char buf[64];
-        pid_t pid = readlockfile(path);
-        
-        if (pid > 0) 
-            snprintf(buf, sizeof(buf), " (%d)", pid);
-        else
-            *buf = '\0';
-            
-        logn(LOGERR, _("There seems another poldek%s uses %s"), buf, dir);
-    }
-
-    return rc > 0; 
-}
-
 
 const char *poldek_util_ngettext_n_packages_fmt(int n) 
 {

================================================================
Index: poldek/poldek/install/misc.c
diff -u poldek/poldek/install/misc.c:1.9 poldek/poldek/install/misc.c:1.10
--- poldek/poldek/install/misc.c:1.9	Sun Jun 24 20:09:10 2007
+++ poldek/poldek/install/misc.c	Sun Jun 24 22:38:13 2007
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2000 - 2005 Pawel A. Gajda <mis at k2.net.pl>
+  Copyright (C) 2000 - 2007 Pawel A. Gajda <mis at pld-linux.org>
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2 as
@@ -57,9 +57,6 @@
     return n;
 }
 
-
-
-
 /* RET: 0 - not installable,  1 - installable,  -1 - something wrong */
 int in_is_pkg_installable(struct install_ctx *ictx, struct pkg *pkg,
                           int is_hand_marked)
@@ -71,9 +68,6 @@
     force = ts->getop(ts, POLDEK_OP_FORCE);
     npkgs = in_is_pkg_installed(ictx, pkg, &cmprc);
     
-    if (npkgs < 0) 
-        die();
-
     n_assert(npkgs >= 0);
 
     installable = 1;

================================================================
Index: poldek/poldek/pm/pset/pset.c
diff -u poldek/poldek/pm/pset/pset.c:1.22 poldek/poldek/pm/pset/pset.c:1.23
--- poldek/poldek/pm/pset/pset.c:1.22	Wed Jun 20 10:25:32 2007
+++ poldek/poldek/pm/pset/pset.c	Sun Jun 24 22:38:13 2007
@@ -387,7 +387,7 @@
             break;
             
         default:
-            die();
+            n_assert(0);
     }
     
     it->i = 0;

================================================================
Index: poldek/poldek/pm/rpm/rpmdb_it.c
diff -u poldek/poldek/pm/rpm/rpmdb_it.c:1.3 poldek/poldek/pm/rpm/rpmdb_it.c:1.4
--- poldek/poldek/pm/rpm/rpmdb_it.c:1.3	Sat Jun 16 17:06:06 2007
+++ poldek/poldek/pm/rpm/rpmdb_it.c	Sun Jun 24 22:38:13 2007
@@ -88,7 +88,8 @@
             break;
             
         default:
-            die();
+            n_assert(0);
+            break;
     }
     
     
@@ -121,7 +122,7 @@
             if (recno == 0)
                 return 0;
             if (recno < 0)
-                die();
+                n_die("%d: invalid recno", recno);
             break;
             
         case PMTAG_NAME:
@@ -145,16 +146,15 @@
             break;
             
         case PMTAG_OBSL:
-            die();
+            n_die("missing feature"); /* don't remember in fact */
             rc = rpmdbFindByConflicts(db, arg, &it->matches);
             break;
             
         default:
-            die();
+            n_assert(0);
     }
-    
     if (rc < 0)
-        die();
+        n_die("rpm database error");
     
     else if (rc != 0) {
         n = 0;
@@ -226,7 +226,7 @@
     }
 
     if (it->i > it->matches.count)
-        die();
+        n_die("rpm database error?");
 
     if (it->dbrec.hdr != NULL)
         headerFree(it->dbrec.hdr);
@@ -236,7 +236,8 @@
     it->i++;
     
     if (it->dbrec.hdr == NULL)
-        die();
+        n_die("rpm database error?");
+    
 #endif /* HAVE_RPM_4_0 */
 
     return &it->dbrec;
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/poldek/poldek/misc.h?r1=1.34&r2=1.35&f=u
    http://cvs.pld-linux.org/poldek/poldek/misc.c?r1=1.55&r2=1.56&f=u
    http://cvs.pld-linux.org/poldek/poldek/install/misc.c?r1=1.9&r2=1.10&f=u
    http://cvs.pld-linux.org/poldek/poldek/pm/pset/pset.c?r1=1.22&r2=1.23&f=u
    http://cvs.pld-linux.org/poldek/poldek/pm/rpm/rpmdb_it.c?r1=1.3&r2=1.4&f=u



More information about the pld-cvs-commit mailing list