diff options
author | infirit <[email protected]> | 2014-11-23 00:06:52 +0100 |
---|---|---|
committer | infirit <[email protected]> | 2014-11-23 00:06:52 +0100 |
commit | d80298f683bc5f8461a06212d0564523146fb6ed (patch) | |
tree | 4e1b815ae0eff4c19340410a0fd7d115fb5e46b0 /src/file-data.c | |
parent | e2cd8acb8233e57847b7486b1096efe86368c44c (diff) | |
download | engrampa-d80298f683bc5f8461a06212d0564523146fb6ed.tar.bz2 engrampa-d80298f683bc5f8461a06212d0564523146fb6ed.tar.xz |
engrampa doesn't delete directories w/ files within
consider '/path/to/dir' and '/path/to/dir/' the same path
Based on FR commit: 238b11888a6d88af70d056963257a7bf2cf4192c
From: Paolo Bacchilega <[email protected]>
Gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=632339
closes #69
Diffstat (limited to 'src/file-data.c')
-rw-r--r-- | src/file-data.c | 33 |
1 files changed, 25 insertions, 8 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; |