From 7163fd6dae38f2e90b40f28f2439eeb46906739b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 25 Apr 2016 22:27:52 +0000 Subject: [PATCH] removing dead code --- src/util/Makefile.am | 1 - src/util/disk_iterator.c | 174 --------------------------------------- src/util/test_disk.c | 22 +---- 3 files changed, 2 insertions(+), 195 deletions(-) delete mode 100644 src/util/disk_iterator.c diff --git a/src/util/Makefile.am b/src/util/Makefile.am index c38f19c93..22471ffda 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -87,7 +87,6 @@ libgnunetutil_la_SOURCES = \ crypto_random.c \ crypto_rsa.c \ disk.c \ - disk_iterator.c \ disk.h \ getopt.c \ getopt_helpers.c \ diff --git a/src/util/disk_iterator.c b/src/util/disk_iterator.c deleted file mode 100644 index 2315f2861..000000000 --- a/src/util/disk_iterator.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2001--2013 GNUnet e.V. - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -/** - * @file util/disk_iterator.c - * @brief asynchronous iteration over a directory - * @author Christian Grothoff - * @author Nils Durner - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "disk.h" - -#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) - -#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall) - -#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) - - -/** - * Opaque handle used for iterating over a directory. - */ -struct GNUNET_DISK_DirectoryIterator -{ - - /** - * Function to call on directory entries. - */ - GNUNET_DISK_DirectoryIteratorCallback callback; - - /** - * Closure for @e callback. - */ - void *callback_cls; - - /** - * Reference to directory. - */ - DIR *directory; - - /** - * Directory name. - */ - char *dirname; - - /** - * Next filename to process. - */ - char *next_name; - - /** - * Our priority. - */ - enum GNUNET_SCHEDULER_Priority priority; - -}; - - -/** - * Task used by the directory iterator. - */ -static void -directory_iterator_task (void *cls) -{ - struct GNUNET_DISK_DirectoryIterator *iter = cls; - char *name; - - name = iter->next_name; - GNUNET_assert (name != NULL); - iter->next_name = NULL; - iter->callback (iter->callback_cls, iter, name, iter->dirname); - GNUNET_free (name); -} - - -/** - * This function must be called during the DiskIteratorCallback - * (exactly once) to schedule the task to process the next - * filename in the directory (if there is one). - * - * @param iter opaque handle for the iterator - * @param can set to #GNUNET_YES to terminate the iteration early - * @return #GNUNET_YES if iteration will continue, - * #GNUNET_NO if this was the last entry (and iteration is complete), - * #GNUNET_SYSERR if abort was YES - */ -int -GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter, - int can) -{ - struct dirent *finfo; - - GNUNET_assert (iter->next_name == NULL); - if (can == GNUNET_YES) - { - CLOSEDIR (iter->directory); - GNUNET_free (iter->dirname); - GNUNET_free (iter); - return GNUNET_SYSERR; - } - while (NULL != (finfo = READDIR (iter->directory))) - { - if ((0 == strcmp (finfo->d_name, ".")) || - (0 == strcmp (finfo->d_name, ".."))) - continue; - GNUNET_asprintf (&iter->next_name, "%s%s%s", iter->dirname, - DIR_SEPARATOR_STR, finfo->d_name); - break; - } - if (finfo == NULL) - { - GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); - return GNUNET_NO; - } - GNUNET_SCHEDULER_add_with_priority (iter->priority, &directory_iterator_task, - iter); - return GNUNET_YES; -} - - -/** - * Scan a directory for files using the scheduler to run a task for - * each entry. The name of the directory must be expanded first (!). - * If a scheduler does not need to be used, GNUNET_DISK_directory_scan - * may provide a simpler API. - * - * @param prio priority to use - * @param dir_name the name of the directory - * @param callback the method to call for each file - * @param callback_cls closure for @a callback - * @return #GNUNET_YES if directory is not empty and @a callback - * will be called later, #GNUNET_NO otherwise, #GNUNET_SYSERR on error. - */ -int -GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, - const char *dir_name, - GNUNET_DISK_DirectoryIteratorCallback - callback, void *callback_cls) -{ - struct GNUNET_DISK_DirectoryIterator *di; - - di = GNUNET_new (struct GNUNET_DISK_DirectoryIterator); - di->callback = callback; - di->callback_cls = callback_cls; - di->directory = OPENDIR (dir_name); - if (di->directory == NULL) - { - GNUNET_free (di); - callback (callback_cls, NULL, NULL, NULL); - return GNUNET_SYSERR; - } - di->dirname = GNUNET_strdup (dir_name); - di->priority = prio; - return GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); -} - -/* end of disk_iterator */ diff --git a/src/util/test_disk.c b/src/util/test_disk.c index 86b96e16c..055e155e9 100644 --- a/src/util/test_disk.c +++ b/src/util/test_disk.c @@ -130,23 +130,6 @@ testDirScan () return 0; } -static void -iter_callback (void *cls, struct GNUNET_DISK_DirectoryIterator *di, - const char *filename, const char *dirname) -{ - int *i = cls; - - (*i)++; - GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); -} - -static void -iter_task (void *cls) -{ - GNUNET_DISK_directory_iterator_start (GNUNET_SCHEDULER_PRIORITY_DEFAULT, - "test", &iter_callback, cls); -} - static int testDirIter () @@ -160,7 +143,6 @@ testDirIter () return 1; if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_more")) return 1; - GNUNET_SCHEDULER_run (&iter_task, &i); if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) return 1; if (i < 3) @@ -184,6 +166,7 @@ testCanonicalize () return 0; } + static int testChangeOwner () { @@ -195,6 +178,7 @@ testChangeOwner () return 0; } + static int testDirMani () { @@ -212,8 +196,6 @@ testDirMani () return 1; if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) return 1; - - return 0; } -- 2.25.1