Fetch bug and fix

Miguel N <[email protected]> Fri, 12 May 2006 01:41:38 +0200
Newsgroups gmane.comp.web.sitecopy
Message-ID <[email protected]>
Hi all, 

When a remote site contains more than 128 subdirectories, a lot of files
are ignored by the fetch process. And this  files are unnecesary uploaded in 
the next update.

The problem is: dirstack array in site_fetch() function has a fixed size,
maximum 128 directories. So when this stack is full, new fetched directories
cannot be added to the stack and are simply  ignored.
  
It's strange because the rest of functions in sites.c file correctly 
implements a dynamic stack , but it seems someone forgot to add this feature 
in site_fetch() function  ;)

A patch to fix the problem is attached.

Regards,
Miguel Novas

_______________________________________________
sitecopy maillist  -  [email protected]
http://dav.lyra.org/mailman/listinfo/sitecopy
fetch.patch (text/x-diff, 1.7 KB)
--- sitecopy-0.16.3/src/sites.c	2006-03-01 20:38:21.000000000 +0100
+++ sitecopy-0.16.3-1mck/src/sites.c	2006-05-11 01:49:08.000000000 +0200
@@ -768,7 +768,7 @@
 
 /* Initial size of directory stack, and amount it grows
  * each time we fill it. */
-#define DIRSTACKSIZE 128
+#define DIRSTACKSIZE 256
 
 void site_read_local_state(struct site *site)
 {
@@ -1095,9 +1095,9 @@
  */
 int site_fetch(struct site *site)
 {
-    int ret, need_modtimes;
+    int ret, need_modtimes, dirmax;
     void *session;
-    const char *dirstack[DIRSTACKSIZE];
+    const char **dirstack;
     size_t dirtop;
     struct proto_file *files = NULL;
 
@@ -1116,6 +1116,8 @@
      * mode: */
     need_modtimes = site->safemode || site->state_method == state_timesize;
 
+    dirmax   = DIRSTACKSIZE; /* size of stack */
+    dirstack = ne_malloc(sizeof(char *) * DIRSTACKSIZE);
     dirtop = 1;
     dirstack[0] = "";
 
@@ -1138,7 +1140,12 @@
             f->filename = relfn;
 
             if (!file_isexcluded(relfn, site)) {
-                if (f->type == proto_dir && dirtop < DIRSTACKSIZE) {
+                if (f->type == proto_dir) {
+		    if (dirtop == dirmax) {
+		        /* Grow the stack */
+		        dirmax += DIRSTACKSIZE;
+		        dirstack = realloc(dirstack, sizeof(char *) * dirmax);
+		    }
                     dirstack[dirtop++] = relfn;
                 } else if (f->type == proto_file 
                            && site->state_method == state_checksum) {
@@ -1156,6 +1163,8 @@
 
         ne_free(curdir);
     } while (dirtop > 0);
+
+    free(dirstack);
     
     if (ret == SITE_OK) {
         struct proto_file *f, *nextf;
@@ -1177,7 +1186,7 @@
     }
 
     proto_finish(site, session);
-    
+
     return ret;
 }