gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r3846 - GNUnet/src/applications/fs/ecrs GNUnet/src/applicat


From: grothoff
Subject: [GNUnet-SVN] r3846 - GNUnet/src/applications/fs/ecrs GNUnet/src/applications/fs/fsui gnunet-gtk/src/plugins/fs
Date: Fri, 1 Dec 2006 21:22:50 -0800 (PST)

Author: grothoff
Date: 2006-12-01 21:22:45 -0800 (Fri, 01 Dec 2006)
New Revision: 3846

Modified:
   GNUnet/src/applications/fs/ecrs/download.c
   GNUnet/src/applications/fs/fsui/download.c
   gnunet-gtk/src/plugins/fs/download.c
Log:
mantis #1134

Modified: GNUnet/src/applications/fs/ecrs/download.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/download.c  2006-12-02 02:24:39 UTC (rev 
3845)
+++ GNUnet/src/applications/fs/ecrs/download.c  2006-12-02 05:22:45 UTC (rev 
3846)
@@ -113,13 +113,9 @@
   }
   MUTEX_DESTROY(this->lock);
   if (YES == unlinkTreeFiles) {
-    for (i=1;i<= this->treedepth;i++) {
-      fn = MALLOC(strlen(this->filename) + 3 + strlen(GNUNET_DIRECTORY_EXT));
+    for (i=1;i<=this->treedepth;i++) {
+      fn = MALLOC(strlen(this->filename) + 3);
       strcpy(fn, this->filename);
-      if (fn[strlen(fn)-1] == '/') {
-       fn[strlen(fn)-1] = '\0';
-       strcat(fn, GNUNET_DIRECTORY_EXT);
-      }
       strcat(fn, ".A");
       fn[strlen(fn)-1]+=i;
       if (0 != UNLINK(fn))
@@ -172,12 +168,8 @@
     this->handles[i] = -1;
 
   for (i=0;i<=this->treedepth;i++) {
-    fn = MALLOC(strlen(filename) + 3 + strlen(GNUNET_DIRECTORY_EXT));
+    fn = MALLOC(strlen(filename) + 3);
     strcpy(fn, filename);
-    if (fn[strlen(fn)-1] == '/') {
-      fn[strlen(fn)-1] = '\0';
-      strcat(fn, GNUNET_DIRECTORY_EXT);
-    }
     if (i > 0) {
       strcat(fn, ".A");
       fn[strlen(fn)-1] += i;
@@ -1257,49 +1249,93 @@
   NodeClosure * top;
   FileIdentifier fid;
   cron_t minSleep;
+  char * realFN;
+  char * path;
+  char * pos;
+  struct stat buf;
 
 #if DEBUG_DOWNLOAD
-  GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
-      "`%s' running for file `%s'\n",
-      __FUNCTION__,
-      filename);
+  GE_LOG(ectx, 
+        GE_DEBUG | GE_REQUEST | GE_USER,
+        "`%s' running for file `%s'\n",
+        __FUNCTION__,
+        filename);
 #endif
+  GE_ASSERT(ectx, filename != NULL);
+  if ( (filename[strlen(filename)-1] == '/') ||
+       (filename[strlen(filename)-1] == '\\') ) {
+    realFN = MALLOC(strlen(filename) + strlen(GNUNET_DIRECTORY_EXT));
+    strcpy(realFN, filename);
+    realFN[strlen(filename)-1] = '\0';
+    strcat(realFN, GNUNET_DIRECTORY_EXT);
+  } else {
+    realFN = STRDUP(filename);
+  }
+  path = MALLOC(strlen(realFN) * strlen(GNUNET_DIRECTORY_EXT) + 1);
+  strcpy(path, realFN);
+  pos = path;
+  while (*pos != '\0') {
+    if (*pos == '/') {
+      *pos = '\0';
+      if ( (0 == STAT(path, &buf)) &&
+          (! S_ISDIR(buf.st_mode)) ) {
+       *pos = '/';
+       memmove(pos + strlen(GNUNET_DIRECTORY_EXT),
+               pos,
+               strlen(pos));
+       memcpy(pos,
+              GNUNET_DIRECTORY_EXT,
+              strlen(GNUNET_DIRECTORY_EXT));
+       pos += strlen(GNUNET_DIRECTORY_EXT);
+      } else {
+       *pos = '/';
+      }
+    }
+    pos++;
+  }
+  FREE(realFN);
+  realFN = path;
+
   if (SYSERR == disk_directory_create_for_file(ectx,
-                                              filename))
+                                              realFN)) {
+    FREE(realFN);
     return SYSERR;
+  }
   if (0 == ECRS_fileSize(uri)) {
     ret = disk_file_open(ectx,
-                        filename,
+                        realFN,
                         O_CREAT | O_WRONLY | O_TRUNC,
                         S_IRUSR|S_IWUSR);
+    FREE(realFN);
     if (ret == -1)
       return SYSERR;
     CLOSE(ret);
     dpcb(0, 0, get_time(), 0, NULL, 0, dpcbClosure);
     return OK;
   }
-  GE_ASSERT(ectx, filename != NULL);
   fid = uri->data.chk;
   if (! ECRS_isFileUri(uri)) {
     GE_BREAK(ectx, 0);
+    FREE(realFN);
     return SYSERR;
   }
 
   if (OK != createIOContext(ectx,
                            &ioc,
                            ntohll(fid.file_length),
-                           filename)) {
+                           realFN)) {
 #if DEBUG_DOWNLOAD
-    GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
-       "`%s' aborted for file `%s'\n",
-       __FUNCTION__,
-       filename);
+    GE_LOG(ectx,
+          GE_DEBUG | GE_REQUEST | GE_USER,
+          "`%s' aborted for file `%s'\n",
+          __FUNCTION__,
+          realFN);
 #endif
+    FREE(realFN);
     return SYSERR;
   }
   rm = createRequestManager(ectx,
                            cfg);
-
   ctx.startTime = get_time();
   ctx.anonymityLevel = anonymityLevel;
   ctx.TTL_DECREMENT = 5 * cronSECONDS; /* HACK! */
@@ -1346,11 +1382,32 @@
     ret = SYSERR;
   }
   destroyRequestManager(rm);
-  if ( (ret == OK) ||
-       (tt(ttClosure) == SYSERR) )
+  if (ret == OK) {
     freeIOC(&ioc, YES);
-  else
+  } else if (tt(ttClosure) == SYSERR) {
+    freeIOC(&ioc, YES);
+    if (0 != UNLINK(realFN)) {
+      GE_LOG_STRERROR_FILE(ectx,
+                          GE_WARNING | GE_USER | GE_BULK,
+                          "unlink",
+                          realFN);
+    } else { /* delete empty directories */
+      char * rdir;
+      int len;
+      
+      rdir = STRDUP(realFN);
+      len = strlen(rdir);
+      do {
+       while ( (len > 0) &&
+               (rdir[len] != '/') )
+         len--;
+       rdir[len] = '\0';
+      } while ( (len > 0) && (0 == rmdir(rdir)) );
+      FREE(rdir);
+    }
+  } else {
     freeIOC(&ioc, NO); /* aborted */
+  }
 #if DEBUG_DOWNLOAD
   GE_LOG(ectx,
         GE_DEBUG | GE_REQUEST | GE_USER,
@@ -1359,6 +1416,7 @@
         filename,
         ret == OK ? "SUCCESS" : "INCOMPLETE");
 #endif
+  FREE(realFN);
   return ret;
 }
 

Modified: GNUnet/src/applications/fs/fsui/download.c
===================================================================
--- GNUnet/src/applications/fs/fsui/download.c  2006-12-02 02:24:39 UTC (rev 
3845)
+++ GNUnet/src/applications/fs/fsui/download.c  2006-12-02 05:22:45 UTC (rev 
3846)
@@ -86,23 +86,14 @@
     filename = STRDUP(&tmp[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]);
     FREE(tmp);
   }
-  fullName = MALLOC(strlen(parent->filename) +
-                   + strlen(GNUNET_DIRECTORY_EXT) + 2
+  fullName = MALLOC(strlen(parent->filename) + 2
                    + strlen(filename));
-  strcpy(fullName, parent->filename);
-  if (fullName[strlen(fullName)-1] == '/')
-    fullName[strlen(fullName)-1] = '\0';
-  else
-    strcat(fullName, GNUNET_DIRECTORY_EXT);
-  while (NULL != (dotdot = strstr(fullName, "..")))
-    dotdot[0] = dotdot[1] = '_';
-  disk_directory_create(ectx, fullName);
+  strcpy(fullName, 
+        parent->filename);
   strcat(fullName,
-        DIR_SEPARATOR_STR);
-  while (NULL != (dotdot = strstr(filename, "..")))
-    dotdot[0] = dotdot[1] = '_';
-  strcat(fullName,
         filename);
+  while (NULL != (dotdot = strstr(fullName, "..")))
+    dotdot[0] = dotdot[1] = '_';
   FREE(filename);
 #if DEBUG_DTM
   GE_LOG(ectx,
@@ -204,7 +195,8 @@
 testTerminate(void * cls) {
   FSUI_DownloadList * dl = cls;
   
-  if (dl->state == FSUI_ERROR)
+  if ( (dl->state == FSUI_ERROR) ||
+       (dl->state == FSUI_ABORTED) )
     return SYSERR; /* aborted - delete! */
   if (dl->state != FSUI_ACTIVE)
     return NO; /* suspended */
@@ -304,7 +296,7 @@
     struct ECRS_MetaData * md;
 
     totalBytes = ECRS_fileSize(dl->fi.uri);
-    fn = MALLOC(strlen(dl->filename) + 3 + strlen(GNUNET_DIRECTORY_EXT));
+    fn = MALLOC(strlen(dl->filename) + strlen(GNUNET_DIRECTORY_EXT));
     strcpy(fn, dl->filename);
     if (fn[strlen(fn)-1] == '/') {
       fn[strlen(fn)-1] = '\0';
@@ -497,7 +489,7 @@
     list->state = FSUI_ACTIVE;
     list->handle = PTHREAD_CREATE(&downloadThread,
                                  list,
-                                 32 * 1024);
+                                 128 * 1024);
     if (list->handle != NULL) {
       list->ctx->activeDownloadThreads++;
     } else {
@@ -640,13 +632,6 @@
   } else {
     GE_ASSERT(ctx->ectx, dl->handle == NULL);
   }
-  if (dl->state == FSUI_ERROR_JOINED) {
-    if (0 != UNLINK(dl->filename))
-      GE_LOG_STRERROR_FILE(ctx->ectx,
-                          GE_WARNING | GE_USER | GE_BULK,
-                          "unlink",
-                          dl->filename);
-  }
   event.type = FSUI_download_stopped;
   event.data.DownloadStopped.dc.pos = dl;
   event.data.DownloadStopped.dc.cctx = dl->cctx;

Modified: gnunet-gtk/src/plugins/fs/download.c
===================================================================
--- gnunet-gtk/src/plugins/fs/download.c        2006-12-02 02:24:39 UTC (rev 
3845)
+++ gnunet-gtk/src/plugins/fs/download.c        2006-12-02 05:22:45 UTC (rev 
3846)
@@ -56,6 +56,10 @@
     return SYSERR;
   model = GTK_TREE_MODEL(list->searchList->tree);
   path = gtk_tree_row_reference_get_path(list->searchViewRowReference);
+  if (path == NULL) {
+    GE_BREAK(ectx, 0);
+    return SYSERR;
+  }
   gtk_tree_model_get_iter(model,
                          &iter,
                          path);
@@ -221,13 +225,18 @@
       /* have parent, must be download from
         directory inside of search */
       path = 
gtk_tree_row_reference_get_path(dl_parent->searchViewRowReference);
-      valid = gtk_tree_model_get_iter(GTK_TREE_MODEL(sl_parent->tree),
-                                     &piter,
-                                     path);
-      if (valid == TRUE)
-       valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(sl_parent->tree),
-                                            &iter,
-                                            &piter);
+      if (path != NULL) {
+       valid = gtk_tree_model_get_iter(GTK_TREE_MODEL(sl_parent->tree),
+                                       &piter,
+                                       path);
+       if (valid == TRUE)
+         valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(sl_parent->tree),
+                                              &iter,
+                                              &piter);
+      } else {
+       GE_BREAK(ectx, 0);
+       valid = FALSE;
+      }
     } else {
       /* must be top-level entry in search */
       valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(sl_parent->tree),
@@ -294,6 +303,10 @@
   struct ECRS_MetaData * meta;
 
   path = gtk_tree_row_reference_get_path(list->summaryViewRowReference);
+  if (path == NULL) {
+    GE_BREAK(ectx, 0);
+    return;
+  }
   gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary),
                          &iter,
                          path);
@@ -351,14 +364,18 @@
   DownloadList * prev;
 
   path = gtk_tree_row_reference_get_path(list->summaryViewRowReference);
-  gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary),
-                         &iter,
-                         path);
-  gtk_tree_path_free(path);
-  gtk_tree_row_reference_free(list->summaryViewRowReference);
-  list->summaryViewRowReference = NULL;
-  gtk_tree_store_remove(download_summary,
-                       &iter);
+  if (path == NULL) {
+    GE_BREAK(ectx, 0);
+  } else {
+    gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary),
+                           &iter,
+                           path);
+    gtk_tree_path_free(path);
+    gtk_tree_row_reference_free(list->summaryViewRowReference);
+    list->summaryViewRowReference = NULL;
+    gtk_tree_store_remove(download_summary,
+                         &iter);
+  }
   if (list->searchViewRowReference != NULL) {
     gtk_tree_row_reference_free(list->searchViewRowReference);
     list->searchViewRowReference = NULL;
@@ -449,7 +466,6 @@
   SearchList * searchContext;
   DownloadList * parentContext;
 
-  DEBUG_BEGIN();
   idc_uri = NULL;
   idc_meta = NULL;
   idc_name = NULL;
@@ -500,10 +516,18 @@
   cname = idc_name;
   dname = STRDUP(idc_name);
   cname = &dname[strlen(dname)-1];
+  if (cname != dname)
+    cname--; /* ignore tailing '/' */
   while ( (cname != dname) &&
          (*cname != DIR_SEPARATOR) )
     cname--;
-  *cname = '\0';
+  if (*cname == DIR_SEPARATOR) {
+    *cname = '\0';
+    FREE(idc_name);
+    idc_name = STRDUP(cname + 1);
+  } else {
+    *cname = '\0';
+  }
   cname = NULL;
 
   GC_get_configuration_value_filename(cfg,
@@ -525,9 +549,6 @@
   }
   FREE(dname);
   dname = NULL;
-  disk_directory_create(ectx, final_download_dir);
-
-
   /* If file is inside a directory, get the full path */
   dirTreePath = gtk_tree_path_copy(path);
   dirPath = MALLOC(1);
@@ -535,27 +556,26 @@
   dirPathLen = 0;
   while (gtk_tree_path_get_depth(dirTreePath) > 1) {
     char * dirname;
-    char * new;
+    char * newPath;
 
     if (! gtk_tree_path_up(dirTreePath))
       break;
-
-    if (!gtk_tree_model_get_iter(model,
-                                &iiter,
-                                dirTreePath))
+    if (! gtk_tree_model_get_iter(model,
+                                 &iiter,
+                                 dirTreePath))
       break;
     gtk_tree_model_get(model,
                        &iiter,
                        SEARCH_NAME, &dirname,
                        -1);
     dirPathLen = strlen(dirPath) + strlen(dirname) + strlen(DIR_SEPARATOR_STR) 
+ 1;
-    new = MALLOC(dirPathLen + 1);
-    strcpy(new, dirname);
-    if (new[strlen(new)-1] != DIR_SEPARATOR)
-      strcat(new, DIR_SEPARATOR_STR);
-    strcat(new, dirPath);
+    newPath = MALLOC(dirPathLen + 1);
+    strcpy(newPath, dirname);
+    if (newPath[strlen(newPath)-1] != DIR_SEPARATOR)
+      strcat(newPath, DIR_SEPARATOR_STR);
+    strcat(newPath, dirPath);
     FREE(dirPath);
-    dirPath = new;
+    dirPath = newPath;
     free(dirname);
   }
   gtk_tree_path_free(dirTreePath);
@@ -571,23 +591,8 @@
            DIR_SEPARATOR_STR);
   strcat(idc_final_download_destination, 
         dirPath);
-  disk_directory_create(ectx,
-                       idc_final_download_destination);
   strcat(idc_final_download_destination, 
         idc_name);
-  if ( (idc_final_download_destination[strlen(idc_final_download_destination) 
- 1] == '/') ||
-       (idc_final_download_destination[strlen(idc_final_download_destination) 
- 1] == '\\') )
-    idc_final_download_destination[strlen(idc_final_download_destination) - 1] 
= '\0';
-  /* append ".gnd" if needed (== directory and .gnd not present) */
-  if ( (idc_mime != NULL) &&
-       (0 == strcmp(idc_mime, GNUNET_DIRECTORY_MIME)) &&
-       ( (strlen(idc_final_download_destination) < 
strlen(GNUNET_DIRECTORY_EXT)) ||
-        (0 != 
strcmp(&idc_final_download_destination[strlen(idc_final_download_destination)
-                                                     - 
strlen(GNUNET_DIRECTORY_EXT)],
-                     GNUNET_DIRECTORY_EXT)) ) )
-    strcat(idc_final_download_destination, 
-          GNUNET_DIRECTORY_EXT);
-
   /* FIXME: check that there is no pending download for idc_name! */
   if (OK == check_pending(idc_name,
                          NULL)) {





reply via email to

[Prev in Thread] Current Thread [Next in Thread]