diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-04-25 22:27:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-04-25 22:27:52 +0000 |
commit | 7163fd6dae38f2e90b40f28f2439eeb46906739b (patch) | |
tree | 3b738bdae14559e476cf92f06d1fcc19c7018447 /src | |
parent | 738a832406e48dadd062150c5bc2aa03cfa401ba (diff) | |
download | gnunet-7163fd6dae38f2e90b40f28f2439eeb46906739b.tar.gz gnunet-7163fd6dae38f2e90b40f28f2439eeb46906739b.zip |
removing dead code
Diffstat (limited to 'src')
-rw-r--r-- | src/util/Makefile.am | 1 | ||||
-rw-r--r-- | src/util/disk_iterator.c | 174 | ||||
-rw-r--r-- | src/util/test_disk.c | 22 |
3 files changed, 2 insertions, 195 deletions
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 = \ | |||
87 | crypto_random.c \ | 87 | crypto_random.c \ |
88 | crypto_rsa.c \ | 88 | crypto_rsa.c \ |
89 | disk.c \ | 89 | disk.c \ |
90 | disk_iterator.c \ | ||
91 | disk.h \ | 90 | disk.h \ |
92 | getopt.c \ | 91 | getopt.c \ |
93 | getopt_helpers.c \ | 92 | 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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2001--2013 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/disk_iterator.c | ||
22 | * @brief asynchronous iteration over a directory | ||
23 | * @author Christian Grothoff | ||
24 | * @author Nils Durner | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "disk.h" | ||
29 | |||
30 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | ||
31 | |||
32 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall) | ||
33 | |||
34 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) | ||
35 | |||
36 | |||
37 | /** | ||
38 | * Opaque handle used for iterating over a directory. | ||
39 | */ | ||
40 | struct GNUNET_DISK_DirectoryIterator | ||
41 | { | ||
42 | |||
43 | /** | ||
44 | * Function to call on directory entries. | ||
45 | */ | ||
46 | GNUNET_DISK_DirectoryIteratorCallback callback; | ||
47 | |||
48 | /** | ||
49 | * Closure for @e callback. | ||
50 | */ | ||
51 | void *callback_cls; | ||
52 | |||
53 | /** | ||
54 | * Reference to directory. | ||
55 | */ | ||
56 | DIR *directory; | ||
57 | |||
58 | /** | ||
59 | * Directory name. | ||
60 | */ | ||
61 | char *dirname; | ||
62 | |||
63 | /** | ||
64 | * Next filename to process. | ||
65 | */ | ||
66 | char *next_name; | ||
67 | |||
68 | /** | ||
69 | * Our priority. | ||
70 | */ | ||
71 | enum GNUNET_SCHEDULER_Priority priority; | ||
72 | |||
73 | }; | ||
74 | |||
75 | |||
76 | /** | ||
77 | * Task used by the directory iterator. | ||
78 | */ | ||
79 | static void | ||
80 | directory_iterator_task (void *cls) | ||
81 | { | ||
82 | struct GNUNET_DISK_DirectoryIterator *iter = cls; | ||
83 | char *name; | ||
84 | |||
85 | name = iter->next_name; | ||
86 | GNUNET_assert (name != NULL); | ||
87 | iter->next_name = NULL; | ||
88 | iter->callback (iter->callback_cls, iter, name, iter->dirname); | ||
89 | GNUNET_free (name); | ||
90 | } | ||
91 | |||
92 | |||
93 | /** | ||
94 | * This function must be called during the DiskIteratorCallback | ||
95 | * (exactly once) to schedule the task to process the next | ||
96 | * filename in the directory (if there is one). | ||
97 | * | ||
98 | * @param iter opaque handle for the iterator | ||
99 | * @param can set to #GNUNET_YES to terminate the iteration early | ||
100 | * @return #GNUNET_YES if iteration will continue, | ||
101 | * #GNUNET_NO if this was the last entry (and iteration is complete), | ||
102 | * #GNUNET_SYSERR if abort was YES | ||
103 | */ | ||
104 | int | ||
105 | GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter, | ||
106 | int can) | ||
107 | { | ||
108 | struct dirent *finfo; | ||
109 | |||
110 | GNUNET_assert (iter->next_name == NULL); | ||
111 | if (can == GNUNET_YES) | ||
112 | { | ||
113 | CLOSEDIR (iter->directory); | ||
114 | GNUNET_free (iter->dirname); | ||
115 | GNUNET_free (iter); | ||
116 | return GNUNET_SYSERR; | ||
117 | } | ||
118 | while (NULL != (finfo = READDIR (iter->directory))) | ||
119 | { | ||
120 | if ((0 == strcmp (finfo->d_name, ".")) || | ||
121 | (0 == strcmp (finfo->d_name, ".."))) | ||
122 | continue; | ||
123 | GNUNET_asprintf (&iter->next_name, "%s%s%s", iter->dirname, | ||
124 | DIR_SEPARATOR_STR, finfo->d_name); | ||
125 | break; | ||
126 | } | ||
127 | if (finfo == NULL) | ||
128 | { | ||
129 | GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); | ||
130 | return GNUNET_NO; | ||
131 | } | ||
132 | GNUNET_SCHEDULER_add_with_priority (iter->priority, &directory_iterator_task, | ||
133 | iter); | ||
134 | return GNUNET_YES; | ||
135 | } | ||
136 | |||
137 | |||
138 | /** | ||
139 | * Scan a directory for files using the scheduler to run a task for | ||
140 | * each entry. The name of the directory must be expanded first (!). | ||
141 | * If a scheduler does not need to be used, GNUNET_DISK_directory_scan | ||
142 | * may provide a simpler API. | ||
143 | * | ||
144 | * @param prio priority to use | ||
145 | * @param dir_name the name of the directory | ||
146 | * @param callback the method to call for each file | ||
147 | * @param callback_cls closure for @a callback | ||
148 | * @return #GNUNET_YES if directory is not empty and @a callback | ||
149 | * will be called later, #GNUNET_NO otherwise, #GNUNET_SYSERR on error. | ||
150 | */ | ||
151 | int | ||
152 | GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, | ||
153 | const char *dir_name, | ||
154 | GNUNET_DISK_DirectoryIteratorCallback | ||
155 | callback, void *callback_cls) | ||
156 | { | ||
157 | struct GNUNET_DISK_DirectoryIterator *di; | ||
158 | |||
159 | di = GNUNET_new (struct GNUNET_DISK_DirectoryIterator); | ||
160 | di->callback = callback; | ||
161 | di->callback_cls = callback_cls; | ||
162 | di->directory = OPENDIR (dir_name); | ||
163 | if (di->directory == NULL) | ||
164 | { | ||
165 | GNUNET_free (di); | ||
166 | callback (callback_cls, NULL, NULL, NULL); | ||
167 | return GNUNET_SYSERR; | ||
168 | } | ||
169 | di->dirname = GNUNET_strdup (dir_name); | ||
170 | di->priority = prio; | ||
171 | return GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); | ||
172 | } | ||
173 | |||
174 | /* 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 () | |||
130 | return 0; | 130 | return 0; |
131 | } | 131 | } |
132 | 132 | ||
133 | static void | ||
134 | iter_callback (void *cls, struct GNUNET_DISK_DirectoryIterator *di, | ||
135 | const char *filename, const char *dirname) | ||
136 | { | ||
137 | int *i = cls; | ||
138 | |||
139 | (*i)++; | ||
140 | GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); | ||
141 | } | ||
142 | |||
143 | static void | ||
144 | iter_task (void *cls) | ||
145 | { | ||
146 | GNUNET_DISK_directory_iterator_start (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
147 | "test", &iter_callback, cls); | ||
148 | } | ||
149 | |||
150 | 133 | ||
151 | static int | 134 | static int |
152 | testDirIter () | 135 | testDirIter () |
@@ -160,7 +143,6 @@ testDirIter () | |||
160 | return 1; | 143 | return 1; |
161 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_more")) | 144 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_more")) |
162 | return 1; | 145 | return 1; |
163 | GNUNET_SCHEDULER_run (&iter_task, &i); | ||
164 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) | 146 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) |
165 | return 1; | 147 | return 1; |
166 | if (i < 3) | 148 | if (i < 3) |
@@ -184,6 +166,7 @@ testCanonicalize () | |||
184 | return 0; | 166 | return 0; |
185 | } | 167 | } |
186 | 168 | ||
169 | |||
187 | static int | 170 | static int |
188 | testChangeOwner () | 171 | testChangeOwner () |
189 | { | 172 | { |
@@ -195,6 +178,7 @@ testChangeOwner () | |||
195 | return 0; | 178 | return 0; |
196 | } | 179 | } |
197 | 180 | ||
181 | |||
198 | static int | 182 | static int |
199 | testDirMani () | 183 | testDirMani () |
200 | { | 184 | { |
@@ -212,8 +196,6 @@ testDirMani () | |||
212 | return 1; | 196 | return 1; |
213 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) | 197 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) |
214 | return 1; | 198 | return 1; |
215 | |||
216 | |||
217 | return 0; | 199 | return 0; |
218 | } | 200 | } |
219 | 201 | ||