aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_file_information.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-04-30 08:57:16 +0000
committerChristian Grothoff <christian@grothoff.org>2010-04-30 08:57:16 +0000
commit8080b1223983045fc3374e67fc01be643a84a09f (patch)
tree0b1f889880863766c5cbcd9db6646cdfd01a728d /src/fs/fs_file_information.c
parent377c3e56c2b903b6cf57b687f20b2379299c5c89 (diff)
downloadgnunet-8080b1223983045fc3374e67fc01be643a84a09f.tar.gz
gnunet-8080b1223983045fc3374e67fc01be643a84a09f.zip
towards fi synchronization
Diffstat (limited to 'src/fs/fs_file_information.c')
-rw-r--r--src/fs/fs_file_information.c87
1 files changed, 37 insertions, 50 deletions
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index 40fc88432..2d0194741 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -36,40 +36,6 @@
36 36
37 37
38/** 38/**
39 * Create a temporary file on disk to store the current
40 * state of "fi" in.
41 *
42 * @param fi file information to sync with disk
43 */
44void
45GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation * fi)
46{
47 if (NULL == fi->serialization)
48 {
49 fi->serialization = NULL; // FIXME -- need cfg!
50 }
51 // FIXME...
52}
53
54
55/**
56 * Load file information from the file to which
57 * it was sync'ed.
58 *
59 * @param fn name of the file to use
60 * @return NULL on error
61 */
62struct GNUNET_FS_FileInformation *
63GNUNET_FS_file_information_recover (const char *fn)
64{
65 struct GNUNET_FS_FileInformation *ret;
66 ret = NULL;
67 // FIXME!
68 return ret;
69}
70
71
72/**
73 * Obtain the name under which this file information 39 * Obtain the name under which this file information
74 * structure is stored on disk. Only works for top-level 40 * structure is stored on disk. Only works for top-level
75 * file information structures. 41 * file information structures.
@@ -177,6 +143,7 @@ data_reader_file(void *cls,
177/** 143/**
178 * Create an entry for a file in a publish-structure. 144 * Create an entry for a file in a publish-structure.
179 * 145 *
146 * @param h handle to the file sharing subsystem
180 * @param client_info initial value for the client-info value for this entry 147 * @param client_info initial value for the client-info value for this entry
181 * @param filename name of the file or directory to publish 148 * @param filename name of the file or directory to publish
182 * @param keywords under which keywords should this file be available 149 * @param keywords under which keywords should this file be available
@@ -192,7 +159,8 @@ data_reader_file(void *cls,
192 * @return publish structure entry for the file 159 * @return publish structure entry for the file
193 */ 160 */
194struct GNUNET_FS_FileInformation * 161struct GNUNET_FS_FileInformation *
195GNUNET_FS_file_information_create_from_file (void *client_info, 162GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
163 void *client_info,
196 const char *filename, 164 const char *filename,
197 const struct GNUNET_FS_Uri *keywords, 165 const struct GNUNET_FS_Uri *keywords,
198 const struct GNUNET_CONTAINER_MetaData *meta, 166 const struct GNUNET_CONTAINER_MetaData *meta,
@@ -221,7 +189,8 @@ GNUNET_FS_file_information_create_from_file (void *client_info,
221 GNUNET_free (fi); 189 GNUNET_free (fi);
222 return NULL; 190 return NULL;
223 } 191 }
224 ret = GNUNET_FS_file_information_create_from_reader (client_info, 192 ret = GNUNET_FS_file_information_create_from_reader (h,
193 client_info,
225 sbuf.st_size, 194 sbuf.st_size,
226 &data_reader_file, 195 &data_reader_file,
227 fi, 196 fi,
@@ -231,6 +200,7 @@ GNUNET_FS_file_information_create_from_file (void *client_info,
231 anonymity, 200 anonymity,
232 priority, 201 priority,
233 expirationTime); 202 expirationTime);
203 ret->h = h;
234 ret->filename = GNUNET_strdup (filename); 204 ret->filename = GNUNET_strdup (filename);
235 fn = filename; 205 fn = filename;
236 while (NULL != (ss = strstr (fn, 206 while (NULL != (ss = strstr (fn,
@@ -285,6 +255,7 @@ data_reader_copy(void *cls,
285/** 255/**
286 * Create an entry for a file in a publish-structure. 256 * Create an entry for a file in a publish-structure.
287 * 257 *
258 * @param h handle to the file sharing subsystem
288 * @param client_info initial value for the client-info value for this entry 259 * @param client_info initial value for the client-info value for this entry
289 * @param length length of the file 260 * @param length length of the file
290 * @param data data for the file (should not be used afterwards by 261 * @param data data for the file (should not be used afterwards by
@@ -302,7 +273,8 @@ data_reader_copy(void *cls,
302 * @return publish structure entry for the file 273 * @return publish structure entry for the file
303 */ 274 */
304struct GNUNET_FS_FileInformation * 275struct GNUNET_FS_FileInformation *
305GNUNET_FS_file_information_create_from_data (void *client_info, 276GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
277 void *client_info,
306 uint64_t length, 278 uint64_t length,
307 void *data, 279 void *data,
308 const struct GNUNET_FS_Uri *keywords, 280 const struct GNUNET_FS_Uri *keywords,
@@ -312,7 +284,8 @@ GNUNET_FS_file_information_create_from_data (void *client_info,
312 uint32_t priority, 284 uint32_t priority,
313 struct GNUNET_TIME_Absolute expirationTime) 285 struct GNUNET_TIME_Absolute expirationTime)
314{ 286{
315 return GNUNET_FS_file_information_create_from_reader (client_info, 287 return GNUNET_FS_file_information_create_from_reader (h,
288 client_info,
316 length, 289 length,
317 &data_reader_copy, 290 &data_reader_copy,
318 data, 291 data,
@@ -328,6 +301,7 @@ GNUNET_FS_file_information_create_from_data (void *client_info,
328/** 301/**
329 * Create an entry for a file in a publish-structure. 302 * Create an entry for a file in a publish-structure.
330 * 303 *
304 * @param h handle to the file sharing subsystem
331 * @param client_info initial value for the client-info value for this entry 305 * @param client_info initial value for the client-info value for this entry
332 * @param length length of the file 306 * @param length length of the file
333 * @param reader function that can be used to obtain the data for the file 307 * @param reader function that can be used to obtain the data for the file
@@ -345,7 +319,8 @@ GNUNET_FS_file_information_create_from_data (void *client_info,
345 * @return publish structure entry for the file 319 * @return publish structure entry for the file
346 */ 320 */
347struct GNUNET_FS_FileInformation * 321struct GNUNET_FS_FileInformation *
348GNUNET_FS_file_information_create_from_reader (void *client_info, 322GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
323 void *client_info,
349 uint64_t length, 324 uint64_t length,
350 GNUNET_FS_DataReader reader, 325 GNUNET_FS_DataReader reader,
351 void *reader_cls, 326 void *reader_cls,
@@ -359,6 +334,7 @@ GNUNET_FS_file_information_create_from_reader (void *client_info,
359 struct GNUNET_FS_FileInformation *ret; 334 struct GNUNET_FS_FileInformation *ret;
360 335
361 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation)); 336 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
337 ret->h = h;
362 ret->client_info = client_info; 338 ret->client_info = client_info;
363 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 339 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
364 if (ret->meta == NULL) 340 if (ret->meta == NULL)
@@ -371,7 +347,6 @@ GNUNET_FS_file_information_create_from_reader (void *client_info,
371 ret->data.file.file_size = length; 347 ret->data.file.file_size = length;
372 ret->anonymity = anonymity; 348 ret->anonymity = anonymity;
373 ret->priority = priority; 349 ret->priority = priority;
374 GNUNET_FS_file_information_sync (ret);
375 return ret; 350 return ret;
376} 351}
377 352
@@ -387,6 +362,11 @@ struct DirScanCls
387 struct EXTRACTOR_PluginList *extractors; 362 struct EXTRACTOR_PluginList *extractors;
388 363
389 /** 364 /**
365 * Master context.
366 */
367 struct GNUNET_FS_Handle *h;
368
369 /**
390 * Function to call on each directory entry. 370 * Function to call on each directory entry.
391 */ 371 */
392 GNUNET_FS_FileProcessor proc; 372 GNUNET_FS_FileProcessor proc;
@@ -462,7 +442,8 @@ dir_scan_cb (void *cls,
462 } 442 }
463 if (S_ISDIR (sbuf.st_mode)) 443 if (S_ISDIR (sbuf.st_mode))
464 { 444 {
465 fi = GNUNET_FS_file_information_create_from_directory (NULL, 445 fi = GNUNET_FS_file_information_create_from_directory (dsc->h,
446 NULL,
466 filename, 447 filename,
467 dsc->scanner, 448 dsc->scanner,
468 dsc->scanner_cls, 449 dsc->scanner_cls,
@@ -486,7 +467,8 @@ dir_scan_cb (void *cls,
486 // FIXME: remove path from filename in metadata! 467 // FIXME: remove path from filename in metadata!
487 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta); 468 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
488 ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords); 469 ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords);
489 fi = GNUNET_FS_file_information_create_from_file (NULL, 470 fi = GNUNET_FS_file_information_create_from_file (dsc->h,
471 NULL,
490 filename, 472 filename,
491 ksk_uri, 473 ksk_uri,
492 meta, 474 meta,
@@ -517,6 +499,7 @@ dir_scan_cb (void *cls,
517 * convenience function. 499 * convenience function.
518 * 500 *
519 * @param cls must be of type "struct EXTRACTOR_Extractor*" 501 * @param cls must be of type "struct EXTRACTOR_Extractor*"
502 * @param h handle to the file sharing subsystem
520 * @param dirname name of the directory to scan 503 * @param dirname name of the directory to scan
521 * @param do_index should files be indexed or inserted 504 * @param do_index should files be indexed or inserted
522 * @param anonymity desired anonymity level 505 * @param anonymity desired anonymity level
@@ -529,6 +512,7 @@ dir_scan_cb (void *cls,
529 */ 512 */
530int 513int
531GNUNET_FS_directory_scanner_default (void *cls, 514GNUNET_FS_directory_scanner_default (void *cls,
515 struct GNUNET_FS_Handle *h,
532 const char *dirname, 516 const char *dirname,
533 int do_index, 517 int do_index,
534 uint32_t anonymity, 518 uint32_t anonymity,
@@ -541,6 +525,7 @@ GNUNET_FS_directory_scanner_default (void *cls,
541 struct EXTRACTOR_PluginList *ex = cls; 525 struct EXTRACTOR_PluginList *ex = cls;
542 struct DirScanCls dsc; 526 struct DirScanCls dsc;
543 527
528 dsc.h = h;
544 dsc.extractors = ex; 529 dsc.extractors = ex;
545 dsc.proc = proc; 530 dsc.proc = proc;
546 dsc.proc_cls = proc_cls; 531 dsc.proc_cls = proc_cls;
@@ -607,6 +592,7 @@ dirproc (void *cls,
607 * passed (GNUNET_FS_directory_scanner_default). This is strictly a 592 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
608 * convenience function. 593 * convenience function.
609 * 594 *
595 * @param h handle to the file sharing subsystem
610 * @param client_info initial value for the client-info value for this entry 596 * @param client_info initial value for the client-info value for this entry
611 * @param filename name of the top-level file or directory 597 * @param filename name of the top-level file or directory
612 * @param scanner function used to get a list of files in a directory 598 * @param scanner function used to get a list of files in a directory
@@ -621,7 +607,8 @@ dirproc (void *cls,
621 * @return publish structure entry for the directory, NULL on error 607 * @return publish structure entry for the directory, NULL on error
622 */ 608 */
623struct GNUNET_FS_FileInformation * 609struct GNUNET_FS_FileInformation *
624GNUNET_FS_file_information_create_from_directory (void *client_info, 610GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
611 void *client_info,
625 const char *filename, 612 const char *filename,
626 GNUNET_FS_DirectoryScanner scanner, 613 GNUNET_FS_DirectoryScanner scanner,
627 void *scanner_cls, 614 void *scanner_cls,
@@ -642,6 +629,7 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
642 meta = GNUNET_CONTAINER_meta_data_create (); 629 meta = GNUNET_CONTAINER_meta_data_create ();
643 GNUNET_FS_meta_data_make_directory (meta); 630 GNUNET_FS_meta_data_make_directory (meta);
644 scanner (scanner_cls, 631 scanner (scanner_cls,
632 h,
645 filename, 633 filename,
646 do_index, 634 do_index,
647 anonymity, 635 anonymity,
@@ -652,7 +640,8 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
652 emsg); 640 emsg);
653 ksk = NULL; // FIXME... 641 ksk = NULL; // FIXME...
654 // FIXME: create meta! 642 // FIXME: create meta!
655 ret = GNUNET_FS_file_information_create_empty_directory (client_info, 643 ret = GNUNET_FS_file_information_create_empty_directory (h,
644 client_info,
656 ksk, 645 ksk,
657 meta, 646 meta,
658 anonymity, 647 anonymity,
@@ -663,7 +652,6 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
663 while (dc.entries != NULL) 652 while (dc.entries != NULL)
664 { 653 {
665 dc.entries->dir = ret; 654 dc.entries->dir = ret;
666 GNUNET_FS_file_information_sync (dc.entries);
667 dc.entries = dc.entries->next; 655 dc.entries = dc.entries->next;
668 } 656 }
669 fn = filename; 657 fn = filename;
@@ -678,7 +666,6 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
678 fn, 666 fn,
679 strlen (fn) + 1); 667 strlen (fn) + 1);
680 ret->filename = GNUNET_strdup (filename); 668 ret->filename = GNUNET_strdup (filename);
681 GNUNET_FS_file_information_sync (ret);
682 return ret; 669 return ret;
683} 670}
684 671
@@ -689,6 +676,7 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
689 * use of "GNUNET_FS_file_information_create_from_directory" 676 * use of "GNUNET_FS_file_information_create_from_directory"
690 * is not appropriate. 677 * is not appropriate.
691 * 678 *
679 * @param h handle to the file sharing subsystem
692 * @param client_info initial value for the client-info value for this entry 680 * @param client_info initial value for the client-info value for this entry
693 * @param meta metadata for the directory 681 * @param meta metadata for the directory
694 * @param keywords under which keywords should this directory be available 682 * @param keywords under which keywords should this directory be available
@@ -701,7 +689,8 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
701 * @return publish structure entry for the directory , NULL on error 689 * @return publish structure entry for the directory , NULL on error
702 */ 690 */
703struct GNUNET_FS_FileInformation * 691struct GNUNET_FS_FileInformation *
704GNUNET_FS_file_information_create_empty_directory (void *client_info, 692GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
693 void *client_info,
705 const struct GNUNET_FS_Uri *keywords, 694 const struct GNUNET_FS_Uri *keywords,
706 const struct GNUNET_CONTAINER_MetaData *meta, 695 const struct GNUNET_CONTAINER_MetaData *meta,
707 uint32_t anonymity, 696 uint32_t anonymity,
@@ -711,6 +700,7 @@ GNUNET_FS_file_information_create_empty_directory (void *client_info,
711 struct GNUNET_FS_FileInformation *ret; 700 struct GNUNET_FS_FileInformation *ret;
712 701
713 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation)); 702 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
703 ret->h = h;
714 ret->client_info = client_info; 704 ret->client_info = client_info;
715 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 705 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
716 ret->keywords = GNUNET_FS_uri_dup (keywords); 706 ret->keywords = GNUNET_FS_uri_dup (keywords);
@@ -718,7 +708,6 @@ GNUNET_FS_file_information_create_empty_directory (void *client_info,
718 ret->is_directory = GNUNET_YES; 708 ret->is_directory = GNUNET_YES;
719 ret->anonymity = anonymity; 709 ret->anonymity = anonymity;
720 ret->priority = priority; 710 ret->priority = priority;
721 GNUNET_FS_file_information_sync (ret);
722 return ret; 711 return ret;
723} 712}
724 713
@@ -749,8 +738,6 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
749 ent->next = dir->data.dir.entries; 738 ent->next = dir->data.dir.entries;
750 dir->data.dir.entries = ent; 739 dir->data.dir.entries = ent;
751 dir->data.dir.dir_size = 0; 740 dir->data.dir.dir_size = 0;
752 GNUNET_FS_file_information_sync (ent);
753 GNUNET_FS_file_information_sync (dir);
754 return GNUNET_OK; 741 return GNUNET_OK;
755} 742}
756 743