Attached is a patch to have a "browse host" request respond with the files
sorted by descending file date/time (so that the newest files on the system
appear at the beginning of the browse list).
As part of this change, it was necessary for me to move some things from
"recurse_scan_intern()" to "share_scan()", as I was having problems with the
SHA1 calculation routine relying on values that were set in
"recurse_scan_intern()" (Otherwise, I would have had to wait until all
SHA1's were updated before doing the sort - that could take a while).
I created a new property to determine whether or not this sort is performed:
"sort_browse_upload" (gboolean, of course). The property is live and can be
accessed via the preferences-debug screen (or the shell) or the gnet_config
file. If somebody has an exceptionally large number of files, then the sort
could potentially add a substantial amount of time to the total required for
a rescan (note: on my headless box, which is an obsolete P2-300, processing
7600 files, having this option active adds about 15 seconds to the time
required for a rescan. Not too bad....)
Christian - could you take care of adding a check box into the GUI? I'm
having a case of learning-curve-itis with Glade, and I don't know how long
it will be before I can add it in myself (if ever, that is - I've never been
good at GUI development).
The patch is relative to the main GtkG directory (the parent of "src").
Files affected:
src/core/share.c
src/core/share.h
if/gnet_property.c
if/gnet_props.ag
(if/gnet_property.h)
(if/gnet_property_priv.h)
(the last two are auto-generated by autogen - I included them in the patch
anyway...)
Lloyd Bryant
diff --exclude-from=./diff.excludes -ru /usr/local/src/base.gtkg/gtk-gnutella/src/core/share.c src/core/share.c
--- /usr/local/src/base.gtkg/gtk-gnutella/src/core/share.c 2006-11-15 06:36:40.000000000 -0700
+++ src/core/share.c 2006-11-15 17:50:04.000000000 -0700
@@ -1017,8 +1017,9 @@
if (
0 == ascii_strcasecmp("--all--", e->str) || /* All files */
(start >= name && *start == '.' &&
- 0 == ascii_strcasecmp(start + 1, e->str))
- ) {
+ 0 == ascii_strcasecmp(start + 1, e->str)))
+ {
+
struct shared_file *found = NULL;
struct stat file_stat;
@@ -1077,20 +1078,10 @@
break;
}
- found->file_index = ++files_scanned;
-
- if (request_sha1(found)) {
- st_insert_item(search_table, found->name_canonic, found);
+ shared_files = g_slist_prepend(shared_files, shared_file_ref(found));
+ files_scanned++;
- shared_files = g_slist_prepend(shared_files,
- shared_file_ref(found));
- bytes_scanned += file_stat.st_size;
- kbytes_scanned += bytes_scanned >> 10;
- bytes_scanned &= (1 << 10) - 1;
- } else {
- found = NULL;
- }
break; /* for loop */
}
}
@@ -1228,8 +1219,30 @@
dirs = NULL;
/*
- * Done scanning all the files.
- */
+ * Done scanning for the files. Now process them.
+ * 1. Sort file list (if configured)
+ * 2. Set file_index based on new sort order
+ * 3. Lookup/Calculate SHA1's
+ * 4. Add to search table
+ * 5. Maintain byte/kbyte counts
+ * 5. Compact the search table
+ */
+
+ if (sort_browse_upload)
+ shared_files = g_slist_sort(shared_files, shared_file_sort_dsnd_mtime);
+
+ for (i = 1, sl = shared_files; sl; i++, sl = g_slist_next(sl)) {
+ shared_file_t * sf = sl->data;
+
+ sf->file_index = i;
+ if (request_sha1(sf)) {
+ st_insert_item(search_table, sf->name_canonic, sf);
+ bytes_scanned += sf->file_size;
+ kbytes_scanned += sf->file_size >> 10;
+ bytes_scanned &= (1 << 10) - 1;
+ } else
+ sl->data = NULL; /* request_sha1() calls shared_file_remove() */
+ }
st_compact(search_table);
@@ -1246,6 +1259,7 @@
* --RAM, 23/10/2002
*/
+
file_table = g_malloc0((files_scanned + 1) * sizeof *file_table);
for (i = 0, sl = shared_files; sl; i++, sl = g_slist_next(sl)) {
@@ -2640,4 +2654,30 @@
return files_scanned;
}
+/**
+ * Sort function - shared files by descending mtime.
+ * Note: "Holes" in the file table will sort to the bottom.
+ */
+gint
+shared_file_sort_dsnd_mtime(gconstpointer f1, gconstpointer f2)
+{
+ const shared_file_t * sf1 = f1;
+ const shared_file_t * sf2 = f2;
+ time_t file1_mtime = 0;
+ time_t file2_mtime = 0;
+
+ /* Protect against holes in the file table */
+ if (sf1)
+ file1_mtime = sf1->mtime;
+ if (sf2)
+ file2_mtime = sf2->mtime;
+
+ if (file1_mtime > file2_mtime)
+ return(-1);
+ else if (file1_mtime == file2_mtime)
+ return(0);
+ else
+ return(1);
+
+}
/* vi: set ts=4 sw=4 cindent: */
diff --exclude-from=./diff.excludes -ru /usr/local/src/base.gtkg/gtk-gnutella/src/core/share.h src/core/share.h
--- /usr/local/src/base.gtkg/gtk-gnutella/src/core/share.h 2006-11-15 06:36:40.000000000 -0700
+++ src/core/share.h 2006-11-15 11:00:25.000000000 -0700
@@ -133,6 +133,7 @@
const gchar *map_muid_to_query_string(const gchar muid[GUID_RAW_SIZE]);
+gint shared_file_sort_dsnd_mtime(gconstpointer f1, gconstpointer f2);
#endif /* _core_share_h_ */
/* vi: set ts=4 sw=4 cindent: */
diff --exclude-from=./diff.excludes -ru /usr/local/src/base.gtkg/gtk-gnutella/src/if/gnet_property.c src/if/gnet_property.c
--- /usr/local/src/base.gtkg/gtk-gnutella/src/if/gnet_property.c 2006-11-15 06:36:45.000000000 -0700
+++ src/if/gnet_property.c 2006-11-15 20:15:37.000000000 -0700
@@ -652,6 +652,8 @@
gboolean dump_received_gnutella_packets_def = FALSE;
gboolean search_results_expose_relative_paths = FALSE;
gboolean search_results_expose_relative_paths_def = FALSE;
+gboolean sort_browse_upload = FALSE;
+gboolean sort_browse_upload_def = FALSE;
static prop_set_t *gnet_property = NULL;
@@ -6239,6 +6241,23 @@
gnet_property->props[292].data.boolean.def = &search_results_expose_relative_paths_def;
gnet_property->props[292].data.boolean.value = &search_results_expose_relative_paths;
+
+ /*
+ * PROP_SORT_BROWSE_UPLOAD:
+ *
+ * General data:
+ */
+ gnet_property->props[293].name = "sort_browse_upload";
+ gnet_property->props[293].desc = _("If enabled, any browse host uploads will be sorted by descending file time (in other words, newest files first). Changing this value has no effect until a rescan is performed. Note: If there are a large number of files, this can add substantially to the amount of time required for a rescan!");
+ gnet_property->props[293].ev_changed = event_new("sort_browse_upload_changed");
+ gnet_property->props[293].save = TRUE;
+ gnet_property->props[293].vector_size = 1;
+
+ /* Type specific data: */
+ gnet_property->props[293].type = PROP_TYPE_BOOLEAN;
+ gnet_property->props[293].data.boolean.def = &sort_browse_upload_def;
+ gnet_property->props[293].data.boolean.value = &sort_browse_upload;
+
gnet_property->byName = g_hash_table_new(g_str_hash, g_str_equal);
for (n = 0; n < GNET_PROPERTY_NUM; n ++) {
g_hash_table_insert(gnet_property->byName,
diff --exclude-from=./diff.excludes -ru /usr/local/src/base.gtkg/gtk-gnutella/src/if/gnet_property.h src/if/gnet_property.h
--- /usr/local/src/base.gtkg/gtk-gnutella/src/if/gnet_property.h 2006-11-15 06:36:45.000000000 -0700
+++ src/if/gnet_property.h 2006-11-15 20:15:36.000000000 -0700
@@ -329,6 +329,7 @@
PROP_MAX_SIMULTANEOUS_DOWNLOADS_PER_FILE,
PROP_DUMP_RECEIVED_GNUTELLA_PACKETS,
PROP_SEARCH_RESULTS_EXPOSE_RELATIVE_PATHS,
+ PROP_SORT_BROWSE_UPLOAD,
GNET_PROPERTY_END
} gnet_property_t;
diff --exclude-from=./diff.excludes -ru /usr/local/src/base.gtkg/gtk-gnutella/src/if/gnet_property_priv.h src/if/gnet_property_priv.h
--- /usr/local/src/base.gtkg/gtk-gnutella/src/if/gnet_property_priv.h 2006-11-15 06:36:45.000000000 -0700
+++ src/if/gnet_property_priv.h 2006-11-15 20:15:36.000000000 -0700
@@ -337,6 +337,7 @@
extern const guint32 max_simultaneous_downloads_per_file;
extern const gboolean dump_received_gnutella_packets;
extern const gboolean search_results_expose_relative_paths;
+extern const gboolean sort_browse_upload;
prop_set_t *gnet_prop_init(void);
diff --exclude-from=./diff.excludes -ru /usr/local/src/base.gtkg/gtk-gnutella/src/if/gnet_props.ag src/if/gnet_props.ag
--- /usr/local/src/base.gtkg/gtk-gnutella/src/if/gnet_props.ag 2006-11-15 06:36:45.000000000 -0700
+++ src/if/gnet_props.ag 2006-11-15 18:56:02.000000000 -0700
@@ -3409,4 +3409,17 @@
};
};
+prop = {
+ name = "sort_browse_upload";
+ desc = "If enabled, any browse host uploads will be sorted by descending "
+ "file time (in other words, newest files first). Changing this "
+ "value has no effect until a rescan is performed. Note: If there "
+ "are a large number of files, this can add substantially to the "
+ "amount of time required for a rescan!";
+ type = boolean;
+ data = {
+ default = FALSE;
+ };
+};
+
/* vi: set ts=4: */
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Gtk-gnutella-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtk-gnutella-devel