From 098d336eada46dfb14675757bd0979519ec0601d Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Tue, 3 Oct 2023 10:50:49 +0100 Subject: [PATCH] Include symbolic link as a search option --- doc/docbook/GuideImageSearchSearch.xml | 4 +- src/search.cc | 61 ++++++++++++++------------ 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/doc/docbook/GuideImageSearchSearch.xml b/doc/docbook/GuideImageSearchSearch.xml index 361e1ea5..a82add0c 100644 --- a/doc/docbook/GuideImageSearchSearch.xml +++ b/doc/docbook/GuideImageSearchSearch.xml @@ -83,7 +83,9 @@ File - If "name is" is selected, the search will match if the text exactly matches the file name. If "name contains" or "path contains" is selected, the search will match if the entered text appears within the file name or path.The text comparison can be made to be case sensitive by enabling the Match case checkbox. + If "name is" is selected, the search will match if the text exactly matches the file name. If "name contains" or "path contains" is selected, the search will match if the entered text appears within the file name or path. + The text comparison can be made to be case sensitive by enabling the Match case checkbox. + The search can be restricted to symbolic links by enabling the Symbolic Link checkbox. If "contains" or "path contains" is selected, Perl Compatible Regular Expressions diff --git a/src/search.cc b/src/search.cc index 95331e17..2dde8a31 100644 --- a/src/search.cc +++ b/src/search.cc @@ -163,6 +163,7 @@ struct SearchData gchar *search_name; GRegex *search_name_regex; gboolean search_name_match_case; + gboolean search_name_symbolic_link; gint64 search_size; gint64 search_size_end; gint search_date_y; @@ -1958,38 +1959,41 @@ static gboolean search_file_next(SearchData *sd) tested = TRUE; match = FALSE; - if (sd->match_name == SEARCH_MATCH_NAME_EQUAL) + if (!sd->search_name_symbolic_link || (sd->search_name_symbolic_link && islink(fd->path))) { - if (sd->search_name_match_case) + if (sd->match_name == SEARCH_MATCH_NAME_EQUAL) { - match = (strcmp(fd->name, sd->search_name) == 0); - } - else - { - match = (g_ascii_strcasecmp(fd->name, sd->search_name) == 0); - } - } - else if (sd->match_name == SEARCH_MATCH_NAME_CONTAINS || sd->match_name == SEARCH_MATCH_PATH_CONTAINS) - { - const gchar *fd_name_or_path; - if (sd->match_name == SEARCH_MATCH_NAME_CONTAINS) - { - fd_name_or_path = fd->name; - } - else - { - fd_name_or_path = fd->path; - } - if (sd->search_name_match_case) - { - match = g_regex_match(sd->search_name_regex, fd_name_or_path, static_cast(0), nullptr); + if (sd->search_name_match_case) + { + match = (strcmp(fd->name, sd->search_name) == 0); + } + else + { + match = (g_ascii_strcasecmp(fd->name, sd->search_name) == 0); + } } - else + else if (sd->match_name == SEARCH_MATCH_NAME_CONTAINS || sd->match_name == SEARCH_MATCH_PATH_CONTAINS) { - /* sd->search_name is converted in search_start() */ - gchar *haystack = g_utf8_strdown(fd_name_or_path, -1); - match = g_regex_match(sd->search_name_regex, haystack, static_cast(0), nullptr); - g_free(haystack); + const gchar *fd_name_or_path; + if (sd->match_name == SEARCH_MATCH_NAME_CONTAINS) + { + fd_name_or_path = fd->name; + } + else + { + fd_name_or_path = fd->path; + } + if (sd->search_name_match_case) + { + match = g_regex_match(sd->search_name_regex, fd_name_or_path, static_cast(0), nullptr); + } + else + { + /* sd->search_name is converted in search_start() */ + gchar *haystack = g_utf8_strdown(fd_name_or_path, -1); + match = g_regex_match(sd->search_name_regex, haystack, static_cast(0), nullptr); + g_free(haystack); + } } } } @@ -3415,6 +3419,7 @@ void search_new(FileData *dir_fd, FileData *example_file) gtk_widget_show(combo); pref_checkbox_new_int(hbox, _("Match case"), sd->search_name_match_case, &sd->search_name_match_case); + pref_checkbox_new_int(hbox, _("Symbolic link"), sd->search_name_symbolic_link, &sd->search_name_symbolic_link); gtk_widget_set_tooltip_text(GTK_WIDGET(combo), "When set to \"contains\" or \"path contains\", this field uses Perl Compatible Regular Expressions.\ne.g. use \n.*\\.jpg\n and not \n*.jpg\n\nSee the Help file."); /* Search for file size */ -- 2.20.1