aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-unindex.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-unindex.c')
-rw-r--r--src/fs/gnunet-unindex.c137
1 files changed, 60 insertions, 77 deletions
diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c
index c1d1890db..a4aad4568 100644
--- a/src/fs/gnunet-unindex.c
+++ b/src/fs/gnunet-unindex.c
@@ -40,8 +40,7 @@ static struct GNUNET_FS_UnindexContext *uc;
40 40
41 41
42static void 42static void
43cleanup_task (void *cls, 43cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
44 const struct GNUNET_SCHEDULER_TaskContext *tc)
45{ 44{
46 GNUNET_FS_stop (ctx); 45 GNUNET_FS_stop (ctx);
47 ctx = NULL; 46 ctx = NULL;
@@ -49,17 +48,16 @@ cleanup_task (void *cls,
49 48
50 49
51static void 50static void
52shutdown_task (void *cls, 51shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
53 const struct GNUNET_SCHEDULER_TaskContext *tc)
54{ 52{
55 struct GNUNET_FS_UnindexContext *u; 53 struct GNUNET_FS_UnindexContext *u;
56 54
57 if (uc != NULL) 55 if (uc != NULL)
58 { 56 {
59 u = uc; 57 u = uc;
60 uc = NULL; 58 uc = NULL;
61 GNUNET_FS_unindex_stop (u); 59 GNUNET_FS_unindex_stop (u);
62 } 60 }
63} 61}
64 62
65/** 63/**
@@ -76,49 +74,44 @@ shutdown_task (void *cls,
76 * field in the GNUNET_FS_ProgressInfo struct. 74 * field in the GNUNET_FS_ProgressInfo struct.
77 */ 75 */
78static void * 76static void *
79progress_cb (void *cls, 77progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
80 const struct GNUNET_FS_ProgressInfo *info)
81{ 78{
82 char *s; 79 char *s;
83 80
84 switch (info->status) 81 switch (info->status)
82 {
83 case GNUNET_FS_STATUS_UNINDEX_START:
84 break;
85 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
86 if (verbose)
85 { 87 {
86 case GNUNET_FS_STATUS_UNINDEX_START: 88 s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta);
87 break;
88 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
89 if (verbose)
90 {
91 s = GNUNET_STRINGS_relative_time_to_string(info->value.unindex.eta);
92 fprintf (stdout,
93 _("Unindexing at %llu/%llu (%s remaining)\n"),
94 (unsigned long long) info->value.unindex.completed,
95 (unsigned long long) info->value.unindex.size,
96 s);
97 GNUNET_free (s);
98 }
99 break;
100 case GNUNET_FS_STATUS_UNINDEX_ERROR:
101 fprintf (stderr,
102 _("Error unindexing: %s.\n"),
103 info->value.unindex.specifics.error.message);
104 GNUNET_SCHEDULER_shutdown ();
105 break;
106 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
107 fprintf (stdout, 89 fprintf (stdout,
108 _("Unindexing done.\n")); 90 _("Unindexing at %llu/%llu (%s remaining)\n"),
109 GNUNET_SCHEDULER_shutdown (); 91 (unsigned long long) info->value.unindex.completed,
110 break; 92 (unsigned long long) info->value.unindex.size, s);
111 case GNUNET_FS_STATUS_UNINDEX_STOPPED: 93 GNUNET_free (s);
112 GNUNET_SCHEDULER_add_continuation (&cleanup_task,
113 NULL,
114 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
115 break;
116 default:
117 fprintf (stderr,
118 _("Unexpected status: %d\n"),
119 info->status);
120 break;
121 } 94 }
95 break;
96 case GNUNET_FS_STATUS_UNINDEX_ERROR:
97 fprintf (stderr,
98 _("Error unindexing: %s.\n"),
99 info->value.unindex.specifics.error.message);
100 GNUNET_SCHEDULER_shutdown ();
101 break;
102 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
103 fprintf (stdout, _("Unindexing done.\n"));
104 GNUNET_SCHEDULER_shutdown ();
105 break;
106 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
107 GNUNET_SCHEDULER_add_continuation (&cleanup_task,
108 NULL,
109 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
110 break;
111 default:
112 fprintf (stderr, _("Unexpected status: %d\n"), info->status);
113 break;
114 }
122 return NULL; 115 return NULL;
123} 116}
124 117
@@ -134,45 +127,35 @@ progress_cb (void *cls,
134static void 127static void
135run (void *cls, 128run (void *cls,
136 char *const *args, 129 char *const *args,
137 const char *cfgfile, 130 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
138 const struct GNUNET_CONFIGURATION_Handle *c)
139{ 131{
140 /* check arguments */ 132 /* check arguments */
141 if ( (args[0] == NULL) || (args[1] != NULL) ) 133 if ((args[0] == NULL) || (args[1] != NULL))
142 { 134 {
143 printf (_ 135 printf (_("You must specify one and only one filename for unindexing.\n"));
144 ("You must specify one and only one filename for unindexing.\n")); 136 ret = -1;
145 ret = -1; 137 return;
146 return; 138 }
147 }
148 cfg = c; 139 cfg = c;
149 ctx = GNUNET_FS_start (cfg, 140 ctx = GNUNET_FS_start (cfg,
150 "gnunet-unindex", 141 "gnunet-unindex",
151 &progress_cb, 142 &progress_cb,
152 NULL, 143 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
153 GNUNET_FS_FLAGS_NONE,
154 GNUNET_FS_OPTIONS_END);
155 if (NULL == ctx) 144 if (NULL == ctx)
156 { 145 {
157 fprintf (stderr, 146 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
158 _("Could not initialize `%s' subsystem.\n"), 147 ret = 1;
159 "FS"); 148 return;
160 ret = 1; 149 }
161 return; 150 uc = GNUNET_FS_unindex_start (ctx, args[0], NULL);
162 }
163 uc = GNUNET_FS_unindex_start (ctx,
164 args[0],
165 NULL);
166 if (NULL == uc) 151 if (NULL == uc)
167 { 152 {
168 fprintf (stderr, 153 fprintf (stderr, _("Could not start unindex operation.\n"));
169 _("Could not start unindex operation.\n")); 154 GNUNET_FS_stop (ctx);
170 GNUNET_FS_stop (ctx); 155 return;
171 return; 156 }
172 }
173 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 157 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
174 &shutdown_task, 158 &shutdown_task, NULL);
175 NULL);
176} 159}
177 160
178 161