aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-auto-share.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-auto-share.c')
-rw-r--r--src/fs/gnunet-auto-share.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c
index 13bc908e8..3aed0268b 100644
--- a/src/fs/gnunet-auto-share.c
+++ b/src/fs/gnunet-auto-share.c
@@ -190,18 +190,22 @@ load_state ()
190 190
191 emsg = NULL; 191 emsg = NULL;
192 fn = get_state_file (); 192 fn = get_state_file ();
193 rh = GNUNET_BIO_read_open (fn); 193 rh = GNUNET_BIO_read_open_file (fn);
194 GNUNET_free (fn); 194 GNUNET_free (fn);
195 if (NULL == rh) 195 if (NULL == rh)
196 return; 196 return;
197 fn = NULL; 197 fn = NULL;
198 if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &n)) 198 if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "number of files",
199 (int32_t *) &n))
199 goto error; 200 goto error;
200 while (n-- > 0) 201 while (n-- > 0)
201 { 202 {
202 if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "filename", &fn, 1024)) || 203 struct GNUNET_BIO_ReadSpec rs[] = {
203 (GNUNET_OK != 204 GNUNET_BIO_read_spec_string("filename", &fn, 1024),
204 GNUNET_BIO_read (rh, "id", &id, sizeof(struct GNUNET_HashCode)))) 205 GNUNET_BIO_read_spec_object("id", &id, sizeof(struct GNUNET_HashCode)),
206 GNUNET_BIO_read_spec_end(),
207 };
208 if (GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs))
205 goto error; 209 goto error;
206 wi = GNUNET_new (struct WorkItem); 210 wi = GNUNET_new (struct WorkItem);
207 wi->id = id; 211 wi->id = id;
@@ -251,9 +255,13 @@ write_item (void *cls, const struct GNUNET_HashCode *key, void *value)
251 "Saving serialization ID of file `%s' with value `%s'\n", 255 "Saving serialization ID of file `%s' with value `%s'\n",
252 wi->filename, 256 wi->filename,
253 GNUNET_h2s (&wi->id)); 257 GNUNET_h2s (&wi->id));
254 if ((GNUNET_OK != GNUNET_BIO_write_string (wh, wi->filename)) || 258 struct GNUNET_BIO_WriteSpec ws[] = {
255 (GNUNET_OK != 259 GNUNET_BIO_write_spec_string ("auto-share-write-item-filename",
256 GNUNET_BIO_write (wh, &wi->id, sizeof(struct GNUNET_HashCode)))) 260 wi->filename),
261 GNUNET_BIO_write_spec_object ("id", &wi->id, sizeof(struct GNUNET_HashCode)),
262 GNUNET_BIO_write_spec_end (),
263 };
264 if (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws))
257 return GNUNET_SYSERR; /* write error, abort iteration */ 265 return GNUNET_SYSERR; /* write error, abort iteration */
258 return GNUNET_OK; 266 return GNUNET_OK;
259} 267}
@@ -271,7 +279,7 @@ save_state ()
271 279
272 n = GNUNET_CONTAINER_multihashmap_size (work_finished); 280 n = GNUNET_CONTAINER_multihashmap_size (work_finished);
273 fn = get_state_file (); 281 fn = get_state_file ();
274 wh = GNUNET_BIO_write_open (fn); 282 wh = GNUNET_BIO_write_open_file (fn);
275 if (NULL == wh) 283 if (NULL == wh)
276 { 284 {
277 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 285 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -280,9 +288,9 @@ save_state ()
280 GNUNET_free (fn); 288 GNUNET_free (fn);
281 return; 289 return;
282 } 290 }
283 if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, n)) 291 if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "size of state", n))
284 { 292 {
285 (void) GNUNET_BIO_write_close (wh); 293 (void) GNUNET_BIO_write_close (wh, NULL);
286 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 294 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
287 _ ("Failed to save state to file %s\n"), 295 _ ("Failed to save state to file %s\n"),
288 fn); 296 fn);
@@ -290,7 +298,7 @@ save_state ()
290 return; 298 return;
291 } 299 }
292 (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, &write_item, wh); 300 (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, &write_item, wh);
293 if (GNUNET_OK != GNUNET_BIO_write_close (wh)) 301 if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
294 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 302 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
295 _ ("Failed to save state to file %s\n"), 303 _ ("Failed to save state to file %s\n"),
296 fn); 304 fn);