[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r1732 - GNUnet/src/applications/fs/ecrs GNUnet/src/applicat
From: |
grothoff |
Subject: |
[GNUnet-SVN] r1732 - GNUnet/src/applications/fs/ecrs GNUnet/src/applications/fs/fsui gnunet-gtk/src/common gnunet-gtk/src/plugins/fs gnunet-gtk/src/plugins/stats |
Date: |
Wed, 17 Aug 2005 23:26:34 -0700 (PDT) |
Author: grothoff
Date: 2005-08-17 23:26:31 -0700 (Wed, 17 Aug 2005)
New Revision: 1732
Modified:
GNUnet/src/applications/fs/ecrs/meta.c
GNUnet/src/applications/fs/fsui/download.c
gnunet-gtk/src/common/helper.c
gnunet-gtk/src/plugins/fs/download.c
gnunet-gtk/src/plugins/fs/fs.c
gnunet-gtk/src/plugins/fs/fs.h
gnunet-gtk/src/plugins/fs/meta.c
gnunet-gtk/src/plugins/fs/search.c
gnunet-gtk/src/plugins/stats/functions.c
Log:
various bugfixes, including mantis 867
Modified: GNUnet/src/applications/fs/ecrs/meta.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/meta.c 2005-08-18 04:33:52 UTC (rev
1731)
+++ GNUnet/src/applications/fs/ecrs/meta.c 2005-08-18 06:26:31 UTC (rev
1732)
@@ -710,16 +710,26 @@
/**
* Suggest a better filename for a file (and do the
* renaming).
+ * @return the new filename
*/
char * ECRS_suggestFilename(const char * filename) {
EXTRACTOR_ExtractorList * l;
EXTRACTOR_KeywordList * list;
const char * key;
const char * mime;
+ char * path;
int i;
+ unsigned int j;
char * renameTo;
char * ret;
+ struct stat filestat;
+ path = STRDUP(filename);
+ i = strlen(path);
+ while ( (i > 0) &&
+ (path[i] != DIR_SEPARATOR) )
+ i--;
+ path[i] = '\0';
ret = NULL;
l = EXTRACTOR_loadDefaultLibraries();
list = EXTRACTOR_getKeywords(l, filename);
@@ -761,31 +771,64 @@
mime = NULL;
}
if (mime == NULL) {
- renameTo = STRDUP(key);
+ i = strlen(filename);
+ while ( (i>0) &&
+ (filename[i] != '.') &&
+ (filename[i] != DIR_SEPARATOR) )
+ i--;
+ if (filename[i] == '.')
+ mime = STRDUP(&filename[i]);
+ }
+ if (mime == NULL) {
+ renameTo = MALLOC(strlen(path) + strlen(key) + strlen(DIR_SEPARATOR_STR) +
20);
+ strcpy(renameTo, path);
+ if (path[strlen(path)-1] != DIR_SEPARATOR)
+ strcat(renameTo, DIR_SEPARATOR_STR);
+ strcat(renameTo, key);
} else {
- renameTo = MALLOC(strlen(key) + strlen(mime) + 1);
- strcpy(renameTo, key);
+ renameTo = MALLOC(strlen(path) + strlen(key) + strlen(mime) +
strlen(DIR_SEPARATOR_STR) + 20);
+ strcpy(renameTo, path);
+ if (path[strlen(path)-1] != DIR_SEPARATOR)
+ strcat(renameTo, DIR_SEPARATOR_STR);
+ strcat(renameTo, key);
strcat(renameTo, mime);
}
for (i=strlen(renameTo)-1;i>=0;i--)
if (! isprint(renameTo[i]))
renameTo[i] = '_';
+ if (0 == STAT(renameTo,
+ &filestat)) {
+ i = strlen(renameTo);
+ j = 0;
+ do {
+ SNPRINTF(&renameTo[i],
+ 19,
+ ".%u",
+ j++);
+ if (j > 100000)
+ break;
+ } while (0 == STAT(renameTo,
+ &filestat));
+ }
if (0 != strcmp(renameTo, filename)) {
- struct stat filestat;
if (0 != STAT(renameTo,
&filestat)) {
if (0 != RENAME(filename, renameTo))
LOG(LOG_ERROR,
_("Renaming of file '%s' to '%s' failed: %s\n"),
- filename, renameTo, STRERROR(errno));
+ filename,
+ renameTo,
+ STRERROR(errno));
else
ret = STRDUP(renameTo);
} else {
LOG(LOG_ERROR,
_("Could not rename file '%s' to '%s': file exists\n"),
- filename, renameTo);
+ filename,
+ renameTo);
}
}
+ FREE(path);
FREE(renameTo);
EXTRACTOR_freeKeywords(list);
EXTRACTOR_removeAll(l);
Modified: GNUnet/src/applications/fs/fsui/download.c
===================================================================
--- GNUnet/src/applications/fs/fsui/download.c 2005-08-18 04:33:52 UTC (rev
1731)
+++ GNUnet/src/applications/fs/fsui/download.c 2005-08-18 06:26:31 UTC (rev
1732)
@@ -455,7 +455,7 @@
} else {
dpos = dpos->child;
while ( (dpos != NULL) &&
- (dpos != list) )
+ (dpos->next != list) )
dpos = dpos->next;
GNUNET_ASSERT(dpos != NULL);
dpos->next = list->next;
Modified: gnunet-gtk/src/common/helper.c
===================================================================
--- gnunet-gtk/src/common/helper.c 2005-08-18 04:33:52 UTC (rev 1731)
+++ gnunet-gtk/src/common/helper.c 2005-08-18 06:26:31 UTC (rev 1732)
@@ -416,7 +416,7 @@
Plugin * next;
next = plugin->next;
- unloadPlugin(plugin);
+ unloadPlugin(plugin);
plugin = next;
}
@@ -434,7 +434,7 @@
for (i=0;i<pscCount;i++)
psc[i]->func(psc[i]);
i = pscCount;
- MUTEX_UNLOCK(&sclock);
+ MUTEX_UNLOCK(&sclock);
/* wait until all PSC-jobs have left
the gtkSaveCall method before destroying
the mutex! */
Modified: gnunet-gtk/src/plugins/fs/download.c
===================================================================
--- gnunet-gtk/src/plugins/fs/download.c 2005-08-18 04:33:52 UTC (rev
1731)
+++ gnunet-gtk/src/plugins/fs/download.c 2005-08-18 06:26:31 UTC (rev
1732)
@@ -71,6 +71,7 @@
gtk_tree_model_get_iter(GTK_TREE_MODEL(pos->model),
&iter,
path);
+ gtk_tree_path_free(path);
for (i=gtk_tree_model_iter_n_children(pos->model,
&iter)-1;i>=0;i--) {
if (TRUE == gtk_tree_model_iter_nth_child(pos->model,
@@ -108,11 +109,12 @@
struct ECRS_MetaData * meta;
char * filename;
char * pfx;
+ char * lnk;
char * fn;
DownloadList * list;
GtkTreeIter iiter;
GtkWidget * spin;
- char * name;
+ const char * name;
struct stat sbuf;
unsigned int anon;
@@ -127,7 +129,6 @@
-1);
if (uri == NULL) {
BREAK();
- FREENONNULL(name);
return;
}
filename = ECRS_uriToString(uri);
@@ -136,17 +137,16 @@
strlen(ECRS_URI_PREFIX) +
strlen(ECRS_FILE_INFIX)) ) {
BREAK();
- FREENONNULL(name);
FREENONNULL(filename);
return;
}
if (name == NULL)
- name = STRDUP(_("unnamed"));
+ name = filename;
list = MALLOC(sizeof(DownloadList));
list->next = head;
list->rr = NULL;
list->model = NULL;
- if (ECRS_isDirectory(meta)) {
+ if (YES == ECRS_isDirectory(meta)) {
list->rr = gtk_tree_row_reference_new(model, path);
list->model = model;
}
@@ -157,53 +157,41 @@
" in section '%s' under '%s'."));
mkdirp(fn);
pfx = MALLOC(strlen(fn) + 2 +
- strlen(filename) + strlen(name));
+ strlen(name));
+ lnk = MALLOC(strlen(fn) + 2 +
+ strlen(filename));
strcpy(pfx, fn);
+ if (pfx[strlen(pfx)-1] != DIR_SEPARATOR)
+ strcat(pfx,
+ DIR_SEPARATOR_STR);
+ strcpy(lnk, fn);
+ FREE(fn);
+ if (lnk[strlen(lnk)-1] != DIR_SEPARATOR)
+ strcat(lnk,
+ DIR_SEPARATOR_STR);
strcat(pfx,
- DIR_SEPARATOR_STR);
- strcat(pfx,
name);
- while ( (strlen(pfx) > 0) &&
- (pfx[strlen(pfx)-1] == DIR_SEPARATOR) )
- pfx[strlen(pfx)-1] = '\0';
- if (0 == STAT(pfx,
+ strcat(lnk,
+ &filename[strlen(ECRS_URI_PREFIX) +
+ strlen(ECRS_FILE_INFIX)]);
+ if (0 != STAT(pfx,
&sbuf)) {
- GtkWidget * dialog;
-
- dialog = gtk_message_dialog_new
- (NULL,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_CLOSE,
- _("File '%s' exists in '%s',\n"
- "will store download under its"
- " GNUnet URI '%s' instead.\n"),
- name,
- fn,
- &filename[strlen(ECRS_URI_PREFIX) +
- strlen(ECRS_FILE_INFIX)]);
- gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
- strcpy(pfx, fn);
- strcat(pfx,
- DIR_SEPARATOR_STR);
- strcat(pfx,
- &filename[strlen(ECRS_URI_PREFIX) +
- strlen(ECRS_FILE_INFIX)]);
+ if (0 != SYMLINK(lnk, pfx))
+ LOG_FILE_STRERROR(LOG_ERROR, "symlink", pfx);
+ } else {
+ FREE(pfx);
+ pfx = STRDUP(lnk);
}
- FREE(fn);
-
-
list->filename = pfx;
head = list;
-
gtk_tree_store_insert(summary,
&iiter,
NULL,
0);
gtk_tree_store_set(summary,
&iiter,
- DOWNLOAD_FILENAME, name,
+ DOWNLOAD_FILENAME, lnk,
+ DOWNLOAD_LINKNAME, pfx,
DOWNLOAD_SIZE, ECRS_fileSize(uri),
DOWNLOAD_PROGRESS, 0, /* progress */
DOWNLOAD_URISTRING, filename,
@@ -212,7 +200,6 @@
/* internal: row reference! */
-1);
FREE(filename);
- FREE(name);
spin = getAnonymityButtonFromTM(model);
if (spin == NULL) {
BREAK();
@@ -220,12 +207,12 @@
} else {
anon = gtk_spin_button_get_value_as_int
(GTK_SPIN_BUTTON(spin));
- }
-
+ }
FSUI_startDownload(ctx,
anon,
uri,
- pfx);
+ lnk);
+ FREE(lnk);
}
void on_downloadButton_clicked(GtkWidget * treeview,
@@ -290,12 +277,17 @@
void displayDownloadComplete(const struct ECRS_URI * uri,
const char * filename) {
char * ren;
+ const char * fn;
+ const char * ln;
unsigned long long size;
char * data;
int fd;
struct ECRS_MetaData * meta;
DownloadList * pos;
-
+ GtkTreeIter iter;
+ GtkTreePath * path;
+ struct ECRS_URI * u;
+
pos = head;
while (pos != NULL) {
if (ECRS_equalsUri(uri,
@@ -303,41 +295,81 @@
break;
pos = pos->next;
}
+ if (pos == NULL)
+ return;
+ if ( (pos->rr != NULL) &&
+ (gtk_tree_row_reference_valid(pos->rr)) ) {
- ren = ECRS_suggestFilename(filename);
- if (ren == NULL)
- return;
- if (0 != strcmp(ren,
- filename)) {
- /* fixme: ask user for confirmation? */
- /* rename(filename, ren); */
- }
- FREE(ren);
- /* fixme: also update download model? */
- /* update directory view (if applicable!) */
- if ( (pos != NULL) &&
- (pos->rr != NULL) &&
- (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);
+ /* 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) {
+ gtk_tree_path_free(path);
+ return;
+ }
+ gtk_tree_path_free(path);
}
+
+ /* only rename top-level files, not files inside of directories! */
+ if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary),
+ &iter)) {
+ do {
+ ln = NULL;
+ fn = NULL;
+ gtk_tree_model_get(GTK_TREE_MODEL(summary),
+ &iter,
+ DOWNLOAD_URI, &u,
+ DOWNLOAD_FILENAME, &fn,
+ DOWNLOAD_LINKNAME, &ln,
+ -1);
+ if (ECRS_equalsUri(u, uri)) {
+ ren = ECRS_suggestFilename(ln);
+ if (ren != NULL) {
+ gtk_tree_store_set(summary,
+ &iter,
+ DOWNLOAD_LINKNAME, ren,
+ -1);
+ if (0 == strcmp(fn, ln)) {
+ /* keep the actual data under the URI name
+ and create a symlink */
+ if (0 != RENAME(ren, fn))
+ LOG(LOG_ERROR,
+ _("Renaming of file '%s' to '%s' failed: %s\n"),
+ ren,
+ fn,
+ STRERROR(errno));
+ else
+ if (0 != SYMLINK(fn, ren))
+ LOG_FILE_STRERROR(LOG_ERROR, "symlink", ren);
+ }
+ FREE(ren);
+ }
+ break;
+ }
+ } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(summary),
+ &iter));
+ }
}
@@ -440,6 +472,7 @@
gtk_tree_store_set(summary,
&iiter,
DOWNLOAD_FILENAME, filename,
+ DOWNLOAD_LINKNAME, filename,
DOWNLOAD_SIZE, filesize,
DOWNLOAD_PROGRESS, progress,
DOWNLOAD_URISTRING, uriname,
@@ -460,7 +493,8 @@
"activeDownloadsList");
summary =
gtk_tree_store_new(DOWNLOAD_NUM,
- G_TYPE_STRING, /* name */
+ G_TYPE_STRING, /* name (URI as string) */
+ G_TYPE_STRING, /* name (user-friendly name) */
G_TYPE_UINT64, /* size */
G_TYPE_INT, /* progress */
G_TYPE_STRING, /* uri */
@@ -474,7 +508,7 @@
_("Name"),
renderer,
"value", DOWNLOAD_PROGRESS,
- "text", DOWNLOAD_FILENAME,
+ "text", DOWNLOAD_LINKNAME,
NULL);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(downloadList),
Modified: gnunet-gtk/src/plugins/fs/fs.c
===================================================================
--- gnunet-gtk/src/plugins/fs/fs.c 2005-08-18 04:33:52 UTC (rev 1731)
+++ gnunet-gtk/src/plugins/fs/fs.c 2005-08-18 06:26:31 UTC (rev 1732)
@@ -58,14 +58,10 @@
event->data.DownloadProgress.completed,
event->data.DownloadProgress.last_block,
event->data.DownloadProgress.last_size);
- /* FIXME:
- if directory, also update search view! */
break;
case FSUI_download_complete:
displayDownloadComplete(event->data.DownloadProgress.uri,
event->data.DownloadProgress.filename);
- /* FIXME:
- if directory, also update search view! */
break;
case FSUI_download_error:
BREAK();
Modified: gnunet-gtk/src/plugins/fs/fs.h
===================================================================
--- gnunet-gtk/src/plugins/fs/fs.h 2005-08-18 04:33:52 UTC (rev 1731)
+++ gnunet-gtk/src/plugins/fs/fs.h 2005-08-18 06:26:31 UTC (rev 1732)
@@ -51,6 +51,7 @@
enum {
DOWNLOAD_FILENAME = 0,
+ DOWNLOAD_LINKNAME,
DOWNLOAD_SIZE,
DOWNLOAD_PROGRESS,
DOWNLOAD_URISTRING,
Modified: gnunet-gtk/src/plugins/fs/meta.c
===================================================================
--- gnunet-gtk/src/plugins/fs/meta.c 2005-08-18 04:33:52 UTC (rev 1731)
+++ gnunet-gtk/src/plugins/fs/meta.c 2005-08-18 06:26:31 UTC (rev 1732)
@@ -106,6 +106,7 @@
ts,
NULL);
pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
+ g_object_ref(pixbuf);
gdk_pixbuf_loader_close(loader,
NULL);
if (pixbuf != NULL) {
@@ -113,6 +114,7 @@
pixbuf);
g_object_unref(pixbuf);
}
+ UNREF(loader);
}
}
Modified: gnunet-gtk/src/plugins/fs/search.c
===================================================================
--- gnunet-gtk/src/plugins/fs/search.c 2005-08-18 04:33:52 UTC (rev 1731)
+++ gnunet-gtk/src/plugins/fs/search.c 2005-08-18 06:26:31 UTC (rev 1732)
@@ -111,6 +111,7 @@
pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
gdk_pixbuf_loader_close(loader,
NULL);
+ g_object_ref(pixbuf);
UNREF(loader);
} else {
pixbuf = NULL;
Modified: gnunet-gtk/src/plugins/stats/functions.c
===================================================================
--- gnunet-gtk/src/plugins/stats/functions.c 2005-08-18 04:33:52 UTC (rev
1731)
+++ gnunet-gtk/src/plugins/stats/functions.c 2005-08-18 06:26:31 UTC (rev
1732)
@@ -405,6 +405,9 @@
NULL);
MUTEX_DESTROY(&lock);
releaseClientSocket(sock);
+ GROW(lastStatValues,
+ lsv_size,
+ 0);
sock = NULL;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r1732 - GNUnet/src/applications/fs/ecrs GNUnet/src/applications/fs/fsui gnunet-gtk/src/common gnunet-gtk/src/plugins/fs gnunet-gtk/src/plugins/stats,
grothoff <=