diff options
Diffstat (limited to 'src/util/disk.c')
-rw-r--r-- | src/util/disk.c | 139 |
1 files changed, 0 insertions, 139 deletions
diff --git a/src/util/disk.c b/src/util/disk.c index da78a1e1d..81413265e 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -1278,145 +1278,6 @@ GNUNET_DISK_directory_scan (const char *dir_name, | |||
1278 | 1278 | ||
1279 | 1279 | ||
1280 | /** | 1280 | /** |
1281 | * Opaque handle used for iterating over a directory. | ||
1282 | */ | ||
1283 | struct GNUNET_DISK_DirectoryIterator | ||
1284 | { | ||
1285 | |||
1286 | /** | ||
1287 | * Function to call on directory entries. | ||
1288 | */ | ||
1289 | GNUNET_DISK_DirectoryIteratorCallback callback; | ||
1290 | |||
1291 | /** | ||
1292 | * Closure for callback. | ||
1293 | */ | ||
1294 | void *callback_cls; | ||
1295 | |||
1296 | /** | ||
1297 | * Reference to directory. | ||
1298 | */ | ||
1299 | DIR *directory; | ||
1300 | |||
1301 | /** | ||
1302 | * Directory name. | ||
1303 | */ | ||
1304 | char *dirname; | ||
1305 | |||
1306 | /** | ||
1307 | * Next filename to process. | ||
1308 | */ | ||
1309 | char *next_name; | ||
1310 | |||
1311 | /** | ||
1312 | * Our priority. | ||
1313 | */ | ||
1314 | enum GNUNET_SCHEDULER_Priority priority; | ||
1315 | |||
1316 | }; | ||
1317 | |||
1318 | |||
1319 | /** | ||
1320 | * Task used by the directory iterator. | ||
1321 | */ | ||
1322 | static void | ||
1323 | directory_iterator_task (void *cls, | ||
1324 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1325 | { | ||
1326 | struct GNUNET_DISK_DirectoryIterator *iter = cls; | ||
1327 | char *name; | ||
1328 | |||
1329 | name = iter->next_name; | ||
1330 | GNUNET_assert (name != NULL); | ||
1331 | iter->next_name = NULL; | ||
1332 | iter->callback (iter->callback_cls, iter, name, iter->dirname); | ||
1333 | GNUNET_free (name); | ||
1334 | } | ||
1335 | |||
1336 | |||
1337 | /** | ||
1338 | * This function must be called during the DiskIteratorCallback | ||
1339 | * (exactly once) to schedule the task to process the next | ||
1340 | * filename in the directory (if there is one). | ||
1341 | * | ||
1342 | * @param iter opaque handle for the iterator | ||
1343 | * @param can set to GNUNET_YES to terminate the iteration early | ||
1344 | * @return GNUNET_YES if iteration will continue, | ||
1345 | * GNUNET_NO if this was the last entry (and iteration is complete), | ||
1346 | * GNUNET_SYSERR if abort was YES | ||
1347 | */ | ||
1348 | int | ||
1349 | GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter, | ||
1350 | int can) | ||
1351 | { | ||
1352 | struct dirent *finfo; | ||
1353 | |||
1354 | GNUNET_assert (iter->next_name == NULL); | ||
1355 | if (can == GNUNET_YES) | ||
1356 | { | ||
1357 | CLOSEDIR (iter->directory); | ||
1358 | GNUNET_free (iter->dirname); | ||
1359 | GNUNET_free (iter); | ||
1360 | return GNUNET_SYSERR; | ||
1361 | } | ||
1362 | while (NULL != (finfo = READDIR (iter->directory))) | ||
1363 | { | ||
1364 | if ((0 == strcmp (finfo->d_name, ".")) || | ||
1365 | (0 == strcmp (finfo->d_name, ".."))) | ||
1366 | continue; | ||
1367 | GNUNET_asprintf (&iter->next_name, "%s%s%s", iter->dirname, | ||
1368 | DIR_SEPARATOR_STR, finfo->d_name); | ||
1369 | break; | ||
1370 | } | ||
1371 | if (finfo == NULL) | ||
1372 | { | ||
1373 | GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); | ||
1374 | return GNUNET_NO; | ||
1375 | } | ||
1376 | GNUNET_SCHEDULER_add_with_priority (iter->priority, &directory_iterator_task, | ||
1377 | iter); | ||
1378 | return GNUNET_YES; | ||
1379 | } | ||
1380 | |||
1381 | |||
1382 | /** | ||
1383 | * Scan a directory for files using the scheduler to run a task for | ||
1384 | * each entry. The name of the directory must be expanded first (!). | ||
1385 | * If a scheduler does not need to be used, GNUNET_DISK_directory_scan | ||
1386 | * may provide a simpler API. | ||
1387 | * | ||
1388 | * @param prio priority to use | ||
1389 | * @param dir_name the name of the directory | ||
1390 | * @param callback the method to call for each file | ||
1391 | * @param callback_cls closure for callback | ||
1392 | * @return GNUNET_YES if directory is not empty and 'callback' | ||
1393 | * will be called later, GNUNET_NO otherwise, GNUNET_SYSERR on error. | ||
1394 | */ | ||
1395 | int | ||
1396 | GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, | ||
1397 | const char *dir_name, | ||
1398 | GNUNET_DISK_DirectoryIteratorCallback | ||
1399 | callback, void *callback_cls) | ||
1400 | { | ||
1401 | struct GNUNET_DISK_DirectoryIterator *di; | ||
1402 | |||
1403 | di = GNUNET_new (struct GNUNET_DISK_DirectoryIterator); | ||
1404 | di->callback = callback; | ||
1405 | di->callback_cls = callback_cls; | ||
1406 | di->directory = OPENDIR (dir_name); | ||
1407 | if (di->directory == NULL) | ||
1408 | { | ||
1409 | GNUNET_free (di); | ||
1410 | callback (callback_cls, NULL, NULL, NULL); | ||
1411 | return GNUNET_SYSERR; | ||
1412 | } | ||
1413 | di->dirname = GNUNET_strdup (dir_name); | ||
1414 | di->priority = prio; | ||
1415 | return GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); | ||
1416 | } | ||
1417 | |||
1418 | |||
1419 | /** | ||
1420 | * Function that removes the given directory by calling | 1281 | * Function that removes the given directory by calling |
1421 | * "GNUNET_DISK_directory_remove". | 1282 | * "GNUNET_DISK_directory_remove". |
1422 | * | 1283 | * |