aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fs/download.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/fs/download.c')
-rw-r--r--src/plugins/fs/download.c113
1 files changed, 67 insertions, 46 deletions
diff --git a/src/plugins/fs/download.c b/src/plugins/fs/download.c
index 2bb724d7..8bc32872 100644
--- a/src/plugins/fs/download.c
+++ b/src/plugins/fs/download.c
@@ -325,7 +325,7 @@ static void initiateDownload(GtkTreeModel * model,
325 FSUI_startDownload(ctx, 325 FSUI_startDownload(ctx,
326 anon, 326 anon,
327 uri, 327 uri,
328 lnk); 328 pfx);
329 FREE(lnk); 329 FREE(lnk);
330} 330}
331 331
@@ -412,40 +412,42 @@ void displayDownloadComplete(const struct ECRS_URI * uri,
412 break; 412 break;
413 pos = pos->next; 413 pos = pos->next;
414 } 414 }
415 if (pos == NULL) 415
416 return; 416 /* Not available for resumed downloads */
417 if ( (pos->rr != NULL) && 417 if (pos != NULL) {
418 (gtk_tree_row_reference_valid(pos->rr)) ) { 418 if ( (pos->rr != NULL) &&
419 419 (gtk_tree_row_reference_valid(pos->rr)) ) {
420 /* update directory view (if applicable!) */ 420
421 if (OK == getFileSize(filename, &size)) { 421 /* update directory view (if applicable!) */
422 fd = fileopen(filename, O_RDONLY); 422 if (OK == getFileSize(filename, &size)) {
423 data = MMAP(NULL, 423 fd = fileopen(filename, O_RDONLY);
424 size, 424 data = MMAP(NULL,
425 PROT_READ, 425 size,
426 MAP_SHARED, 426 PROT_READ,
427 fd, 427 MAP_SHARED,
428 0); 428 fd,
429 meta = NULL; 429 0);
430 if (data != NULL) { 430 meta = NULL;
431 ECRS_listDirectory(data, 431 if (data != NULL) {
432 size, 432 ECRS_listDirectory(data,
433 &meta, 433 size,
434 &addFilesToDirectory, 434 &meta,
435 (void*)uri); 435 &addFilesToDirectory,
436 MUNMAP(data, size); 436 (void*)uri);
437 MUNMAP(data, size);
438 }
439 CLOSE(fd);
440 if (meta != NULL)
441 ECRS_freeMetaData(meta);
442 }
443
444 path = gtk_tree_row_reference_get_path(pos->rr);
445 if (gtk_tree_path_get_depth(path) > 1) {
446 gtk_tree_path_free(path);
447 return;
437 } 448 }
438 CLOSE(fd);
439 if (meta != NULL)
440 ECRS_freeMetaData(meta);
441 }
442
443 path = gtk_tree_row_reference_get_path(pos->rr);
444 if (gtk_tree_path_get_depth(path) > 1) {
445 gtk_tree_path_free(path); 449 gtk_tree_path_free(path);
446 return;
447 } 450 }
448 gtk_tree_path_free(path);
449 } 451 }
450 452
451 /* only rename top-level files, not files inside of directories! */ 453 /* only rename top-level files, not files inside of directories! */
@@ -463,6 +465,8 @@ void displayDownloadComplete(const struct ECRS_URI * uri,
463 -1); 465 -1);
464 if (ECRS_equalsUri(u, uri)) { 466 if (ECRS_equalsUri(u, uri)) {
465 char *dstPath, *newFn, *dstFile; 467 char *dstPath, *newFn, *dstFile;
468 char fnURL[PATH_MAX + 1], dummy[2];
469 ssizet_t len;
466 470
467 ren = ECRS_suggestFilename(ln); 471 ren = ECRS_suggestFilename(ln);
468 newFn = strrchr(ren ? ren : ln, DIR_SEPARATOR) + 1; 472 newFn = strrchr(ren ? ren : ln, DIR_SEPARATOR) + 1;
@@ -493,27 +497,44 @@ void displayDownloadComplete(const struct ECRS_URI * uri,
493 strcpy(dstFile, dstPath); 497 strcpy(dstFile, dstPath);
494 strcat(dstFile, DIR_SEPARATOR_STR); 498 strcat(dstFile, DIR_SEPARATOR_STR);
495 strcat(dstFile, newFn); 499 strcat(dstFile, newFn);
496 500
497 if (RENAME(fn, dstFile) == -1) { 501 if ((len = readlink(ln ? ln : fn, fnURL, PATH_MAX)) == -1) {
498 /* renaming failed, try to copy */ 502 LOG(LOG_ERROR, _("Could not open symlink `%s': %s\n"),
499 if (!copyFile(fn, dstFile)) { 503 ln ? ln : fn, STRERROR(errno));
500 LOG(LOG_ERROR, _("Could not move or copy downloaded file %s to %s: %s."), 504
501 fn, dstFile, STRERROR(errno)); 505 FREE(dstFile);
502 FREE(dstFile); 506 FREE(ren);
503 FREE(ren); 507
504 508 return;
505 return; 509 }
510 fnURL[len] = 0;
511
512 /* If the file was downloaded before, fnURL is a symlink to
513 dstFile */
514 if ((readlink(fnURL, dummy, 1) == -1) && (errno == EINVAL)) {
515 if (RENAME(fnURL, dstFile) == -1) {
516 /* renaming failed, try to copy */
517 if (!copyFile(fnURL, dstFile)) {
518 LOG(LOG_ERROR, _("Could not move or copy downloaded file %s to %s: %s."),
519 fnURL, dstFile, STRERROR(errno));
520 FREE(dstFile);
521 FREE(ren);
522
523 return;
524 }
525
526 if (REMOVE(fnURL) == -1)
527 LOG(LOG_ERROR, _("Could not remove temporary file %s: %s\n"), fnURL, STRERROR(errno));
506 } 528 }
507 529
508 if (REMOVE(fn) == -1) 530 SYMLINK(dstFile, fnURL);
509 LOG(LOG_ERROR, _("Could not remove temporary file %s: %s\n"), fn, STRERROR(errno)); 531
510 } 532 }
511 533
512 if (ren) 534 if (ren)
513 REMOVE(ren); 535 REMOVE(ren);
514 else 536 else
515 REMOVE(ln); 537 REMOVE(ln);
516 SYMLINK(dstFile, fn);
517 538
518 gtk_tree_store_set(summary, 539 gtk_tree_store_set(summary,
519 &iter, 540 &iter,