aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-18 09:43:20 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-18 09:43:20 +0000
commitbb6613b3a12e4108ca2c844bfc5666a5a5ae8e8b (patch)
treee657b54a8a5d68f80068cb57e0f8e5ca6b28d69e /src
parentd7f07521d128b52e1b2c2326705cf64ad3888143 (diff)
downloadgnunet-bb6613b3a12e4108ca2c844bfc5666a5a5ae8e8b.tar.gz
gnunet-bb6613b3a12e4108ca2c844bfc5666a5a5ae8e8b.zip
-implementing write_state
Diffstat (limited to 'src')
-rw-r--r--src/fs/gnunet-auto-share.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c
index ec324e43e..db5b4537b 100644
--- a/src/fs/gnunet-auto-share.c
+++ b/src/fs/gnunet-auto-share.c
@@ -149,7 +149,7 @@ get_state_file ()
149 char *ret; 149 char *ret;
150 150
151 GNUNET_asprintf (&ret, 151 GNUNET_asprintf (&ret,
152 "%s%s.auto", 152 "%s%s.auto-share",
153 dir_name, 153 dir_name,
154 (DIR_SEPARATOR == dir_name[strlen(dir_name)-1]) ? "" : DIR_SEPARATOR_STR); 154 (DIR_SEPARATOR == dir_name[strlen(dir_name)-1]) ? "" : DIR_SEPARATOR_STR);
155 return ret; 155 return ret;
@@ -213,13 +213,63 @@ load_state ()
213 213
214 214
215/** 215/**
216 * Write work item from the work_finished map to the given write handle.
217 *
218 * @param cls the 'struct GNUNET_BIO_WriteHandle*'
219 * @param key key of the item in the map (unused)
220 * @param value the 'struct WorkItem' to write
221 * @return GNUNET_OK to continue to iterate (if write worked)
222 */
223static int
224write_item (void *cls,
225 const struct GNUNET_HashCode *key,
226 void *value)
227{
228 struct GNUNET_BIO_WriteHandle *wh = cls;
229 struct WorkItem *wi = value;
230
231 if ( (GNUNET_OK !=
232 GNUNET_BIO_write_string (wh, wi->filename)) ||
233 (GNUNET_OK !=
234 GNUNET_BIO_write (wh,
235 &wi->id,
236 sizeof (struct GNUNET_HashCode))) )
237 return GNUNET_SYSERR; /* write error, abort iteration */
238 return GNUNET_OK;
239}
240
241
242/**
216 * Save the set of 'work_finished' items on disk. 243 * Save the set of 'work_finished' items on disk.
217 */ 244 */
218static void 245static void
219save_state () 246save_state ()
220{ 247{
221 GNUNET_break (0); 248 uint32_t n;
222 // FIXME: implement! 249 struct GNUNET_BIO_WriteHandle *wh;
250 char *fn;
251
252 n = GNUNET_CONTAINER_multihashmap_size (work_finished);
253 fn = get_state_file ();
254 wh = GNUNET_BIO_write_open (fn);
255 if (GNUNET_OK !=
256 GNUNET_BIO_write_int32 (wh, n))
257 {
258 (void) GNUNET_BIO_write_close (wh);
259 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
260 _("Failed to save state to file %s\n"),
261 fn);
262 GNUNET_free (fn);
263 return;
264 }
265 (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished,
266 &write_item,
267 wh);
268 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
269 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
270 _("Failed to save state to file %s\n"),
271 fn);
272 GNUNET_free (fn);
223} 273}
224 274
225 275
@@ -298,6 +348,9 @@ determine_id (void *cls,
298 struct GNUNET_HashCode fx[2]; 348 struct GNUNET_HashCode fx[2];
299 struct GNUNET_HashCode ft; 349 struct GNUNET_HashCode ft;
300 350
351 if (NULL != strstr (filename,
352 DIR_SEPARATOR_STR ".auto-share"))
353 return GNUNET_OK; /* skip internal file */
301 if (0 != STAT (filename, &sbuf)) 354 if (0 != STAT (filename, &sbuf))
302 { 355 {
303 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); 356 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);