[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r22071 - gnunet/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r22071 - gnunet/src/fs |
Date: |
Mon, 18 Jun 2012 11:43:20 +0200 |
Author: grothoff
Date: 2012-06-18 11:43:20 +0200 (Mon, 18 Jun 2012)
New Revision: 22071
Modified:
gnunet/src/fs/gnunet-auto-share.c
Log:
-implementing write_state
Modified: gnunet/src/fs/gnunet-auto-share.c
===================================================================
--- gnunet/src/fs/gnunet-auto-share.c 2012-06-18 09:32:04 UTC (rev 22070)
+++ gnunet/src/fs/gnunet-auto-share.c 2012-06-18 09:43:20 UTC (rev 22071)
@@ -149,7 +149,7 @@
char *ret;
GNUNET_asprintf (&ret,
- "%s%s.auto",
+ "%s%s.auto-share",
dir_name,
(DIR_SEPARATOR == dir_name[strlen(dir_name)-1]) ? "" :
DIR_SEPARATOR_STR);
return ret;
@@ -213,13 +213,63 @@
/**
+ * Write work item from the work_finished map to the given write handle.
+ *
+ * @param cls the 'struct GNUNET_BIO_WriteHandle*'
+ * @param key key of the item in the map (unused)
+ * @param value the 'struct WorkItem' to write
+ * @return GNUNET_OK to continue to iterate (if write worked)
+ */
+static int
+write_item (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ struct GNUNET_BIO_WriteHandle *wh = cls;
+ struct WorkItem *wi = value;
+
+ if ( (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, wi->filename)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write (wh,
+ &wi->id,
+ sizeof (struct GNUNET_HashCode))) )
+ return GNUNET_SYSERR; /* write error, abort iteration */
+ return GNUNET_OK;
+}
+
+
+/**
* Save the set of 'work_finished' items on disk.
*/
static void
save_state ()
{
- GNUNET_break (0);
- // FIXME: implement!
+ uint32_t n;
+ struct GNUNET_BIO_WriteHandle *wh;
+ char *fn;
+
+ n = GNUNET_CONTAINER_multihashmap_size (work_finished);
+ fn = get_state_file ();
+ wh = GNUNET_BIO_write_open (fn);
+ if (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, n))
+ {
+ (void) GNUNET_BIO_write_close (wh);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to save state to file %s\n"),
+ fn);
+ GNUNET_free (fn);
+ return;
+ }
+ (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished,
+ &write_item,
+ wh);
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to save state to file %s\n"),
+ fn);
+ GNUNET_free (fn);
}
@@ -298,6 +348,9 @@
struct GNUNET_HashCode fx[2];
struct GNUNET_HashCode ft;
+ if (NULL != strstr (filename,
+ DIR_SEPARATOR_STR ".auto-share"))
+ return GNUNET_OK; /* skip internal file */
if (0 != STAT (filename, &sbuf))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r22071 - gnunet/src/fs,
gnunet <=