diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-03-10 16:45:11 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-03-10 16:45:11 +0000 |
commit | cd3275dec48f35828837a84aae979c5e180f5184 (patch) | |
tree | 5e1b0ccec36c6520c8bb9031fbbb60d3b239680a /src/fs/gnunet-publish.c | |
parent | f80a715b51f29c406885b63e92620deacf427c84 (diff) | |
download | gnunet-cd3275dec48f35828837a84aae979c5e180f5184.tar.gz gnunet-cd3275dec48f35828837a84aae979c5e180f5184.zip |
fixing gnunet-publish for files
Diffstat (limited to 'src/fs/gnunet-publish.c')
-rw-r--r-- | src/fs/gnunet-publish.c | 108 |
1 files changed, 78 insertions, 30 deletions
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index d063b73c7..db4ea978e 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c | |||
@@ -41,6 +41,8 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
41 | 41 | ||
42 | static struct GNUNET_FS_Handle *ctx; | 42 | static struct GNUNET_FS_Handle *ctx; |
43 | 43 | ||
44 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
45 | |||
44 | static struct GNUNET_FS_PublishContext *pc; | 46 | static struct GNUNET_FS_PublishContext *pc; |
45 | 47 | ||
46 | static struct GNUNET_CONTAINER_MetaData *meta; | 48 | static struct GNUNET_CONTAINER_MetaData *meta; |
@@ -70,6 +72,21 @@ static int extract_only; | |||
70 | static int do_disable_creation_time; | 72 | static int do_disable_creation_time; |
71 | 73 | ||
72 | 74 | ||
75 | static void | ||
76 | do_stop_task (void *cls, | ||
77 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
78 | { | ||
79 | struct GNUNET_FS_PublishContext *p; | ||
80 | |||
81 | if (pc != NULL) | ||
82 | { | ||
83 | p = pc; | ||
84 | pc = NULL; | ||
85 | GNUNET_FS_publish_stop (p); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | |||
73 | /** | 90 | /** |
74 | * Called by FS client to give information about the progress of an | 91 | * Called by FS client to give information about the progress of an |
75 | * operation. | 92 | * operation. |
@@ -110,18 +127,23 @@ progress_cb (void *cls, | |||
110 | fprintf (stderr, | 127 | fprintf (stderr, |
111 | _("Error publishing: %s.\n"), | 128 | _("Error publishing: %s.\n"), |
112 | info->value.publish.specifics.error.message); | 129 | info->value.publish.specifics.error.message); |
113 | GNUNET_FS_publish_stop (pc); | 130 | GNUNET_SCHEDULER_add_continuation (sched, |
131 | &do_stop_task, | ||
132 | NULL, | ||
133 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
114 | break; | 134 | break; |
115 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 135 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
116 | fprintf (stdout, | 136 | fprintf (stdout, |
117 | _("Publishing `%s' done.\n"), | 137 | _("Publishing `%s' done.\n"), |
118 | info->value.publish.filename); | 138 | info->value.publish.filename); |
119 | if (info->value.publish.pctx == NULL) | 139 | if (info->value.publish.pctx == NULL) |
120 | GNUNET_FS_publish_stop (pc); | 140 | GNUNET_SCHEDULER_add_continuation (sched, |
141 | &do_stop_task, | ||
142 | NULL, | ||
143 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
121 | break; | 144 | break; |
122 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 145 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
123 | if (info->value.publish.sc == pc) | 146 | GNUNET_break (NULL == pc); |
124 | GNUNET_FS_stop (ctx); | ||
125 | return NULL; | 147 | return NULL; |
126 | default: | 148 | default: |
127 | fprintf (stderr, | 149 | fprintf (stderr, |
@@ -203,10 +225,9 @@ meta_merger (void *cls, | |||
203 | 225 | ||
204 | 226 | ||
205 | /** | 227 | /** |
206 | * Function called on all entries before the | 228 | * Function called on all entries before the publication. This is |
207 | * publication. This is where we perform | 229 | * where we perform modifications to the default based on command-line |
208 | * modifications to the default based on | 230 | * options. |
209 | * command-line options. | ||
210 | * | 231 | * |
211 | * @param cls closure | 232 | * @param cls closure |
212 | * @param fi the entry in the publish-structure | 233 | * @param fi the entry in the publish-structure |
@@ -236,18 +257,23 @@ publish_inspector (void *cls, | |||
236 | char *fs; | 257 | char *fs; |
237 | struct GNUNET_FS_Uri *new_uri; | 258 | struct GNUNET_FS_Uri *new_uri; |
238 | 259 | ||
239 | if (! do_disable_creation_time) | ||
240 | GNUNET_CONTAINER_meta_data_add_publication_date (meta); | ||
241 | if (NULL != topKeywords) | 260 | if (NULL != topKeywords) |
242 | { | 261 | { |
243 | new_uri = GNUNET_FS_uri_ksk_merge (topKeywords, | 262 | if (*uri != NULL) |
244 | *uri); | 263 | { |
245 | GNUNET_FS_uri_destroy (*uri); | 264 | new_uri = GNUNET_FS_uri_ksk_merge (topKeywords, |
246 | *uri = new_uri; | 265 | *uri); |
247 | GNUNET_FS_uri_destroy (topKeywords); | 266 | GNUNET_FS_uri_destroy (*uri); |
267 | *uri = new_uri; | ||
268 | GNUNET_FS_uri_destroy (topKeywords); | ||
269 | } | ||
270 | else | ||
271 | { | ||
272 | *uri = topKeywords; | ||
273 | } | ||
248 | topKeywords = NULL; | 274 | topKeywords = NULL; |
249 | } | 275 | } |
250 | if (NULL != meta) | 276 | if (NULL != meta) |
251 | { | 277 | { |
252 | GNUNET_CONTAINER_meta_data_iterate (meta, | 278 | GNUNET_CONTAINER_meta_data_iterate (meta, |
253 | &meta_merger, | 279 | &meta_merger, |
@@ -255,9 +281,11 @@ publish_inspector (void *cls, | |||
255 | GNUNET_CONTAINER_meta_data_destroy (meta); | 281 | GNUNET_CONTAINER_meta_data_destroy (meta); |
256 | meta = NULL; | 282 | meta = NULL; |
257 | } | 283 | } |
284 | if (! do_disable_creation_time) | ||
285 | GNUNET_CONTAINER_meta_data_add_publication_date (m); | ||
258 | if (extract_only) | 286 | if (extract_only) |
259 | { | 287 | { |
260 | fn = GNUNET_CONTAINER_meta_data_get_by_type (meta, | 288 | fn = GNUNET_CONTAINER_meta_data_get_by_type (m, |
261 | EXTRACTOR_METATYPE_FILENAME); | 289 | EXTRACTOR_METATYPE_FILENAME); |
262 | fs = GNUNET_STRINGS_byte_size_fancy (length); | 290 | fs = GNUNET_STRINGS_byte_size_fancy (length); |
263 | fprintf (stdout, | 291 | fprintf (stdout, |
@@ -266,12 +294,12 @@ publish_inspector (void *cls, | |||
266 | fs); | 294 | fs); |
267 | GNUNET_free (fn); | 295 | GNUNET_free (fn); |
268 | GNUNET_free (fs); | 296 | GNUNET_free (fs); |
269 | GNUNET_CONTAINER_meta_data_iterate (meta, | 297 | GNUNET_CONTAINER_meta_data_iterate (m, |
270 | &meta_printer, | 298 | &meta_printer, |
271 | NULL); | 299 | NULL); |
272 | fprintf (stdout, "\n"); | 300 | fprintf (stdout, "\n"); |
273 | } | 301 | } |
274 | if (GNUNET_FS_meta_data_test_for_directory (meta)) | 302 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) |
275 | GNUNET_FS_file_information_inspect (fi, | 303 | GNUNET_FS_file_information_inspect (fi, |
276 | &publish_inspector, | 304 | &publish_inspector, |
277 | NULL); | 305 | NULL); |
@@ -283,14 +311,14 @@ publish_inspector (void *cls, | |||
283 | * Main function that will be run by the scheduler. | 311 | * Main function that will be run by the scheduler. |
284 | * | 312 | * |
285 | * @param cls closure | 313 | * @param cls closure |
286 | * @param sched the scheduler to use | 314 | * @param s the scheduler to use |
287 | * @param args remaining command-line arguments | 315 | * @param args remaining command-line arguments |
288 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | 316 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) |
289 | * @param c configuration | 317 | * @param c configuration |
290 | */ | 318 | */ |
291 | static void | 319 | static void |
292 | run (void *cls, | 320 | run (void *cls, |
293 | struct GNUNET_SCHEDULER_Handle *sched, | 321 | struct GNUNET_SCHEDULER_Handle *s, |
294 | char *const *args, | 322 | char *const *args, |
295 | const char *cfgfile, | 323 | const char *cfgfile, |
296 | const struct GNUNET_CONFIGURATION_Handle *c) | 324 | const struct GNUNET_CONFIGURATION_Handle *c) |
@@ -298,9 +326,11 @@ run (void *cls, | |||
298 | struct GNUNET_FS_FileInformation *fi; | 326 | struct GNUNET_FS_FileInformation *fi; |
299 | struct GNUNET_FS_Namespace *namespace; | 327 | struct GNUNET_FS_Namespace *namespace; |
300 | struct EXTRACTOR_PluginList *l; | 328 | struct EXTRACTOR_PluginList *l; |
329 | struct stat sbuf; | ||
301 | char *ex; | 330 | char *ex; |
302 | char *emsg; | 331 | char *emsg; |
303 | 332 | ||
333 | sched = s; | ||
304 | /* check arguments */ | 334 | /* check arguments */ |
305 | if ( ( (uri_string == NULL) || (extract_only) ) | 335 | if ( ( (uri_string == NULL) || (extract_only) ) |
306 | && ( (args[0] == NULL) || (args[1] != NULL) ) ) | 336 | && ( (args[0] == NULL) || (args[1] != NULL) ) ) |
@@ -409,15 +439,33 @@ run (void *cls, | |||
409 | GNUNET_free (ex); | 439 | GNUNET_free (ex); |
410 | } | 440 | } |
411 | } | 441 | } |
412 | fi = GNUNET_FS_file_information_create_from_directory (NULL, | 442 | emsg = NULL; |
413 | args[0], | 443 | if (0 != STAT (args[0], &sbuf)) |
414 | &GNUNET_FS_directory_scanner_default, | 444 | GNUNET_asprintf (&emsg, |
415 | l, | 445 | _("Could not access file: %s\n"), |
416 | !do_insert, | 446 | STRERROR (errno)); |
417 | anonymity, | 447 | else if (S_ISDIR (sbuf.st_mode)) |
418 | priority, | 448 | fi = GNUNET_FS_file_information_create_from_directory (NULL, |
419 | GNUNET_TIME_relative_to_absolute (DEFAULT_EXPIRATION), | 449 | args[0], |
420 | &emsg); | 450 | &GNUNET_FS_directory_scanner_default, |
451 | l, | ||
452 | !do_insert, | ||
453 | anonymity, | ||
454 | priority, | ||
455 | GNUNET_TIME_relative_to_absolute (DEFAULT_EXPIRATION), | ||
456 | &emsg); | ||
457 | else | ||
458 | { | ||
459 | fi = GNUNET_FS_file_information_create_from_file (NULL, | ||
460 | args[0], | ||
461 | NULL, | ||
462 | NULL, | ||
463 | !do_insert, | ||
464 | anonymity, | ||
465 | priority, | ||
466 | GNUNET_TIME_relative_to_absolute (DEFAULT_EXPIRATION)); | ||
467 | GNUNET_break (fi != NULL); | ||
468 | } | ||
421 | EXTRACTOR_plugin_remove_all (l); | 469 | EXTRACTOR_plugin_remove_all (l); |
422 | if (fi == NULL) | 470 | if (fi == NULL) |
423 | { | 471 | { |