towards fi synchronization
authorChristian Grothoff <christian@grothoff.org>
Fri, 30 Apr 2010 08:57:16 +0000 (08:57 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 30 Apr 2010 08:57:16 +0000 (08:57 +0000)
15 files changed:
src/fs/fs.c
src/fs/fs.h
src/fs/fs_file_information.c
src/fs/fs_publish.c
src/fs/fs_test_lib.c
src/fs/gnunet-publish.c
src/fs/test_fs_download.c
src/fs/test_fs_file_information.c
src/fs/test_fs_list_indexed.c
src/fs/test_fs_publish.c
src/fs/test_fs_search.c
src/fs/test_fs_unindex.c
src/include/gnunet_disk_lib.h
src/include/gnunet_fs_service.h
src/util/disk.c

index e14f0570a1389bcdbe0a3222cc1281cdd062d9f7..963fd7920191baf22bd48ef55c8d059c0f14f41b 100644 (file)
@@ -274,6 +274,31 @@ get_read_handle (struct GNUNET_FS_Handle *h,
 }
 
 
+/**
+ * Return a write handle for serialization.
+ *
+ * @param h master context
+ * @param ext component of the path 
+ * @param ent entity identifier (or emtpy string for the directory)
+ * @return NULL on error
+ */
+static struct GNUNET_BIO_WriteHandle *
+get_write_handle (struct GNUNET_FS_Handle *h,
+                const char *ext,
+                const char *ent)
+{
+  char *fn;
+  struct GNUNET_BIO_WriteHandle *ret;
+
+  fn = get_serialization_file_name (h, ext, ent);
+  if (fn == NULL)
+    return NULL;
+  ret = GNUNET_BIO_write_open (fn);
+  GNUNET_free (fn);
+  return ret;
+}
+
+
 /**
  * Using the given serialization filename, try to deserialize
  * the file-information tree associated with it.
@@ -489,6 +514,60 @@ deserialize_file_information (struct GNUNET_FS_Handle *h,
 }
 
 
+/**
+ * Create a temporary file on disk to store the current
+ * state of "fi" in.
+ *
+ * @param fi file information to sync with disk
+ */
+void
+GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi)
+{
+  char *fn;
+  char *dn;
+  const char *end;
+  const char *nxt;
+  struct GNUNET_BIO_WriteHandle *wh;
+
+  if (NULL == fi->serialization)
+    {
+      dn = get_serialization_file_name (fi->h, "publish-fi", "");
+      fn = GNUNET_DISK_mktemp (dn);
+      GNUNET_free (dn);
+      if (fn == NULL)
+       return; /* epic fail */
+      end = NULL;
+      nxt = fn;
+      while ('\0' != nxt)
+       {
+         if (DIR_SEPARATOR == *nxt)
+           end = nxt + 1;
+         nxt++;
+       }
+      if ( (end == NULL) ||
+          (strlen (end) == 0) )
+       {
+         GNUNET_break (0);
+         GNUNET_free (fn);
+         return;
+       }
+      GNUNET_break (6 == strlen (end));
+      fi->serialization = GNUNET_strdup (end);
+      GNUNET_free (fn);
+    }
+  wh = get_write_handle (fi->h, "publish-fi", fi->serialization);
+  if (wh == NULL)
+    {
+      GNUNET_free (fi->serialization);
+      fi->serialization = NULL;
+      return;
+    }
+  /* FIXME: actual serialization here! */
+  GNUNET_BIO_write_close (wh);
+}
+
+
+
 /**
  * Find the entry in the file information struct where the
  * serialization filename matches the given name.
index 02bb3715ed596b41cf84ebce0222398aba2a68d2..50306851e16341a170b9f85d63eef5144ad25048 100644 (file)
@@ -293,6 +293,11 @@ struct GNUNET_FS_FileInformation
    */
   struct GNUNET_FS_FileInformation *dir;
 
+  /**
+   * Handle to the master context.
+   */
+  struct GNUNET_FS_Handle *h;
+
   /**
    * Pointer kept for the client.
    */
@@ -606,6 +611,20 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
                                const struct GNUNET_FS_FileInformation *p,
                                uint64_t offset);
 
+
+/**
+ * Synchronize this file-information struct with its mirror
+ * on disk.  Note that all internal FS-operations that change
+ * file information data should already call "sync" internally,
+ * so this function is likely not useful for clients.
+ * 
+ * @param fi the struct to sync
+ */
+void
+GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
+
+
+
 /**
  * Master context for most FS operations.
  */
index 40fc884324a093a256d73ad6f88ed8aa4144a29f..2d01947417cbf2c62519818e3441945d89a67a2d 100644 (file)
 #include "fs_tree.h"
 
 
-/**
- * Create a temporary file on disk to store the current
- * state of "fi" in.
- *
- * @param fi file information to sync with disk
- */
-void
-GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation * fi)
-{
-  if (NULL == fi->serialization)
-    {
-      fi->serialization = NULL; // FIXME -- need cfg!
-    }
-  // FIXME...
-}
-
-
-/**
- * Load file information from the file to which
- * it was sync'ed.
- *
- * @param fn name of the file to use
- * @return NULL on error
- */
-struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_recover (const char *fn)
-{
-  struct GNUNET_FS_FileInformation *ret;
-  ret = NULL;
-  // FIXME!
-  return ret;
-}
-
-
 /**
  * Obtain the name under which this file information
  * structure is stored on disk.  Only works for top-level
@@ -177,6 +143,7 @@ data_reader_file(void *cls,
 /**
  * Create an entry for a file in a publish-structure.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial value for the client-info value for this entry
  * @param filename name of the file or directory to publish
  * @param keywords under which keywords should this file be available
@@ -192,7 +159,8 @@ data_reader_file(void *cls,
  * @return publish structure entry for the file
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_file (void *client_info,
+GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
+                                            void *client_info,
                                             const char *filename,
                                             const struct GNUNET_FS_Uri *keywords,
                                             const struct GNUNET_CONTAINER_MetaData *meta,
@@ -221,7 +189,8 @@ GNUNET_FS_file_information_create_from_file (void *client_info,
       GNUNET_free (fi);
       return NULL;
     }
-  ret = GNUNET_FS_file_information_create_from_reader (client_info,
+  ret = GNUNET_FS_file_information_create_from_reader (h,
+                                                      client_info,
                                                       sbuf.st_size,
                                                       &data_reader_file,
                                                       fi,
@@ -231,6 +200,7 @@ GNUNET_FS_file_information_create_from_file (void *client_info,
                                                       anonymity,
                                                       priority,
                                                       expirationTime);
+  ret->h = h;
   ret->filename = GNUNET_strdup (filename);
   fn = filename;
   while (NULL != (ss = strstr (fn,
@@ -285,6 +255,7 @@ data_reader_copy(void *cls,
 /**
  * Create an entry for a file in a publish-structure.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial value for the client-info value for this entry
  * @param length length of the file
  * @param data data for the file (should not be used afterwards by
@@ -302,7 +273,8 @@ data_reader_copy(void *cls,
  * @return publish structure entry for the file
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_data (void *client_info,
+GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
+                                            void *client_info,
                                             uint64_t length,
                                             void *data,
                                             const struct GNUNET_FS_Uri *keywords,
@@ -312,7 +284,8 @@ GNUNET_FS_file_information_create_from_data (void *client_info,
                                             uint32_t priority,
                                             struct GNUNET_TIME_Absolute expirationTime)
 {
-  return GNUNET_FS_file_information_create_from_reader (client_info,
+  return GNUNET_FS_file_information_create_from_reader (h,
+                                                       client_info,
                                                        length,
                                                        &data_reader_copy,
                                                        data,
@@ -328,6 +301,7 @@ GNUNET_FS_file_information_create_from_data (void *client_info,
 /**
  * Create an entry for a file in a publish-structure.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial value for the client-info value for this entry
  * @param length length of the file
  * @param reader function that can be used to obtain the data for the file 
@@ -345,7 +319,8 @@ GNUNET_FS_file_information_create_from_data (void *client_info,
  * @return publish structure entry for the file
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_reader (void *client_info,
+GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
+                                              void *client_info,
                                               uint64_t length,
                                               GNUNET_FS_DataReader reader,
                                               void *reader_cls,
@@ -359,6 +334,7 @@ GNUNET_FS_file_information_create_from_reader (void *client_info,
   struct GNUNET_FS_FileInformation *ret;
 
   ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
+  ret->h = h;
   ret->client_info = client_info;  
   ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
   if (ret->meta == NULL)
@@ -371,7 +347,6 @@ GNUNET_FS_file_information_create_from_reader (void *client_info,
   ret->data.file.file_size = length;
   ret->anonymity = anonymity;
   ret->priority = priority;
-  GNUNET_FS_file_information_sync (ret);
   return ret;
 }
 
@@ -386,6 +361,11 @@ struct DirScanCls
    */
   struct EXTRACTOR_PluginList *extractors;
 
+  /**
+   * Master context.
+   */ 
+  struct GNUNET_FS_Handle *h;
+
   /**
    * Function to call on each directory entry.
    */
@@ -462,7 +442,8 @@ dir_scan_cb (void *cls,
     }
   if (S_ISDIR (sbuf.st_mode))
     {
-      fi = GNUNET_FS_file_information_create_from_directory (NULL,
+      fi = GNUNET_FS_file_information_create_from_directory (dsc->h,
+                                                            NULL,
                                                             filename,
                                                             dsc->scanner,
                                                             dsc->scanner_cls,
@@ -486,7 +467,8 @@ dir_scan_cb (void *cls,
       // FIXME: remove path from filename in metadata!
       keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
       ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords);
-      fi = GNUNET_FS_file_information_create_from_file (NULL,
+      fi = GNUNET_FS_file_information_create_from_file (dsc->h,
+                                                       NULL,
                                                        filename,
                                                        ksk_uri,
                                                        meta,
@@ -517,6 +499,7 @@ dir_scan_cb (void *cls,
  * convenience function.
  *
  * @param cls must be of type "struct EXTRACTOR_Extractor*"
+ * @param h handle to the file sharing subsystem
  * @param dirname name of the directory to scan
  * @param do_index should files be indexed or inserted
  * @param anonymity desired anonymity level
@@ -529,6 +512,7 @@ dir_scan_cb (void *cls,
  */
 int
 GNUNET_FS_directory_scanner_default (void *cls,
+                                    struct GNUNET_FS_Handle *h,
                                     const char *dirname,
                                     int do_index,
                                     uint32_t anonymity,
@@ -541,6 +525,7 @@ GNUNET_FS_directory_scanner_default (void *cls,
   struct EXTRACTOR_PluginList *ex = cls;
   struct DirScanCls dsc;
 
+  dsc.h = h;
   dsc.extractors = ex;
   dsc.proc = proc;
   dsc.proc_cls = proc_cls;
@@ -607,6 +592,7 @@ dirproc (void *cls,
  * passed (GNUNET_FS_directory_scanner_default).  This is strictly a
  * convenience function.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial value for the client-info value for this entry
  * @param filename name of the top-level file or directory
  * @param scanner function used to get a list of files in a directory
@@ -621,7 +607,8 @@ dirproc (void *cls,
  * @return publish structure entry for the directory, NULL on error
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_directory (void *client_info,
+GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
+                                                 void *client_info,
                                                  const char *filename,
                                                  GNUNET_FS_DirectoryScanner scanner,
                                                  void *scanner_cls,
@@ -642,6 +629,7 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
   meta = GNUNET_CONTAINER_meta_data_create ();
   GNUNET_FS_meta_data_make_directory (meta);
   scanner (scanner_cls,
+          h,
           filename,
           do_index,
           anonymity,
@@ -652,7 +640,8 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
           emsg);
   ksk = NULL; // FIXME...
   // FIXME: create meta!
-  ret = GNUNET_FS_file_information_create_empty_directory (client_info,
+  ret = GNUNET_FS_file_information_create_empty_directory (h,
+                                                          client_info,
                                                           ksk,
                                                           meta,
                                                           anonymity,
@@ -663,7 +652,6 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
   while (dc.entries != NULL)
     {
       dc.entries->dir = ret;
-      GNUNET_FS_file_information_sync (dc.entries);
       dc.entries = dc.entries->next;
     }
   fn = filename;
@@ -678,7 +666,6 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
                                     fn,
                                     strlen (fn) + 1);
   ret->filename = GNUNET_strdup (filename);
-  GNUNET_FS_file_information_sync (ret);
   return ret;
 }
 
@@ -689,6 +676,7 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
  * use of "GNUNET_FS_file_information_create_from_directory"
  * is not appropriate.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial value for the client-info value for this entry
  * @param meta metadata for the directory
  * @param keywords under which keywords should this directory be available
@@ -701,7 +689,8 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
  * @return publish structure entry for the directory , NULL on error
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_empty_directory (void *client_info,
+GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
+                                                  void *client_info,
                                                   const struct GNUNET_FS_Uri *keywords,
                                                   const struct GNUNET_CONTAINER_MetaData *meta,
                                                   uint32_t anonymity,
@@ -711,6 +700,7 @@ GNUNET_FS_file_information_create_empty_directory (void *client_info,
   struct GNUNET_FS_FileInformation *ret;
 
   ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
+  ret->h = h;
   ret->client_info = client_info;
   ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
   ret->keywords = GNUNET_FS_uri_dup (keywords);
@@ -718,7 +708,6 @@ GNUNET_FS_file_information_create_empty_directory (void *client_info,
   ret->is_directory = GNUNET_YES;
   ret->anonymity = anonymity;
   ret->priority = priority;
-  GNUNET_FS_file_information_sync (ret);
   return ret;
 }
 
@@ -749,8 +738,6 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
   ent->next = dir->data.dir.entries;
   dir->data.dir.entries = ent;
   dir->data.dir.dir_size = 0;
-  GNUNET_FS_file_information_sync (ent);
-  GNUNET_FS_file_information_sync (dir);
   return GNUNET_OK;
 }
 
index 973ecd43880aab7c482e9247eb90a635278a0d56..16bab3ba1ef7a9082401f245cc3ce3870ec7a6ff 100644 (file)
@@ -158,13 +158,11 @@ ds_put_cont (void *cls,
       GNUNET_asprintf (&pcc->p->emsg, 
                       _("Upload failed: %s"),
                       msg);
-      GNUNET_FS_file_information_sync (pcc->p);
       pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
       pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
       pi.value.publish.specifics.error.message = pcc->p->emsg;
       pcc->p->client_info = GNUNET_FS_publish_make_status_ (&pi, pcc->sc, pcc->p, 0);
     }
-  GNUNET_FS_file_information_sync (pcc->p);
   if (NULL != pcc->cont)
     pcc->sc->upload_task 
       = GNUNET_SCHEDULER_add_with_priority (pcc->sc->h->sched,
@@ -302,7 +300,6 @@ publish_kblocks_cont (void *cls,
                                              sc);
       return;
     }
-  GNUNET_FS_file_information_sync (p);
   if (NULL != p->dir)
     signal_publish_completion (p, sc);
   /* move on to next file */
@@ -400,7 +397,6 @@ encode_cont (void *cls,
                       _("Upload failed: %s"),
                       emsg);
       GNUNET_free (emsg);
-      GNUNET_FS_file_information_sync (p);
       pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
       pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
       pi.value.publish.specifics.error.message = p->emsg;
@@ -833,7 +829,6 @@ GNUNET_FS_publish_main_ (void *cls,
                               _("Recursive upload failed: %s"),
                               p->emsg);              
            }
-         GNUNET_FS_file_information_sync (p);
          pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
          pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
          pi.value.publish.specifics.error.message = p->emsg;
index dd783f40690e1553328f3790b5e95a6804491660..b891b4249982c1e60cac11bd223a3e09b542190e 100644 (file)
@@ -536,7 +536,8 @@ GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched,
   daemon->publish_seed = seed;
   daemon->verbose = verbose;
   daemon->publish_sched = sched;
-  fi = GNUNET_FS_file_information_create_from_reader (daemon,
+  fi = GNUNET_FS_file_information_create_from_reader (daemon->fs,
+                                                     daemon,                                                 
                                                      size,
                                                      &file_generator,
                                                      daemon,
index 279eedcced74878e14aac52185a1a4887e57ffe0..5869fcff5ffad8d815300b2898b9c45f38312bda 100644 (file)
@@ -532,7 +532,8 @@ run (void *cls,
     }
   else if (S_ISDIR (sbuf.st_mode))
     {
-      fi = GNUNET_FS_file_information_create_from_directory (NULL,
+      fi = GNUNET_FS_file_information_create_from_directory (ctx,
+                                                            NULL,
                                                             args[0],
                                                             &GNUNET_FS_directory_scanner_default,
                                                             l,
@@ -544,7 +545,8 @@ run (void *cls,
     }
   else
     {
-      fi = GNUNET_FS_file_information_create_from_file (NULL,
+      fi = GNUNET_FS_file_information_create_from_file (ctx,
+                                                       NULL,
                                                        args[0],
                                                        NULL,
                                                        NULL,
index b06f0e965bfd1706b71d8cfbf765708e13ce267c..047c314e4cffbf9e4b02056b70274f0891f3ea5e 100644 (file)
@@ -296,7 +296,8 @@ run (void *cls,
     buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
   meta = GNUNET_CONTAINER_meta_data_create ();
   kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
-  fi = GNUNET_FS_file_information_create_from_data ("publish-context",
+  fi = GNUNET_FS_file_information_create_from_data (fs,
+                                                   "publish-context",
                                                    FILESIZE,
                                                    buf,
                                                    kuri,
index 36a0771a31270b41a297dbdc1a748c6f5b8f0c81..c5b4ec997736e06895dc7e5dad14a264b396e157 100644 (file)
@@ -83,8 +83,12 @@ run (void *cls,
   struct GNUNET_FS_FileInformation *fi1;
   struct GNUNET_FS_FileInformation *fi2;
   struct GNUNET_FS_FileInformation *fidir;
+  struct GNUNET_FS_Handle *fs;
   size_t i;
 
+  fs = GNUNET_FS_start (s, cfg, "test-fs-file-information", NULL, NULL, 
+                       GNUNET_FS_FLAGS_NONE,
+                       GNUNET_FS_OPTIONS_END);
   fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
   buf = GNUNET_malloc (FILESIZE);
   for (i = 0; i < FILESIZE; i++)
@@ -109,7 +113,8 @@ run (void *cls,
 
   meta = GNUNET_CONTAINER_meta_data_create ();
   kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
-  fi1 = GNUNET_FS_file_information_create_from_file ("file_information-context1",
+  fi1 = GNUNET_FS_file_information_create_from_file (fs,
+                                                    "file_information-context1",
                                                     fn1,
                                                     kuri,
                                                     meta,
@@ -117,7 +122,8 @@ run (void *cls,
                                                     1,
                                                     42,
                                                     GNUNET_TIME_relative_to_absolute (LIFETIME)); 
-  fi2 = GNUNET_FS_file_information_create_from_file ("file_information-context2",
+  fi2 = GNUNET_FS_file_information_create_from_file (fs,
+                                                    "file_information-context2",
                                                     fn2,
                                                     kuri,
                                                     meta,
@@ -125,7 +131,8 @@ run (void *cls,
                                                     1,
                                                     42,
                                                     GNUNET_TIME_relative_to_absolute (LIFETIME)); 
-  fidir = GNUNET_FS_file_information_create_empty_directory ("file_information-context-dir",
+  fidir = GNUNET_FS_file_information_create_empty_directory (fs,
+                                                            "file_information-context-dir",
                                                             kuri,
                                                             meta,
                                                             1,
@@ -144,6 +151,7 @@ run (void *cls,
   GNUNET_DISK_directory_remove (fn2);
   GNUNET_free_non_null (fn1);
   GNUNET_free_non_null (fn2);
+  GNUNET_FS_stop (fs);
 }
 
 
index 58a3f3a829f5d717fe9a6b3e0d8001b1596ad791..280ca11eeb8811242c6d23b5138caf7e46a0df63 100644 (file)
@@ -278,7 +278,8 @@ run (void *cls,
 
   meta = GNUNET_CONTAINER_meta_data_create ();
   kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
-  fi1 = GNUNET_FS_file_information_create_from_file ("list_indexed-context1",
+  fi1 = GNUNET_FS_file_information_create_from_file (fs,
+                                                    "list_indexed-context1",
                                                     fn1,
                                                     kuri,
                                                     meta,
@@ -286,7 +287,8 @@ run (void *cls,
                                                     1,
                                                     42,
                                                     GNUNET_TIME_relative_to_absolute (LIFETIME)); 
-  fi2 = GNUNET_FS_file_information_create_from_file ("list_indexed-context2",
+  fi2 = GNUNET_FS_file_information_create_from_file (fs,
+                                                    "list_indexed-context2",
                                                     fn2,
                                                     kuri,
                                                     meta,
@@ -294,7 +296,8 @@ run (void *cls,
                                                     2,
                                                     42,
                                                     GNUNET_TIME_relative_to_absolute (LIFETIME)); 
-  fidir = GNUNET_FS_file_information_create_empty_directory ("list_indexed-context-dir",
+  fidir = GNUNET_FS_file_information_create_empty_directory (fs,
+                                                            "list_indexed-context-dir",
                                                             kuri,
                                                             meta,
                                                             3,
index 2d664817ce9fcae938fce515f185f35d050aac71..20e65aeace78ebb40062f13cbc42d1ead8cc6419 100644 (file)
@@ -267,7 +267,8 @@ run (void *cls,
 
   meta = GNUNET_CONTAINER_meta_data_create ();
   kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
-  fi1 = GNUNET_FS_file_information_create_from_file ("publish-context1",
+  fi1 = GNUNET_FS_file_information_create_from_file (fs,
+                                                    "publish-context1",
                                                     fn1,
                                                     kuri,
                                                     meta,
@@ -275,7 +276,8 @@ run (void *cls,
                                                     1,
                                                     42,
                                                     GNUNET_TIME_relative_to_absolute (LIFETIME)); 
-  fi2 = GNUNET_FS_file_information_create_from_file ("publish-context2",
+  fi2 = GNUNET_FS_file_information_create_from_file (fs,
+                                                    "publish-context2",
                                                     fn2,
                                                     kuri,
                                                     meta,
@@ -283,7 +285,8 @@ run (void *cls,
                                                     2,
                                                     42,
                                                     GNUNET_TIME_relative_to_absolute (LIFETIME)); 
-  fidir = GNUNET_FS_file_information_create_empty_directory ("publish-context-dir",
+  fidir = GNUNET_FS_file_information_create_empty_directory (fs,
+                                                            "publish-context-dir",
                                                             kuri,
                                                             meta,
                                                             3,
index 32f885814bda70779e950a607abd9167cfe6924d..42687a7431341a205575c64c776983ed81f0621c 100644 (file)
@@ -249,7 +249,8 @@ run (void *cls,
     buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
   meta = GNUNET_CONTAINER_meta_data_create ();
   kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
-  fi = GNUNET_FS_file_information_create_from_data ("publish-context",
+  fi = GNUNET_FS_file_information_create_from_data (fs,
+                                                   "publish-context",
                                                    FILESIZE,
                                                    buf,
                                                    kuri,
index 3607144f35388ffeddbc1b7c7ceb90a129156155..861685d3223b16fc19555a9c2ba2ac75fcd6f99a 100644 (file)
@@ -261,7 +261,8 @@ run (void *cls,
   GNUNET_free (buf);
   meta = GNUNET_CONTAINER_meta_data_create ();
   kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
-  fi = GNUNET_FS_file_information_create_from_file ("publish-context",
+  fi = GNUNET_FS_file_information_create_from_file (fs,
+                                                   "publish-context",
                                                    fn,
                                                    kuri,
                                                    meta,
index fcb58ffeffbb0d4b2a29599c320588d1ed16c9af..6292e029e45132b5230dfa49be86c6f4e3dacc85 100644 (file)
@@ -293,7 +293,10 @@ int GNUNET_DISK_file_get_identifiers (const char *filename,
  
 
 /**
- * Create an (empty) temporary file on disk.
+ * Create an (empty) temporary file on disk.  If the given name is not
+ * an absolute path, the current 'TMPDIR' will be prepended.  In any case,
+ * 6 random characters will be appended to the name to create a unique
+ * filename.
  * 
  * @param t component to use for the name;
  *        does NOT contain "XXXXXX" or "/tmp/".
index 508abeedbf9e762f2b9be805f34be738812ab0c0..8f54943c0139b6040e880ef1c25dcb3bf161a14f 100644 (file)
@@ -1561,16 +1561,6 @@ typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
                                                  void **client_info);
 
 
-/**
- * Recover file information structure from disk.
- *
- * @param fn filename for the structure on disk
- * @return NULL on error 
- */
-struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_recover (const char *fn);
-
-
 /**
  * Obtain the name under which this file information
  * structure is stored on disk.  Only works for top-level
@@ -1585,21 +1575,11 @@ const char *
 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
 
 
-/**
- * Synchronize this file-information struct with its mirror
- * on disk.  Note that all internal FS-operations that change
- * file information data should already call "sync" internally,
- * so this function is likely not useful for clients.
- * 
- * @param fi the struct to sync
- */
-void
-GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation *f);
-
 
 /**
  * Create an entry for a file in a publish-structure.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial client-info value for this entry
  * @param filename name of the file or directory to publish
  * @param keywords under which keywords should this file be available
@@ -1615,7 +1595,8 @@ GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation *f);
  * @return publish structure entry for the file
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_file (void *client_info,
+GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
+                                            void *client_info,
                                             const char *filename,
                                             const struct GNUNET_FS_Uri *keywords,
                                             const struct GNUNET_CONTAINER_MetaData *meta,
@@ -1628,6 +1609,7 @@ GNUNET_FS_file_information_create_from_file (void *client_info,
 /**
  * Create an entry for a file in a publish-structure.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial client-info value for this entry
  * @param length length of the file
  * @param data data for the file (should not be used afterwards by
@@ -1645,7 +1627,8 @@ GNUNET_FS_file_information_create_from_file (void *client_info,
  * @return publish structure entry for the file
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_data (void *client_info,
+GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
+                                            void *client_info,
                                             uint64_t length,
                                             void *data,
                                             const struct GNUNET_FS_Uri *keywords,
@@ -1682,6 +1665,7 @@ typedef size_t (*GNUNET_FS_DataReader)(void *cls,
 /**
  * Create an entry for a file in a publish-structure.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial client-info value for this entry
  * @param length length of the file
  * @param reader function that can be used to obtain the data for the file 
@@ -1699,7 +1683,8 @@ typedef size_t (*GNUNET_FS_DataReader)(void *cls,
  * @return publish structure entry for the file
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_reader (void *client_info,
+GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
+                                              void *client_info,
                                               uint64_t length,
                                               GNUNET_FS_DataReader reader,
                                               void *reader_cls,
@@ -1730,6 +1715,7 @@ typedef void (*GNUNET_FS_FileProcessor)(void *cls,
  * Type of a function that will be used to scan a directory.
  * 
  * @param cls closure
+ * @param h handle to the file sharing subsystem
  * @param dirname name of the directory to scan
  * @param do_index should files be indexed or inserted
  * @param anonymity desired anonymity level
@@ -1741,6 +1727,7 @@ typedef void (*GNUNET_FS_FileProcessor)(void *cls,
  * @return GNUNET_OK on success
  */
 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
+                                         struct GNUNET_FS_Handle *h,
                                          const char *dirname,
                                          int do_index,
                                          uint32_t anonymity,
@@ -1764,6 +1751,7 @@ typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
  * convenience function.
  *
  * @param cls must be of type "struct EXTRACTOR_Extractor*"
+ * @param h handle to the file sharing subsystem
  * @param dirname name of the directory to scan
  * @param do_index should files be indexed or inserted
  * @param anonymity desired anonymity level
@@ -1776,6 +1764,7 @@ typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
  */
 int
 GNUNET_FS_directory_scanner_default (void *cls,
+                                    struct GNUNET_FS_Handle *h,
                                     const char *dirname,
                                     int do_index,
                                     uint32_t anonymity,
@@ -1796,6 +1785,7 @@ GNUNET_FS_directory_scanner_default (void *cls,
  * passed (GNUNET_FS_directory_scanner_default).  This is strictly a
  * convenience function.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial client-info value for this entry
  * @param filename name of the top-level file or directory
  * @param scanner function used to get a list of files in a directory
@@ -1810,7 +1800,8 @@ GNUNET_FS_directory_scanner_default (void *cls,
  * @return publish structure entry for the directory, NULL on error
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_directory (void *client_info,
+GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
+                                                 void *client_info,
                                                  const char *filename,
                                                  GNUNET_FS_DirectoryScanner scanner,
                                                  void *scanner_cls,
@@ -1827,6 +1818,7 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
  * use of "GNUNET_FS_file_information_create_from_directory"
  * is not appropriate.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial client-info value for this entry
  * @param keywords under which keywords should this directory be available
  *         directly; can be NULL
@@ -1839,7 +1831,8 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
  * @return publish structure entry for the directory , NULL on error
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_empty_directory (void *client_info,
+GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
+                                                  void *client_info,
                                                   const struct GNUNET_FS_Uri *keywords,
                                                   const struct GNUNET_CONTAINER_MetaData *meta,
                                                   uint32_t anonymity,
index 23380256945bc5d1ddd36ae610719b3421ab89c6..4477dc13589fe56da19e716b9a3495ee8dc0aa84 100644 (file)
@@ -266,7 +266,10 @@ GNUNET_DISK_file_get_identifiers (const char *filename,
 
 
 /**
- * Create an (empty) temporary file on disk.
+ * Create an (empty) temporary file on disk.  If the given name is not
+ * an absolute path, the current 'TMPDIR' will be prepended.  In any case,
+ * 6 random characters will be appended to the name to create a unique
+ * filename.
  * 
  * @param t component to use for the name;
  *        does NOT contain "XXXXXX" or "/tmp/".
@@ -281,10 +284,17 @@ GNUNET_DISK_mktemp (const char *t)
   char *tmpl;
   char *fn;
 
-  tmpdir = getenv ("TMPDIR");
-  tmpdir = tmpdir ? tmpdir : "/tmp";
-
-  GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX");
+  if ( (t[0] != '/') &&
+       (t[0] != '\\') )
+    {
+      tmpdir = getenv ("TMPDIR");
+      tmpdir = tmpdir ? tmpdir : "/tmp";
+      GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX");
+    }
+  else
+    {
+      GNUNET_asprintf (&tmpl, "%s%s", t, "XXXXXX");
+    }
 #ifdef MINGW
   fn = (char *) GNUNET_malloc (MAX_PATH + 1);
   if (ERROR_SUCCESS != plibc_conv_to_win_path (tmpl, fn))