diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-15 14:55:13 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-15 14:55:13 +0000 |
commit | 8d4671bb0e9e1ae40053a8250203e281b53c7d5c (patch) | |
tree | 2148fc9844a0931b9f0c8cb369f8a81a447a7777 /src/fs/fs_dirmetascan.c | |
parent | 943110ad52014e30c1ea29b0c68166149902ab85 (diff) | |
download | gnunet-8d4671bb0e9e1ae40053a8250203e281b53c7d5c.tar.gz gnunet-8d4671bb0e9e1ae40053a8250203e281b53c7d5c.zip |
-LRN: use filescanner in gnunet-publish
Diffstat (limited to 'src/fs/fs_dirmetascan.c')
-rw-r--r-- | src/fs/fs_dirmetascan.c | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c index b9e400c00..b9fa45c1f 100644 --- a/src/fs/fs_dirmetascan.c +++ b/src/fs/fs_dirmetascan.c | |||
@@ -568,6 +568,13 @@ extract_file (struct AddDirStack *ads, const char *filename) | |||
568 | EXTRACTOR_METATYPE_FILENAME, | 568 | EXTRACTOR_METATYPE_FILENAME, |
569 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 569 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
570 | short_fn, strlen (short_fn) + 1); | 570 | short_fn, strlen (short_fn) + 1); |
571 | if (ads->parent == NULL) | ||
572 | { | ||
573 | /* we're finished with the scan, make sure caller gets the top-level | ||
574 | * directory pointer | ||
575 | */ | ||
576 | ads->adc->toplevel = item; | ||
577 | } | ||
571 | } | 578 | } |
572 | 579 | ||
573 | /** | 580 | /** |
@@ -869,7 +876,7 @@ GNUNET_FS_directory_scan_cleanup (struct GNUNET_FS_DirScanner *ds) | |||
869 | * The function from which the scanner thread starts | 876 | * The function from which the scanner thread starts |
870 | */ | 877 | */ |
871 | #if WINDOWS | 878 | #if WINDOWS |
872 | static DWORD | 879 | DWORD |
873 | #else | 880 | #else |
874 | static void * | 881 | static void * |
875 | #endif | 882 | #endif |
@@ -1043,12 +1050,7 @@ GNUNET_FS_directory_scan_start (const char *filename, | |||
1043 | 1050 | ||
1044 | if (0 != STAT (filename, &sbuf)) | 1051 | if (0 != STAT (filename, &sbuf)) |
1045 | return NULL; | 1052 | return NULL; |
1046 | /* TODO: consider generalizing this for files too! */ | 1053 | |
1047 | if (!S_ISDIR (sbuf.st_mode)) | ||
1048 | { | ||
1049 | GNUNET_break (0); | ||
1050 | return NULL; | ||
1051 | } | ||
1052 | /* scan_directory() is guaranteed to be given expanded filenames, | 1054 | /* scan_directory() is guaranteed to be given expanded filenames, |
1053 | * so expand we will! | 1055 | * so expand we will! |
1054 | */ | 1056 | */ |
@@ -1211,30 +1213,35 @@ trim_share_tree_task (void *cls, | |||
1211 | /* process a child entry (a file or a directory) and move to the next one*/ | 1213 | /* process a child entry (a file or a directory) and move to the next one*/ |
1212 | if (stack->item->is_directory) | 1214 | if (stack->item->is_directory) |
1213 | stack->end_directory = GNUNET_NO; | 1215 | stack->end_directory = GNUNET_NO; |
1214 | stack->dir_entry_count++; | 1216 | if (stack->ctx->toplevel->is_directory) |
1215 | GNUNET_CONTAINER_meta_data_iterate (stack->item->meta, &add_to_meta_counter, stack->metacounter); | ||
1216 | |||
1217 | if (stack->item->is_directory) | ||
1218 | { | 1217 | { |
1219 | char *user = getenv ("USER"); | 1218 | stack->dir_entry_count++; |
1220 | if ((user == NULL) || (0 != strncasecmp (user, stack->item->short_filename, strlen(user)))) | 1219 | GNUNET_CONTAINER_meta_data_iterate (stack->item->meta, &add_to_meta_counter, stack->metacounter); |
1220 | |||
1221 | if (stack->item->is_directory) | ||
1221 | { | 1222 | { |
1222 | /* only use filename if it doesn't match $USER */ | 1223 | char *user = getenv ("USER"); |
1223 | GNUNET_CONTAINER_meta_data_insert (stack->item->meta, "<libgnunetfs>", | 1224 | if ((user == NULL) || (0 != strncasecmp (user, stack->item->short_filename, strlen(user)))) |
1224 | EXTRACTOR_METATYPE_FILENAME, | 1225 | { |
1225 | EXTRACTOR_METAFORMAT_UTF8, | 1226 | /* only use filename if it doesn't match $USER */ |
1226 | "text/plain", stack->item->short_filename, | 1227 | GNUNET_CONTAINER_meta_data_insert (stack->item->meta, "<libgnunetfs>", |
1227 | strlen (stack->item->short_filename) + 1); | 1228 | EXTRACTOR_METATYPE_FILENAME, |
1228 | GNUNET_CONTAINER_meta_data_insert (stack->item->meta, "<libgnunetfs>", | 1229 | EXTRACTOR_METAFORMAT_UTF8, |
1229 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | 1230 | "text/plain", stack->item->short_filename, |
1230 | EXTRACTOR_METAFORMAT_UTF8, | 1231 | strlen (stack->item->short_filename) + 1); |
1231 | "text/plain", stack->item->short_filename, | 1232 | GNUNET_CONTAINER_meta_data_insert (stack->item->meta, "<libgnunetfs>", |
1232 | strlen (stack->item->short_filename) + 1); | 1233 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, |
1234 | EXTRACTOR_METAFORMAT_UTF8, | ||
1235 | "text/plain", stack->item->short_filename, | ||
1236 | strlen (stack->item->short_filename) + 1); | ||
1237 | } | ||
1233 | } | 1238 | } |
1234 | } | 1239 | } |
1235 | |||
1236 | stack->item->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (stack->item->meta); | 1240 | stack->item->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (stack->item->meta); |
1237 | GNUNET_FS_uri_ksk_get_keywords (stack->item->ksk_uri, &add_to_keyword_counter, stack->keywordcounter); | 1241 | if (stack->ctx->toplevel->is_directory) |
1242 | { | ||
1243 | GNUNET_FS_uri_ksk_get_keywords (stack->item->ksk_uri, &add_to_keyword_counter, stack->keywordcounter); | ||
1244 | } | ||
1238 | stack->item = stack->item->next; | 1245 | stack->item = stack->item->next; |
1239 | } | 1246 | } |
1240 | /* Call this task again later, if there are more entries to process */ | 1247 | /* Call this task again later, if there are more entries to process */ |
@@ -1270,8 +1277,13 @@ GNUNET_FS_trim_share_tree (struct GNUNET_FS_ShareTreeItem *toplevel, | |||
1270 | ret->stack = GNUNET_malloc (sizeof (struct ProcessMetadataStackItem)); | 1277 | ret->stack = GNUNET_malloc (sizeof (struct ProcessMetadataStackItem)); |
1271 | ret->stack->ctx = ret; | 1278 | ret->stack->ctx = ret; |
1272 | ret->stack->item = toplevel; | 1279 | ret->stack->item = toplevel; |
1273 | ret->stack->keywordcounter = GNUNET_CONTAINER_multihashmap_create (1024); | 1280 | |
1274 | ret->stack->metacounter = GNUNET_CONTAINER_multihashmap_create (1024); | 1281 | if (ret->stack->ctx->toplevel->is_directory) |
1282 | { | ||
1283 | ret->stack->keywordcounter = GNUNET_CONTAINER_multihashmap_create (1024); | ||
1284 | ret->stack->metacounter = GNUNET_CONTAINER_multihashmap_create (1024); | ||
1285 | } | ||
1286 | |||
1275 | ret->stack->dir_entry_count = 0; | 1287 | ret->stack->dir_entry_count = 0; |
1276 | ret->stack->end_directory = GNUNET_NO; | 1288 | ret->stack->end_directory = GNUNET_NO; |
1277 | 1289 | ||