diff options
Diffstat (limited to 'src/plugins/fs/download.c')
-rw-r--r-- | src/plugins/fs/download.c | 423 |
1 files changed, 132 insertions, 291 deletions
diff --git a/src/plugins/fs/download.c b/src/plugins/fs/download.c index dec11602..7d234b28 100644 --- a/src/plugins/fs/download.c +++ b/src/plugins/fs/download.c | |||
@@ -35,6 +35,7 @@ typedef struct DL { | |||
35 | struct DL * next; | 35 | struct DL * next; |
36 | struct ECRS_URI * uri; | 36 | struct ECRS_URI * uri; |
37 | char * filename; | 37 | char * filename; |
38 | char * finalName; | ||
38 | GtkTreeRowReference * rr; | 39 | GtkTreeRowReference * rr; |
39 | GtkTreeModel * model; | 40 | GtkTreeModel * model; |
40 | } DownloadList; | 41 | } DownloadList; |
@@ -111,24 +112,18 @@ static void initiateDownload(GtkTreeModel * model, | |||
111 | gpointer unused) { | 112 | gpointer unused) { |
112 | struct ECRS_URI * uri; | 113 | struct ECRS_URI * uri; |
113 | struct ECRS_MetaData * meta; | 114 | struct ECRS_MetaData * meta; |
114 | char * filename; | 115 | char * uri_name; |
115 | char * pfx; | 116 | char * final_download_destination; |
116 | char * lnk; | 117 | char * final_download_dir; |
117 | char * fn; | ||
118 | char * inc; | ||
119 | DownloadList * list; | 118 | DownloadList * list; |
120 | GtkTreeIter iiter; | 119 | GtkTreeIter iiter; |
121 | GtkWidget * spin; | 120 | GtkWidget * spin; |
122 | const char * name; | 121 | const char * name; |
123 | const char * mime; | 122 | const char * mime; |
124 | struct stat sbuf; | ||
125 | unsigned int anon; | 123 | unsigned int anon; |
126 | GtkTreePath *dirTreePath; | 124 | GtkTreePath *dirTreePath; |
127 | char *dirPath; | 125 | char *dirPath; |
128 | unsigned int dirPathLen; | 126 | unsigned int dirPathLen; |
129 | #ifdef WINDOWS | ||
130 | unsigned int downDirLen; | ||
131 | #endif | ||
132 | 127 | ||
133 | uri = NULL; | 128 | uri = NULL; |
134 | meta = NULL; | 129 | meta = NULL; |
@@ -145,14 +140,6 @@ static void initiateDownload(GtkTreeModel * model, | |||
145 | BREAK(); | 140 | BREAK(); |
146 | return; | 141 | return; |
147 | } | 142 | } |
148 | spin = getAnonymityButtonFromTM(model); | ||
149 | if (spin == NULL) { | ||
150 | BREAK(); | ||
151 | anon = 1; | ||
152 | } else { | ||
153 | anon = gtk_spin_button_get_value_as_int | ||
154 | (GTK_SPIN_BUTTON(spin)); | ||
155 | } | ||
156 | if (! ECRS_isFileUri(uri)) { | 143 | if (! ECRS_isFileUri(uri)) { |
157 | if (ECRS_isNamespaceUri(uri)) { | 144 | if (ECRS_isNamespaceUri(uri)) { |
158 | /* start namespace search; would probably be better | 145 | /* start namespace search; would probably be better |
@@ -172,130 +159,36 @@ static void initiateDownload(GtkTreeModel * model, | |||
172 | return; | 159 | return; |
173 | } | 160 | } |
174 | } | 161 | } |
175 | filename = ECRS_uriToString(uri); | 162 | |
176 | if ( (filename == NULL) || | 163 | |
177 | (strlen(filename) < | 164 | uri_name = ECRS_uriToString(uri); |
165 | if ( (uri_name == NULL) || | ||
166 | (strlen(uri_name) < | ||
178 | strlen(ECRS_URI_PREFIX) + | 167 | strlen(ECRS_URI_PREFIX) + |
179 | strlen(ECRS_FILE_INFIX)) ) { | 168 | strlen(ECRS_FILE_INFIX)) ) { |
180 | BREAK(); | 169 | BREAK(); |
181 | FREENONNULL(filename); | 170 | FREENONNULL(uri_name); |
182 | return; | 171 | return; |
183 | } | 172 | } |
184 | if (name == NULL) | ||
185 | name = filename; | ||
186 | |||
187 | fn = getFileName("FS", | ||
188 | "DOWNLOADDIR", | ||
189 | _("You must specify a directory in the configuration" | ||
190 | " in section `%s' under `%s'.")); | ||
191 | inc = getFileName("FS", | ||
192 | "INCOMINGDIR", | ||
193 | _("You must specify a directory in the configuration" | ||
194 | " in section `%s' under `%s'.")); | ||
195 | |||
196 | if (strcmp(fn, inc) == 0) { | ||
197 | LOG(LOG_ERROR, _("You must specify different directories in the " | ||
198 | "configuration in section `%s' under `%s' and `%s'."), | ||
199 | "FS", "DOWNLOADDIR", "INCOMINGDIR"); | ||
200 | |||
201 | FREE(filename); | ||
202 | FREENONNULL(fn); | ||
203 | FREENONNULL(inc); | ||
204 | |||
205 | return; | ||
206 | } | ||
207 | |||
208 | addLogEntry(_("Downloading `%s'"), name); | ||
209 | |||
210 | list = MALLOC(sizeof(DownloadList)); | ||
211 | list->next = head; | ||
212 | list->rr = NULL; | ||
213 | list->model = NULL; | ||
214 | if (YES == ECRS_isDirectory(meta)) { | ||
215 | list->rr = gtk_tree_row_reference_new(model, path); | ||
216 | list->model = model; | ||
217 | } | ||
218 | list->uri = ECRS_dupUri(uri); | ||
219 | |||
220 | #ifdef WINDOWS | ||
221 | downDirLen = strlen(fn); | ||
222 | #endif | ||
223 | mkdirp(fn); | ||
224 | pfx = MALLOC(strlen(fn) + 2 + | ||
225 | strlen(name) + 4); /* 4 = ".gnd" */ | ||
226 | lnk = MALLOC(strlen(fn) + 2 + | ||
227 | strlen(filename)); | ||
228 | strcpy(pfx, fn); | ||
229 | if (pfx[strlen(pfx)-1] != DIR_SEPARATOR) | ||
230 | strcat(pfx, | ||
231 | DIR_SEPARATOR_STR); | ||
232 | strcpy(lnk, fn); | ||
233 | FREE(fn); | ||
234 | if (lnk[strlen(lnk)-1] != DIR_SEPARATOR) | ||
235 | strcat(lnk, | ||
236 | DIR_SEPARATOR_STR); | ||
237 | strcat(pfx, | ||
238 | name); | ||
239 | strcat(lnk, | ||
240 | &filename[strlen(ECRS_URI_PREFIX) + | ||
241 | strlen(ECRS_FILE_INFIX)]); | ||
242 | |||
243 | /* Append ".gnd" if needed */ | ||
244 | if (mime && strcmp(mime, GNUNET_DIRECTORY_MIME) == 0) { | ||
245 | int len = strlen(pfx); | ||
246 | if (len > 4 && strcmp(pfx + len - 4, GNUNET_DIRECTORY_EXT) != 0) { | ||
247 | char *end = pfx + len - 1; | ||
248 | if (*end == '/' || *end == '\\') | ||
249 | *end = 0; | ||
250 | } | ||
251 | strcat(pfx, GNUNET_DIRECTORY_EXT); | ||
252 | } | ||
253 | |||
254 | #ifdef WINDOWS | ||
255 | { | ||
256 | /* Do not exceed MAX_PATH under Windows | ||
257 | The longest path we get is | ||
258 | $DOWNLOADDIR\hash.lnk | ||
259 | or | ||
260 | $INCOMINGDIR\hash.lnk | ||
261 | 173 | ||
262 | We truncate the hash here accordingly. */ | 174 | if (name == NULL) |
263 | 175 | name = uri_name; | |
264 | int diff; /* How much is INCOMINGDIR larger than DOWNLOADDIR */ | ||
265 | |||
266 | diff = downDirLen - strlen(inc); | ||
267 | if (diff < 0) | ||
268 | diff = 0; | ||
269 | |||
270 | char *end = lnk + MAX_PATH - 5 - diff; /* 4 = ".lnk" */ | ||
271 | |||
272 | *end = 0; | ||
273 | |||
274 | if (strchr(end + 1, DIR_SEPARATOR)) { | ||
275 | BREAK(); | ||
276 | return; | ||
277 | } | ||
278 | } | ||
279 | #endif | ||
280 | 176 | ||
281 | FREENONNULL(inc); | 177 | final_download_dir = getFileName("FS", |
178 | "INCOMINGDIR", | ||
179 | _("You must specify a directory in the configuration" | ||
180 | " in section `%s' under `%s'.")); | ||
181 | mkdirp(final_download_dir); | ||
282 | 182 | ||
283 | if (0 != STAT(pfx, | ||
284 | &sbuf)) { | ||
285 | if (0 != SYMLINK(lnk, pfx)) | ||
286 | LOG_FILE_STRERROR(LOG_ERROR, "symlink", pfx); | ||
287 | } else { | ||
288 | FREE(pfx); | ||
289 | pfx = STRDUP(lnk); | ||
290 | } | ||
291 | 183 | ||
292 | /* If file is inside a directory, get the full path */ | 184 | /* If file is inside a directory, get the full path */ |
293 | dirTreePath = gtk_tree_path_copy(path); | 185 | dirTreePath = gtk_tree_path_copy(path); |
294 | dirPath = MALLOC(1); | 186 | dirPath = MALLOC(1); |
187 | dirPath[0] = '\0'; | ||
295 | dirPathLen = 0; | 188 | dirPathLen = 0; |
296 | while (gtk_tree_path_get_depth(dirTreePath) > 1) { | 189 | while (gtk_tree_path_get_depth(dirTreePath) > 1) { |
297 | const char *dirname; | 190 | const char * dirname; |
298 | char *new; | 191 | char * new; |
299 | 192 | ||
300 | if (! gtk_tree_path_up(dirTreePath)) | 193 | if (! gtk_tree_path_up(dirTreePath)) |
301 | break; | 194 | break; |
@@ -308,17 +201,58 @@ static void initiateDownload(GtkTreeModel * model, | |||
308 | &iiter, | 201 | &iiter, |
309 | SEARCH_NAME, &dirname, | 202 | SEARCH_NAME, &dirname, |
310 | -1); | 203 | -1); |
311 | dirPathLen += strlen(dirname) + 1; | 204 | dirPathLen = strlen(dirPath) + strlen(dirname) + strlen(DIR_SEPARATOR_STR) + 1; |
312 | new = MALLOC(dirPathLen + 1); | 205 | new = MALLOC(dirPathLen + 1); |
313 | strcpy(new, dirname); | 206 | strcpy(new, dirname); |
314 | strcat(new, DIR_SEPARATOR_STR); | 207 | if (new[strlen(new)-1] != DIR_SEPARATOR) |
208 | strcat(new, DIR_SEPARATOR_STR); | ||
315 | strcat(new, dirPath); | 209 | strcat(new, dirPath); |
316 | FREE(dirPath); | 210 | FREE(dirPath); |
317 | dirPath = new; | 211 | dirPath = new; |
318 | } | 212 | } |
319 | gtk_tree_path_free(dirTreePath); | 213 | gtk_tree_path_free(dirTreePath); |
320 | 214 | ||
321 | list->filename = pfx; | 215 | |
216 | /* construct completed/directory/real-filename */ | ||
217 | final_download_destination = MALLOC(strlen(final_download_dir) + 2 + | ||
218 | strlen(name) + strlen(GNUNET_DIRECTORY_EXT) + | ||
219 | strlen(dirPath)); | ||
220 | strcpy(final_download_destination, final_download_dir); | ||
221 | if (final_download_destination[strlen(final_download_destination)-1] != DIR_SEPARATOR) | ||
222 | strcat(final_download_destination, | ||
223 | DIR_SEPARATOR_STR); | ||
224 | strcat(final_download_destination, dirPath); | ||
225 | mkdirp(final_download_destination); | ||
226 | strcat(final_download_destination, name); | ||
227 | if ( (final_download_destination[strlen(final_download_destination) - 1] == '/') || | ||
228 | (final_download_destination[strlen(final_download_destination) - 1] == '\\') ) | ||
229 | final_download_destination[strlen(final_download_destination) - 1] = '\0'; | ||
230 | /* append ".gnd" if needed (== directory and .gnd not present) */ | ||
231 | if ( (mime != NULL) && | ||
232 | (0 == strcmp(mime, GNUNET_DIRECTORY_MIME)) && | ||
233 | ( (strlen(final_download_destination) < strlen(GNUNET_DIRECTORY_EXT)) || | ||
234 | (0 != strcmp(&final_download_destination[strlen(final_download_destination) - strlen(GNUNET_DIRECTORY_EXT)], | ||
235 | GNUNET_DIRECTORY_EXT)) ) ) | ||
236 | strcat(final_download_destination, GNUNET_DIRECTORY_EXT); | ||
237 | |||
238 | /* setup visualization */ | ||
239 | list = MALLOC(sizeof(DownloadList)); | ||
240 | list->next = head; | ||
241 | list->rr = NULL; | ||
242 | list->model = NULL; | ||
243 | if (YES == ECRS_isDirectory(meta)) { | ||
244 | list->rr = gtk_tree_row_reference_new(model, path); | ||
245 | list->model = model; | ||
246 | } | ||
247 | list->uri = ECRS_dupUri(uri); | ||
248 | list->filename = final_download_destination; | ||
249 | list->finalName = MALLOC(strlen(final_download_dir) + strlen(dirPath) + strlen(name) + 2); | ||
250 | strcpy(list->finalName, final_download_dir); | ||
251 | if (final_download_dir[strlen(final_download_dir)-1] != DIR_SEPARATOR) | ||
252 | strcat(list->finalName, DIR_SEPARATOR_STR); | ||
253 | strcat(list->finalName, dirPath); | ||
254 | mkdirp(list->finalName); | ||
255 | strcat(list->finalName, name); | ||
322 | head = list; | 256 | head = list; |
323 | gtk_tree_store_insert(summary, | 257 | gtk_tree_store_insert(summary, |
324 | &iiter, | 258 | &iiter, |
@@ -326,23 +260,34 @@ static void initiateDownload(GtkTreeModel * model, | |||
326 | 0); | 260 | 0); |
327 | gtk_tree_store_set(summary, | 261 | gtk_tree_store_set(summary, |
328 | &iiter, | 262 | &iiter, |
329 | DOWNLOAD_FILENAME, lnk, | 263 | DOWNLOAD_FILENAME, final_download_destination, |
330 | DOWNLOAD_LINKNAME, pfx, | 264 | DOWNLOAD_SHORTNAME, name, |
331 | DOWNLOAD_SIZE, ECRS_fileSize(uri), | 265 | DOWNLOAD_SIZE, ECRS_fileSize(uri), |
332 | DOWNLOAD_PROGRESS, 0, /* progress */ | 266 | DOWNLOAD_PROGRESS, 0, /* progress */ |
333 | DOWNLOAD_URISTRING, filename, | 267 | DOWNLOAD_URISTRING, uri_name, |
334 | DOWNLOAD_URI, ECRS_dupUri(uri), | 268 | DOWNLOAD_URI, ECRS_dupUri(uri), |
335 | DOWNLOAD_TREEPATH, list->rr, | 269 | DOWNLOAD_TREEPATH, list->rr, /* internal: row reference! */ |
336 | DOWNLOAD_DIRPATH, dirPath, | 270 | DOWNLOAD_DIRPATH, dirPath, |
337 | /* internal: row reference! */ | ||
338 | -1); | 271 | -1); |
339 | FREE(filename); | 272 | FREE(uri_name); |
273 | FREE(dirPath); | ||
274 | FREENONNULL(final_download_dir); | ||
340 | 275 | ||
276 | |||
277 | spin = getAnonymityButtonFromTM(model); | ||
278 | if (spin == NULL) { | ||
279 | BREAK(); | ||
280 | anon = 1; | ||
281 | } else { | ||
282 | anon = gtk_spin_button_get_value_as_int | ||
283 | (GTK_SPIN_BUTTON(spin)); | ||
284 | } | ||
285 | |||
286 | addLogEntry(_("Downloading `%s'"), name); | ||
341 | FSUI_startDownload(ctx, | 287 | FSUI_startDownload(ctx, |
342 | anon, | 288 | anon, |
343 | uri, | 289 | uri, |
344 | pfx); | 290 | final_download_destination); |
345 | FREE(lnk); | ||
346 | } | 291 | } |
347 | 292 | ||
348 | void on_downloadButton_clicked(GtkWidget * treeview, | 293 | void on_downloadButton_clicked(GtkWidget * treeview, |
@@ -408,19 +353,15 @@ void displayDownloadUpdate(const struct ECRS_URI * uri, | |||
408 | */ | 353 | */ |
409 | void displayDownloadComplete(const struct ECRS_URI * uri, | 354 | void displayDownloadComplete(const struct ECRS_URI * uri, |
410 | const char * filename) { | 355 | const char * filename) { |
411 | char * ren; | ||
412 | const char * fn; | ||
413 | const char * ln; | ||
414 | unsigned long long size; | 356 | unsigned long long size; |
415 | char * data; | 357 | char * data; |
416 | int fd; | 358 | int fd; |
417 | struct ECRS_MetaData * meta; | 359 | struct ECRS_MetaData * meta; |
418 | DownloadList * pos; | 360 | DownloadList * pos; |
419 | GtkTreeIter iter; | ||
420 | GtkTreePath * path; | ||
421 | struct ECRS_URI * u; | ||
422 | char *dirPath; | ||
423 | 361 | ||
362 | LOG(LOG_DEBUG, | ||
363 | "Download '%s' complete\n", | ||
364 | filename); | ||
424 | pos = head; | 365 | pos = head; |
425 | while (pos != NULL) { | 366 | while (pos != NULL) { |
426 | if (ECRS_equalsUri(uri, | 367 | if (ECRS_equalsUri(uri, |
@@ -432,148 +373,43 @@ void displayDownloadComplete(const struct ECRS_URI * uri, | |||
432 | /* Not available for resumed downloads */ | 373 | /* Not available for resumed downloads */ |
433 | if (pos != NULL) { | 374 | if (pos != NULL) { |
434 | if ( (pos->rr != NULL) && | 375 | if ( (pos->rr != NULL) && |
435 | (gtk_tree_row_reference_valid(pos->rr)) ) { | 376 | (gtk_tree_row_reference_valid(pos->rr)) ) { |
436 | |||
437 | /* update directory view (if applicable!) */ | 377 | /* update directory view (if applicable!) */ |
438 | if (OK == getFileSize(filename, &size)) { | 378 | if (OK == getFileSize(filename, &size)) { |
439 | fd = fileopen(filename, O_RDONLY); | 379 | LOG(LOG_DEBUG, |
440 | data = MMAP(NULL, | 380 | "Updating directory view of '%s'\n", |
441 | size, | 381 | filename); |
442 | PROT_READ, | 382 | |
443 | MAP_SHARED, | 383 | meta = NULL; |
444 | fd, | 384 | fd = fileopen(filename, O_RDONLY); |
445 | 0); | 385 | if (fd == -1) { |
446 | meta = NULL; | 386 | LOG_FILE_STRERROR(LOG_ERROR, "open", filename); |
447 | if (data != NULL) { | 387 | } else { |
448 | ECRS_listDirectory(data, | 388 | data = MMAP(NULL, |
449 | size, | 389 | size, |
450 | &meta, | 390 | PROT_READ, |
451 | &addFilesToDirectory, | 391 | MAP_SHARED, |
452 | (void*)uri); | 392 | fd, |
453 | MUNMAP(data, size); | 393 | 0); |
454 | } | 394 | if (data == MAP_FAILED) { |
455 | CLOSE(fd); | 395 | LOG_FILE_STRERROR(LOG_ERROR, "mmap", filename); |
456 | if (meta != NULL) | 396 | } else { |
457 | ECRS_freeMetaData(meta); | 397 | if (data != NULL) { |
398 | ECRS_listDirectory(data, | ||
399 | size, | ||
400 | &meta, | ||
401 | &addFilesToDirectory, | ||
402 | (void*)uri); | ||
403 | MUNMAP(data, size); | ||
404 | } | ||
405 | } | ||
406 | CLOSE(fd); | ||
407 | } | ||
408 | if (meta != NULL) | ||
409 | ECRS_freeMetaData(meta); | ||
458 | } | 410 | } |
459 | |||
460 | path = gtk_tree_row_reference_get_path(pos->rr); | ||
461 | if (gtk_tree_path_get_depth(path) > 1) { | ||
462 | gtk_tree_path_free(path); | ||
463 | return; | ||
464 | } | ||
465 | gtk_tree_path_free(path); | ||
466 | } | 411 | } |
467 | } | 412 | } |
468 | |||
469 | /* only rename top-level files, not files inside of directories! */ | ||
470 | if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary), | ||
471 | &iter)) { | ||
472 | do { | ||
473 | ln = NULL; | ||
474 | fn = NULL; | ||
475 | gtk_tree_model_get(GTK_TREE_MODEL(summary), | ||
476 | &iter, | ||
477 | DOWNLOAD_URI, &u, | ||
478 | DOWNLOAD_FILENAME, &fn, | ||
479 | DOWNLOAD_LINKNAME, &ln, | ||
480 | DOWNLOAD_DIRPATH, &dirPath, | ||
481 | -1); | ||
482 | if (ECRS_equalsUri(u, uri)) { | ||
483 | char *dstPath, *newFn, *dstFile; | ||
484 | char fnURL[PATH_MAX + 1], dummy[2]; | ||
485 | size_t len; | ||
486 | |||
487 | len = strlen(ln); | ||
488 | /* Don't change the name of GNUnet directories (.gnd) */ | ||
489 | if (len >= 4 && strcmp(ln + len - 4, ".gnd") != 0) | ||
490 | ren = ECRS_suggestFilename(fn); | ||
491 | else | ||
492 | ren = NULL; | ||
493 | |||
494 | newFn = strrchr(ren ? ren : ln, DIR_SEPARATOR) + 1; | ||
495 | |||
496 | dstPath = getFileName("FS", | ||
497 | "INCOMINGDIR", | ||
498 | _("You must specify a directory in the configuration" | ||
499 | " in section `%s' under `%s'.")); | ||
500 | if (!dstPath) { | ||
501 | FREENONNULL(ren); | ||
502 | return; | ||
503 | } | ||
504 | |||
505 | /* If file is contained in a directory, create directory structure in | ||
506 | the file system. */ | ||
507 | if (dirPath) { | ||
508 | unsigned int pathLen = strlen(dirPath); | ||
509 | if (pathLen) { | ||
510 | pathLen += strlen(dstPath) + 2; | ||
511 | dstPath = REALLOC(dstPath, pathLen); | ||
512 | strcat(dstPath, DIR_SEPARATOR_STR); | ||
513 | strcat(dstPath, dirPath); | ||
514 | FREE(dirPath); | ||
515 | } | ||
516 | } | ||
517 | |||
518 | mkdirp(dstPath); | ||
519 | |||
520 | dstFile = MALLOC(strlen(dstPath) + strlen(newFn) + 2); | ||
521 | strcpy(dstFile, dstPath); | ||
522 | strcat(dstFile, DIR_SEPARATOR_STR); | ||
523 | strcat(dstFile, newFn); | ||
524 | |||
525 | if ((len = READLINK(ln ? ln : fn, fnURL, PATH_MAX)) == -1) { | ||
526 | LOG(LOG_ERROR, _("Could not open symlink `%s': %s\n"), | ||
527 | ln ? ln : fn, STRERROR(errno)); | ||
528 | |||
529 | FREE(dstFile); | ||
530 | FREENONNULL(ren); | ||
531 | |||
532 | return; | ||
533 | } | ||
534 | fnURL[len] = 0; | ||
535 | |||
536 | /* If the file was downloaded before, fnURL is a symlink to | ||
537 | dstFile */ | ||
538 | if ((READLINK(fnURL, dummy, 1) == -1) && (errno == EINVAL)) { | ||
539 | if (RENAME(fnURL, dstFile) == -1) { | ||
540 | /* renaming failed, try to copy */ | ||
541 | if (!copyFile(fnURL, dstFile)) { | ||
542 | LOG(LOG_ERROR, _("Could not move or copy downloaded file %s to %s: %s."), | ||
543 | fnURL, dstFile, STRERROR(errno)); | ||
544 | FREE(dstFile); | ||
545 | FREENONNULL(ren); | ||
546 | |||
547 | return; | ||
548 | } | ||
549 | |||
550 | if (REMOVE(fnURL) == -1) | ||
551 | LOG(LOG_ERROR, _("Could not remove temporary file %s: %s\n"), fnURL, STRERROR(errno)); | ||
552 | } | ||
553 | |||
554 | SYMLINK(dstFile, fnURL); | ||
555 | |||
556 | } | ||
557 | |||
558 | if (ren) | ||
559 | REMOVE(ren); | ||
560 | else | ||
561 | REMOVE(ln); | ||
562 | |||
563 | gtk_tree_store_set(summary, | ||
564 | &iter, | ||
565 | DOWNLOAD_LINKNAME, dstFile, | ||
566 | -1); | ||
567 | FREENONNULL(ren); | ||
568 | FREE(dstFile); | ||
569 | FREE(dstPath); | ||
570 | |||
571 | break; | ||
572 | } | ||
573 | } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(summary), | ||
574 | &iter)); | ||
575 | } | ||
576 | |||
577 | } | 413 | } |
578 | 414 | ||
579 | static int delDownloadView(void * cls, | 415 | static int delDownloadView(void * cls, |
@@ -585,7 +421,8 @@ static int delDownloadView(void * cls, | |||
585 | int isRecursive, | 421 | int isRecursive, |
586 | unsigned int anonymityLevel) { | 422 | unsigned int anonymityLevel) { |
587 | GtkTreeIter iter; | 423 | GtkTreeIter iter; |
588 | char * f, * f2, * fn; | 424 | char * f; |
425 | char * fn; | ||
589 | struct ECRS_URI * u; | 426 | struct ECRS_URI * u; |
590 | 427 | ||
591 | if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary), | 428 | if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary), |
@@ -594,16 +431,14 @@ static int delDownloadView(void * cls, | |||
594 | gtk_tree_model_get(GTK_TREE_MODEL(summary), | 431 | gtk_tree_model_get(GTK_TREE_MODEL(summary), |
595 | &iter, | 432 | &iter, |
596 | DOWNLOAD_FILENAME, &f, | 433 | DOWNLOAD_FILENAME, &f, |
597 | DOWNLOAD_LINKNAME, &f2, | ||
598 | DOWNLOAD_URI, &u, | 434 | DOWNLOAD_URI, &u, |
599 | -1); | 435 | -1); |
600 | 436 | ||
601 | f = strrchr(f, DIR_SEPARATOR); | 437 | f = strrchr(f, DIR_SEPARATOR); |
602 | f2 = strrchr(f2, DIR_SEPARATOR); | ||
603 | fn = strrchr(filename, DIR_SEPARATOR); | 438 | fn = strrchr(filename, DIR_SEPARATOR); |
604 | 439 | ||
605 | if ( (ECRS_equalsUri(u, uri)) && | 440 | if ( (ECRS_equalsUri(u, uri)) && |
606 | (0 == strcmp(f, fn) || 0 == strcmp(f2, fn)) ) { | 441 | (0 == strcmp(f, fn)) ) { |
607 | gtk_tree_store_remove(summary, | 442 | gtk_tree_store_remove(summary, |
608 | &iter); | 443 | &iter); |
609 | break; | 444 | break; |
@@ -679,6 +514,7 @@ static int addDownloadView(void * cls, | |||
679 | GtkTreeIter iiter; | 514 | GtkTreeIter iiter; |
680 | int progress; | 515 | int progress; |
681 | char * uriname; | 516 | char * uriname; |
517 | const char * sname; | ||
682 | 518 | ||
683 | if (filesize != 0) | 519 | if (filesize != 0) |
684 | progress = bytesCompleted * 100 / filesize; | 520 | progress = bytesCompleted * 100 / filesize; |
@@ -689,10 +525,15 @@ static int addDownloadView(void * cls, | |||
689 | &iiter, | 525 | &iiter, |
690 | NULL, | 526 | NULL, |
691 | 0); | 527 | 0); |
528 | sname = filename[strlen(filename)-1]; | ||
529 | while ( (sname > filename) && | ||
530 | (sname[-1] != '/') && | ||
531 | (sname[-1] != '\\') ) | ||
532 | sname--; | ||
692 | gtk_tree_store_set(summary, | 533 | gtk_tree_store_set(summary, |
693 | &iiter, | 534 | &iiter, |
694 | DOWNLOAD_FILENAME, filename, | 535 | DOWNLOAD_FILENAME, filename, |
695 | DOWNLOAD_LINKNAME, filename, | 536 | DOWNLOAD_SHORTNAME, sname, |
696 | DOWNLOAD_SIZE, filesize, | 537 | DOWNLOAD_SIZE, filesize, |
697 | DOWNLOAD_PROGRESS, progress, | 538 | DOWNLOAD_PROGRESS, progress, |
698 | DOWNLOAD_URISTRING, uriname, | 539 | DOWNLOAD_URISTRING, uriname, |
@@ -714,14 +555,14 @@ void fs_download_start() { | |||
714 | "activeDownloadsList"); | 555 | "activeDownloadsList"); |
715 | summary = | 556 | summary = |
716 | gtk_tree_store_new(DOWNLOAD_NUM, | 557 | gtk_tree_store_new(DOWNLOAD_NUM, |
717 | G_TYPE_STRING, /* name (URI as string) */ | 558 | G_TYPE_STRING, /* name (full-path file name) */ |
718 | G_TYPE_STRING, /* name (user-friendly name) */ | 559 | G_TYPE_STRING, /* name (user-friendly name) */ |
719 | G_TYPE_UINT64, /* size */ | 560 | G_TYPE_UINT64, /* size */ |
720 | G_TYPE_INT, /* progress */ | 561 | G_TYPE_INT, /* progress */ |
721 | G_TYPE_STRING, /* uri */ | 562 | G_TYPE_STRING, /* uri */ |
722 | G_TYPE_POINTER, /* url */ | 563 | G_TYPE_POINTER, /* url */ |
723 | G_TYPE_POINTER, /* internal: gtk tree path / NULL */ | 564 | G_TYPE_POINTER, /* internal: gtk tree path / NULL */ |
724 | G_TYPE_POINTER); /* directory path if file is inside a dir */ | 565 | G_TYPE_STRING); /* directory path if file is inside a dir */ |
725 | gtk_tree_view_set_model(GTK_TREE_VIEW(downloadList), | 566 | gtk_tree_view_set_model(GTK_TREE_VIEW(downloadList), |
726 | GTK_TREE_MODEL(summary)); | 567 | GTK_TREE_MODEL(summary)); |
727 | renderer = gtk_cell_renderer_progress_new(); | 568 | renderer = gtk_cell_renderer_progress_new(); |
@@ -730,7 +571,7 @@ void fs_download_start() { | |||
730 | _("Name"), | 571 | _("Name"), |
731 | renderer, | 572 | renderer, |
732 | "value", DOWNLOAD_PROGRESS, | 573 | "value", DOWNLOAD_PROGRESS, |
733 | "text", DOWNLOAD_LINKNAME, | 574 | "text", DOWNLOAD_SHORTNAME, |
734 | NULL); | 575 | NULL); |
735 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(downloadList), | 576 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(downloadList), |
736 | col - 1), | 577 | col - 1), |