[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r2229 - gnunet-gtk/src/plugins/fs
From: |
durner |
Subject: |
[GNUnet-SVN] r2229 - gnunet-gtk/src/plugins/fs |
Date: |
Wed, 2 Nov 2005 12:33:49 -0800 (PST) |
Author: durner
Date: 2005-11-02 12:33:43 -0800 (Wed, 02 Nov 2005)
New Revision: 2229
Modified:
gnunet-gtk/src/plugins/fs/download.c
Log:
fix download resumption (Mantis #944)
Modified: gnunet-gtk/src/plugins/fs/download.c
===================================================================
--- gnunet-gtk/src/plugins/fs/download.c 2005-11-02 08:10:03 UTC (rev
2228)
+++ gnunet-gtk/src/plugins/fs/download.c 2005-11-02 20:33:43 UTC (rev
2229)
@@ -325,7 +325,7 @@
FSUI_startDownload(ctx,
anon,
uri,
- lnk);
+ pfx);
FREE(lnk);
}
@@ -412,40 +412,42 @@
break;
pos = pos->next;
}
- if (pos == NULL)
- return;
- if ( (pos->rr != NULL) &&
- (gtk_tree_row_reference_valid(pos->rr)) ) {
-
- /* update directory view (if applicable!) */
- if (OK == getFileSize(filename, &size)) {
- fd = fileopen(filename, O_RDONLY);
- data = MMAP(NULL,
- size,
- PROT_READ,
- MAP_SHARED,
- fd,
- 0);
- meta = NULL;
- if (data != NULL) {
- ECRS_listDirectory(data,
- size,
- &meta,
- &addFilesToDirectory,
- (void*)uri);
- MUNMAP(data, size);
+
+ /* Not available for resumed downloads */
+ if (pos != NULL) {
+ if ( (pos->rr != NULL) &&
+ (gtk_tree_row_reference_valid(pos->rr)) ) {
+
+ /* update directory view (if applicable!) */
+ if (OK == getFileSize(filename, &size)) {
+ fd = fileopen(filename, O_RDONLY);
+ data = MMAP(NULL,
+ size,
+ PROT_READ,
+ MAP_SHARED,
+ fd,
+ 0);
+ meta = NULL;
+ if (data != NULL) {
+ ECRS_listDirectory(data,
+ size,
+ &meta,
+ &addFilesToDirectory,
+ (void*)uri);
+ MUNMAP(data, size);
+ }
+ CLOSE(fd);
+ if (meta != NULL)
+ ECRS_freeMetaData(meta);
}
- CLOSE(fd);
- if (meta != NULL)
- ECRS_freeMetaData(meta);
- }
-
- path = gtk_tree_row_reference_get_path(pos->rr);
- if (gtk_tree_path_get_depth(path) > 1) {
+
+ path = gtk_tree_row_reference_get_path(pos->rr);
+ if (gtk_tree_path_get_depth(path) > 1) {
+ gtk_tree_path_free(path);
+ return;
+ }
gtk_tree_path_free(path);
- return;
}
- gtk_tree_path_free(path);
}
/* only rename top-level files, not files inside of directories! */
@@ -463,6 +465,8 @@
-1);
if (ECRS_equalsUri(u, uri)) {
char *dstPath, *newFn, *dstFile;
+ char fnURL[PATH_MAX + 1], dummy[2];
+ ssizet_t len;
ren = ECRS_suggestFilename(ln);
newFn = strrchr(ren ? ren : ln, DIR_SEPARATOR) + 1;
@@ -493,27 +497,44 @@
strcpy(dstFile, dstPath);
strcat(dstFile, DIR_SEPARATOR_STR);
strcat(dstFile, newFn);
+
+ if ((len = readlink(ln ? ln : fn, fnURL, PATH_MAX)) == -1) {
+ LOG(LOG_ERROR, _("Could not open symlink `%s': %s\n"),
+ ln ? ln : fn, STRERROR(errno));
+
+ FREE(dstFile);
+ FREE(ren);
+
+ return;
+ }
+ fnURL[len] = 0;
+
+ /* If the file was downloaded before, fnURL is a symlink to
+ dstFile */
+ if ((readlink(fnURL, dummy, 1) == -1) && (errno == EINVAL)) {
+ if (RENAME(fnURL, dstFile) == -1) {
+ /* renaming failed, try to copy */
+ if (!copyFile(fnURL, dstFile)) {
+ LOG(LOG_ERROR, _("Could not move or copy downloaded file %s to
%s: %s."),
+ fnURL, dstFile, STRERROR(errno));
+ FREE(dstFile);
+ FREE(ren);
+
+ return;
+ }
+
+ if (REMOVE(fnURL) == -1)
+ LOG(LOG_ERROR, _("Could not remove temporary file %s: %s\n"),
fnURL, STRERROR(errno));
+ }
- if (RENAME(fn, dstFile) == -1) {
- /* renaming failed, try to copy */
- if (!copyFile(fn, dstFile)) {
- LOG(LOG_ERROR, _("Could not move or copy downloaded file %s to %s:
%s."),
- fn, dstFile, STRERROR(errno));
- FREE(dstFile);
- FREE(ren);
+ SYMLINK(dstFile, fnURL);
- return;
- }
+ }
- if (REMOVE(fn) == -1)
- LOG(LOG_ERROR, _("Could not remove temporary file %s: %s\n"), fn,
STRERROR(errno));
- }
-
if (ren)
REMOVE(ren);
else
REMOVE(ln);
- SYMLINK(dstFile, fn);
gtk_tree_store_set(summary,
&iter,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r2229 - gnunet-gtk/src/plugins/fs,
durner <=