summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/file-data.c33
-rw-r--r--src/fr-window.c27
2 files changed, 51 insertions, 9 deletions
diff --git a/src/file-data.c b/src/file-data.c
index e2ee2dc..8905b96 100644
--- a/src/file-data.c
+++ b/src/file-data.c
@@ -131,21 +131,38 @@ int
find_path_in_file_data_array (GPtrArray *array,
const char *path)
{
- int l, r, p, cmp = -1;
+ int path_l;
+ int left, right, p, cmp = -1;
FileData *fd;
-
- l = 0;
- r = array->len;
- while (l < r) {
- p = l + ((r - l) / 2);
+
+ if (path == NULL)
+ return -1;
+
+ path_l = strlen (path);
+ left = 0;
+ right = array->len;
+ while (left < right) {
+ p = left + ((right - left) / 2);
fd = (FileData *) g_ptr_array_index (array, p);
+
cmp = strcmp (path, fd->original_path);
+ if (cmp != 0) {
+ /* consider '/path/to/dir' and '/path/to/dir/' the same path */
+
+ int original_path_l = strlen (fd->original_path);
+ if ((path_l == original_path_l - 1) && (fd->original_path[original_path_l - 1] == '/')) {
+ int cmp2 = strncmp (path, fd->original_path, original_path_l - 1);
+ if (cmp2 == 0)
+ cmp = cmp2;
+ }
+ }
+
if (cmp == 0)
return p;
else if (cmp < 0)
- r = p;
+ right = p;
else
- l = p + 1;
+ left = p + 1;
}
return -1;
diff --git a/src/fr-window.c b/src/fr-window.c
index fb5da06..cec29a2 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -3289,6 +3289,9 @@ action_performed (FrArchive *archive,
/* -- selections -- */
+#undef DEBUG_GET_DIR_LIST_FROM_PATH
+
+
static GList *
get_dir_list_from_path (FrWindow *window,
char *path)
@@ -3305,9 +3308,31 @@ get_dir_list_from_path (FrWindow *window,
dirname_l = strlen (dirname);
for (i = 0; i < window->archive->command->files->len; i++) {
FileData *fd = g_ptr_array_index (window->archive->command->files, i);
+ gboolean matches = FALSE;
- if (strncmp (dirname, fd->full_path, dirname_l) == 0)
+#ifdef DEBUG_GET_DIR_LIST_FROM_PATH
+ g_print ("%s <=> %s (%d)\n", dirname, fd->full_path, dirname_l);
+#endif
+
+ if (fd->dir) {
+ int full_path_l = strlen (fd->full_path);
+ if ((full_path_l == dirname_l - 1) && (strncmp (dirname, fd->full_path, full_path_l) == 0))
+ /* example: dirname is '/path/to/dir/' and fd->full_path is '/path/to/dir' */
+ matches = TRUE;
+ else if (strcmp (dirname, fd->full_path) == 0)
+ matches = TRUE;
+ }
+
+ if (! matches && strncmp (dirname, fd->full_path, dirname_l) == 0) {
+ matches = TRUE;
+ }
+
+ if (matches) {
+#ifdef DEBUG_GET_DIR_LIST_FROM_PATH
+ g_print ("`-> OK\n");
+#endif
list = g_list_prepend (list, g_strdup (fd->original_path));
+ }
}
g_free (dirname);