gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r2357 - GNUnet/src/applications/fs/module


From: grothoff
Subject: [GNUnet-SVN] r2357 - GNUnet/src/applications/fs/module
Date: Mon, 19 Dec 2005 22:03:34 -0800 (PST)

Author: grothoff
Date: 2005-12-19 22:03:32 -0800 (Mon, 19 Dec 2005)
New Revision: 2357

Modified:
   GNUnet/src/applications/fs/module/fs.c
   GNUnet/src/applications/fs/module/ondemand.c
   GNUnet/src/applications/fs/module/ondemand.h
Log:
avoid getConfigurationStringing all the time

Modified: GNUnet/src/applications/fs/module/fs.c
===================================================================
--- GNUnet/src/applications/fs/module/fs.c      2005-12-20 03:59:30 UTC (rev 
2356)
+++ GNUnet/src/applications/fs/module/fs.c      2005-12-20 06:03:32 UTC (rev 
2357)
@@ -1096,6 +1096,7 @@
   dht = NULL;
 
   coreAPI = capi;
+  ONDEMAND_init();
   MUTEX_CREATE(&lock);
   dsGap.closure = NULL;
   dsGap.get = &gapGet;
@@ -1201,6 +1202,7 @@
   }
   coreAPI = NULL;
   MUTEX_DESTROY(&lock);
+  ONDEMAND_done();
 }
 
 /**

Modified: GNUnet/src/applications/fs/module/ondemand.c
===================================================================
--- GNUnet/src/applications/fs/module/ondemand.c        2005-12-20 03:59:30 UTC 
(rev 2356)
+++ GNUnet/src/applications/fs/module/ondemand.c        2005-12-20 06:03:32 UTC 
(rev 2357)
@@ -63,21 +63,16 @@
 
 } OnDemandBlock;
 
+static char * index_directory;
+
 static char * getOnDemandFile(const HashCode512 * fileId) {
   EncName enc;
   char * fn;
-  char * dir;
 
-  dir = getFileName("FS",
-                   "INDEX-DIRECTORY",
-                   _("You must specify a directory for FS files in the"
-                     " configuration in section `%s' under `%s'."));
-  mkdirp(dir); /* just in case */
   hash2enc(fileId,
           &enc);
-  fn = MALLOC(strlen(dir) + sizeof(EncName) + 1);
-  strcpy(fn, dir);
-  FREE(dir);
+  fn = MALLOC(strlen(index_directory) + sizeof(EncName) + 1);
+  strcpy(fn, index_directory);
   strcat(fn, "/");
   strcat(fn, (char*) &enc);
   return fn;
@@ -113,45 +108,20 @@
 int ONDEMAND_initIndex(const HashCode512 * fileId,
                       const char *fn) {
   EncName enc;
-  char * serverDir;
   char * serverFN;
-  char *tmp;
   char unavail_key[256];
   HashCode512 linkId;
 
-  serverDir
-    = getConfigurationString("FS",
-                            "INDEX-DIRECTORY");
-  if (!serverDir) {
-    serverDir = getConfigurationString("GNUNETD",
-                                      "GNUNETD_HOME");
-    if (!serverDir)
-      return SYSERR;
-
-    serverDir = REALLOC(serverDir,
-                       strlen(serverDir) +
-                       strlen("/data/shared/") + 1);
-    strcat(serverDir, "/data/shared/");
-  }
-  tmp = expandFileName(serverDir);
-  FREE(serverDir);
-  serverDir = tmp;
   if ( (SYSERR == getFileHash(fn,
                              &linkId)) ||
        (! equalsHashCode512(&linkId,
                            fileId)) ) {
-    FREE(serverDir);
     return NO;
   }
 
-  serverFN = MALLOC(strlen(serverDir) + 2 + sizeof(EncName));
+  serverFN = MALLOC(strlen(index_directory) + 2 + sizeof(EncName));
   strcpy(serverFN,
-        serverDir);
-
-  /* Just in case... */
-  mkdirp(serverDir);
-
-  FREE(serverDir);
+        index_directory);
   strcat(serverFN,
         DIR_SEPARATOR_STR);
   hash2enc(fileId,
@@ -677,5 +647,29 @@
   return OK;
 }
 
+int ONDEMAND_init() {
+  char * tmp;
 
+
+  tmp
+    = getConfigurationString("FS",
+                            "INDEX-DIRECTORY");
+  if (NULL == tmp) {
+    tmp = getConfigurationString("GNUNETD",
+                                "GNUNETD_HOME");
+    GNUNET_ASSERT(NULL != tmp);
+    tmp = REALLOC(tmp,
+                             strlen(tmp) +
+                             strlen("/data/shared/") + 1);
+    strcat(tmp, "/data/shared/");
+  }
+  index_directory = expandFileName(tmp);
+  FREE(tmp);
+  mkdirp(index_directory); /* just in case */  
+}
+
+int ONDEMAND_done() {
+  FREE(index_directory);
+}
+
 /* end of ondemand.c */

Modified: GNUnet/src/applications/fs/module/ondemand.h
===================================================================
--- GNUnet/src/applications/fs/module/ondemand.h        2005-12-20 03:59:30 UTC 
(rev 2356)
+++ GNUnet/src/applications/fs/module/ondemand.h        2005-12-20 06:03:32 UTC 
(rev 2357)
@@ -88,5 +88,9 @@
 int ONDEMAND_testindexed(Datastore_ServiceAPI * datastore,
                         const HashCode512 * fileId);
 
+int ONDEMAND_init();
+
+int ONDEMAND_done();
+
 /* end of ondemand.h */
 #endif





reply via email to

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