gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r25783 - gnunet-update/src/fs


From: gnunet
Subject: [GNUnet-SVN] r25783 - gnunet-update/src/fs
Date: Mon, 14 Jan 2013 17:08:40 +0100

Author: harsha
Date: 2013-01-14 17:08:40 +0100 (Mon, 14 Jan 2013)
New Revision: 25783

Modified:
   gnunet-update/src/fs/gnupdate-daemon-search.c
Log:
- read timestamp from install manifest

Modified: gnunet-update/src/fs/gnupdate-daemon-search.c
===================================================================
--- gnunet-update/src/fs/gnupdate-daemon-search.c       2013-01-14 15:53:30 UTC 
(rev 25782)
+++ gnunet-update/src/fs/gnupdate-daemon-search.c       2013-01-14 16:08:40 UTC 
(rev 25783)
@@ -28,14 +28,71 @@
 #include <gnunet/gnunet_util_lib.h>
 #include <gnunet/gnunet_fs_service.h>
 
+/**
+ * Generic logging
+ */
+#define LOG(kind, ...)                          \
+  GNUNET_log (kind, __VA_ARGS__)
 
 /**
+ * Generic debug logging
+ */
+#define DEBUG(...)                              \
+  LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
+/**
  * Return status of the program
  */
-int ret;
+static int ret;
 
+/**
+ * path of the GNUnet installation directory
+ */
+static char *idir;
 
 /**
+ * The suffix for the gnunet-update specific DATA directory in the installation
+ * directory
+ */
+static const char *data_dir_suffix = "share/gnunet-update/install-manifest";
+
+/**
+ * The timestamp from the install manifest
+ */
+static struct tm tstamp;
+
+/**
+ * Returns the broken time after reading it from the install manifest file
+ *
+ * @param 
+ * @return 
+ */
+static int
+get_manifest_timestamp (const char *path, struct tm *tp)
+{
+  char data[256];
+  char tstr[256];
+  ssize_t rsize;
+
+  rsize = GNUNET_DISK_fn_read (path, data, sizeof (data));
+  if (GNUNET_SYSERR == rsize)
+    return GNUNET_SYSERR;
+  data[255] = '\0';
+  if (0 >= sscanf (data, "%s\n", tstr))
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  if (NULL == strptime (tstr, "%s", tp))
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_OK;
+}
+
+
+/**
  * Main function that will be run by the scheduler.
  *
  * @param cls closure
@@ -49,15 +106,44 @@
 {
   //char **keywords;
   char *path;
+  char tstr[256];
   
-  path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
-  printf ("DATA dir: %s\n", path);
+  path = NULL;
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c,
+                                                            "GNUPDATE",
+                                                            "INSTALL_DIR",
+                                                            &idir))
+  {
+    fprintf (stderr, "Cannot determine GNUNET installation dir. "
+             "Set \"INSTALL_DIR\" in configuration\n");
+    goto err_return;
+  }
+  if (0 > GNUNET_asprintf (&path, "%s/%s", idir, data_dir_suffix))
+  {
+    GNUNET_break (0);
+    goto err_return;
+  }
+  GNUNET_free (idir);
+  idir = NULL;
+  if (GNUNET_OK != get_manifest_timestamp (path, &tstamp))
+    goto err_return;
   GNUNET_free (path);
-  path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_SELF_PREFIX);
-  printf ("SELF dir: %s\n", path);
-  GNUNET_free (path);
-  ret = 0;
+  path = NULL;
+  if (0 == strftime (tstr, sizeof (tstr), "%a, %d %b %Y %H:%M:%S %z", &tstamp))
+  {
+    GNUNET_break (0);
+    goto err_return;
+  }
+  tstr[255] = '\0';
+  DEBUG ("%s\n", tstr);
+  ret = GNUNET_OK;
   return;
+
+ err_return:
+  GNUNET_free_non_null (idir);
+  GNUNET_free_non_null (path);
+  ret = GNUNET_SYSERR;
+  return;
 }
 
 




reply via email to

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