poldek: poldek/vfile/fetch.c, poldek/vfile/vfile.c, poldek/vfile/v...

mis mis at pld-linux.org
Mon Jun 25 01:35:52 CEST 2007


Author: mis                          Date: Sun Jun 24 23:35:52 2007 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- wrapped cachedir (default changed to NULL)

---- Files affected:
poldek/poldek/vfile:
   fetch.c (1.41 -> 1.42) , vfile.c (1.69 -> 1.70) , vfile.h (1.48 -> 1.49) , vfile_intern.h (1.6 -> 1.7) 

---- Diffs:

================================================================
Index: poldek/poldek/vfile/fetch.c
diff -u poldek/poldek/vfile/fetch.c:1.41 poldek/poldek/vfile/fetch.c:1.42
--- poldek/poldek/vfile/fetch.c:1.41	Sat Jun 23 21:18:58 2007
+++ poldek/poldek/vfile/fetch.c	Mon Jun 25 01:35:47 2007
@@ -414,7 +414,6 @@
             default:
                 vf_logerr("vf_fetch*: internal error\n");
                 n_assert(0);
-                n_die(0);
                 return 0;
         }
     }

================================================================
Index: poldek/poldek/vfile/vfile.c
diff -u poldek/poldek/vfile/vfile.c:1.69 poldek/poldek/vfile/vfile.c:1.70
--- poldek/poldek/vfile/vfile.c:1.69	Sun Aug 20 20:12:13 2006
+++ poldek/poldek/vfile/vfile.c	Mon Jun 25 01:35:47 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
@@ -48,13 +48,22 @@
 static const char   default_anon_passwd[] = "poldek at znienacka.net";
 
 struct vfile_configuration vfile_conf = {
-    "/tmp", VFILE_CONF_STUBBORN_RETR, 1000 /* nretries */,
+    NULL, VFILE_CONF_STUBBORN_RETR, 1000 /* nretries */,
     NULL, NULL, NULL,
     &verbose, 
     (char*)default_anon_passwd,
     NULL, NULL
 };
 
+static inline const char *vfile_cachedir(void)
+{
+    if (vfile_conf._cachedir == NULL)
+        n_die("vfile: cachedir must be configured");
+    n_assert(vfile_conf._cachedir);
+    n_assert(*vfile_conf._cachedir);
+    return vfile_conf._cachedir;
+}
+
 static void set_anonpasswd(void)
 {
     if (vfile_conf.anon_passwd != default_anon_passwd) {
@@ -106,10 +115,10 @@
         case VFILE_CONF_CACHEDIR:
             vs = va_arg(ap, char*);
             if (vs) {
-                vfile_conf.cachedir = n_strdup(vs);
-                v = strlen(vfile_conf.cachedir);
-                if (vfile_conf.cachedir[v - 1] == '/')
-                    vfile_conf.cachedir[v - 1] = '\0';
+                vfile_conf._cachedir = n_strdup(vs);
+                v = strlen(vfile_conf._cachedir);
+                if (vfile_conf._cachedir[v - 1] == '/')
+                    vfile_conf._cachedir[v - 1] = '\0';
             }
             break;
             
@@ -309,6 +318,7 @@
 static const char *vfdecompr(const char *path, char *dest, int size) 
 {
     char *destdir, destdir_buf[PATH_MAX], uncmpr_path[PATH_MAX];
+    const char *cachedir = NULL;
     struct vflock *vflock;
     int  len, rc;
     
@@ -318,11 +328,12 @@
     if (!vf_decompressable(path, uncmpr_path, sizeof(uncmpr_path)))
         return path;
 
-    len = strlen(vfile_conf.cachedir);
-
-
+    cachedir = vfile_cachedir();
+    
+    len = strlen(cachedir);
+    
        /* file under cachedir */
-    if (strncmp(uncmpr_path, vfile_conf.cachedir, len) == 0) { 
+    if (strncmp(uncmpr_path, cachedir, len) == 0) { 
         char *bn;
         n_snprintf(destdir_buf, sizeof(destdir_buf), "%s", uncmpr_path);
         n_basedirnam(destdir_buf, &destdir, &bn);
@@ -399,7 +410,7 @@
         return 0;
     }
     
-    len = n_snprintf(buf, sizeof(buf), "%s/", vfile_conf.cachedir);
+    len = n_snprintf(buf, sizeof(buf), "%s/", vfile_cachedir());
     vf_url_as_path(&buf[len], sizeof(buf) - len, path);
     
     if ((vfmode & VFM_CACHE) && file_ok(buf, vfmode)) {
@@ -586,7 +597,7 @@
 {
     int n;
 
-    n = n_snprintf(path, size, "%s/%s", vfile_conf.cachedir, dirpath);
+    n = n_snprintf(path, size, "%s/%s", vfile_cachedir(), dirpath);
     vf_mkdir(path);
     return n;
 }
@@ -595,7 +606,7 @@
 {
     int n;
     
-    n = n_snprintf(path, size, "%s/", vfile_conf.cachedir);
+    n = n_snprintf(path, size, "%s/", vfile_cachedir());
     return n + vf_url_as_path(&path[n], size - n, url);
 }
 
@@ -603,21 +614,22 @@
 {
     int n;
     
-    n = n_snprintf(path, size, "%s/", vfile_conf.cachedir);
+    n = n_snprintf(path, size, "%s/", vfile_cachedir());
     return n + vf_url_as_dirpath(&path[n], size - n, url);
 }
 
 
 int vf_cachepath(char *path, size_t size, const char *ofdirpath)
 {
+    const char *cachedir = vfile_cachedir();
     int n, len;
     
-    len = strlen(vfile_conf.cachedir);
+    len = strlen(cachedir);
 
     n_assert(strlen(ofdirpath) > 0);
     n_assert(ofdirpath[strlen(ofdirpath) - 1] != '/'); /* not a dir */
                            
-    if (strncmp(ofdirpath, vfile_conf.cachedir, len) == 0) { 
+    if (strncmp(ofdirpath, cachedir, len) == 0) { 
         n = n_snprintf(path, size, "%s", ofdirpath);
         
     } else {
@@ -629,7 +641,7 @@
 
 int vf_localunlink(const char *path) 
 {
-    if (strncmp(path, vfile_conf.cachedir, strlen(vfile_conf.cachedir)) == 0 &&
+    if (strncmp(path, vfile_cachedir(), strlen(vfile_cachedir())) == 0 &&
         vf_valid_path(path))
         return unlink(path) == 0;
     

================================================================
Index: poldek/poldek/vfile/vfile.h
diff -u poldek/poldek/vfile/vfile.h:1.48 poldek/poldek/vfile/vfile.h:1.49
--- poldek/poldek/vfile/vfile.h:1.48	Sun Aug 20 20:12:13 2006
+++ poldek/poldek/vfile/vfile.h	Mon Jun 25 01:35:47 2007
@@ -1,6 +1,6 @@
 /*
   Not so transparent IO layer. 
-  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 published

================================================================
Index: poldek/poldek/vfile/vfile_intern.h
diff -u poldek/poldek/vfile/vfile_intern.h:1.6 poldek/poldek/vfile/vfile_intern.h:1.7
--- poldek/poldek/vfile/vfile_intern.h:1.6	Fri Oct  7 13:24:55 2005
+++ poldek/poldek/vfile/vfile_intern.h	Mon Jun 25 01:35:47 2007
@@ -37,7 +37,7 @@
 
 extern int *vfile_verbose;
 struct vfile_configuration {
-    char       *cachedir;
+    char       *_cachedir;
     unsigned   flags;
     int        nretries;       /* how many retries in stubborn mode */
     tn_hash    *default_clients_ht;
@@ -50,6 +50,7 @@
 };
 
 extern struct vfile_configuration vfile_conf;
+
 void vfile_set_errno(const char *ctxname, int vf_errno);
 int vfile_sigint_reached(int reset);
 
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/poldek/poldek/vfile/fetch.c?r1=1.41&r2=1.42&f=u
    http://cvs.pld-linux.org/poldek/poldek/vfile/vfile.c?r1=1.69&r2=1.70&f=u
    http://cvs.pld-linux.org/poldek/poldek/vfile/vfile.h?r1=1.48&r2=1.49&f=u
    http://cvs.pld-linux.org/poldek/poldek/vfile/vfile_intern.h?r1=1.6&r2=1.7&f=u



More information about the pld-cvs-commit mailing list