@@ -133,6 +133,11 @@ typedef struct {
133133 guint handler_id ;
134134} GSettingsCondition ;
135135
136+ typedef struct {
137+ GPatternSpec * pattern ;
138+ gboolean absolute ;
139+ } MatchPattern ;
140+
136141static void
137142dbus_condition_free (gpointer data )
138143{
@@ -157,6 +162,29 @@ gsettings_condition_free (gpointer data)
157162 g_free (cond );
158163}
159164
165+ static MatchPattern *
166+ new_match_pattern (const gchar * pattern )
167+ {
168+ MatchPattern * mp = g_new0 (MatchPattern , 1 );
169+
170+ mp -> pattern = g_pattern_spec_new (pattern );
171+
172+ // A pattern with a leading * can be matched against a full path, whether it has
173+ // any other path elements or not (*/foo/bar/* or *.foo)
174+ mp -> absolute = g_str_has_prefix (pattern , "/" ) || g_str_has_prefix (pattern , "*" );
175+
176+ return mp ;
177+ }
178+
179+ static void
180+ free_match_pattern (gpointer data )
181+ {
182+ MatchPattern * mp = (MatchPattern * ) data ;
183+
184+ g_pattern_spec_free (mp -> pattern );
185+ g_free (mp );
186+ }
187+
160188static void
161189nemo_action_init (NemoAction * action )
162190{
@@ -580,23 +608,29 @@ populate_patterns_and_filenames (NemoAction *action,
580608 gint i ;
581609
582610 for (i = 0 ; i < g_strv_length (array ); i ++ ) {
583- const gchar * str = array [i ];
611+ GString * str = g_string_new (array [i ]);
612+
613+ g_string_replace (str , "~" , g_get_home_dir (), 1 );
614+
615+ g_printerr ("str: '%s'\n" , str -> str );
584616
585- if (g_strstr_len (str , -1 , "?" ) || g_strstr_len (str , -1 , "*" )) {
586- if (g_str_has_prefix (array [ i ] , "!" )) {
587- * forbidden_patterns = g_list_prepend (* forbidden_patterns , g_pattern_spec_new ( array [ i ] + 1 ));
617+ if (g_strstr_len (str -> str , -1 , "?" ) || g_strstr_len (str -> str , -1 , "*" )) {
618+ if (g_str_has_prefix (str -> str , "!" )) {
619+ * forbidden_patterns = g_list_prepend (* forbidden_patterns , new_match_pattern ( str -> str + 1 ));
588620 } else {
589- * allowed_patterns = g_list_prepend (* allowed_patterns , g_pattern_spec_new ( array [ i ] ));
621+ * allowed_patterns = g_list_prepend (* allowed_patterns , new_match_pattern ( str -> str ));
590622 }
591-
592- continue ;
593623 }
594-
595- if (g_str_has_prefix (array [i ], "!" )) {
596- * forbidden_filenames = g_list_prepend (* forbidden_filenames , g_strdup (array [i ] + 1 ));
597- } else {
598- * allowed_filenames = g_list_prepend (* allowed_filenames , g_strdup (array [i ]));
624+ else
625+ {
626+ if (g_str_has_prefix (str -> str , "!" )) {
627+ * forbidden_filenames = g_list_prepend (* forbidden_filenames , g_strdup (str -> str + 1 ));
628+ } else {
629+ * allowed_filenames = g_list_prepend (* allowed_filenames , g_strdup (str -> str ));
630+ }
599631 }
632+
633+ g_string_free (str , TRUE);
600634 }
601635
602636 * allowed_patterns = g_list_reverse (* allowed_patterns );
@@ -991,10 +1025,10 @@ nemo_action_finalize (GObject *object)
9911025 g_list_free_full (priv -> dbus , (GDestroyNotify ) dbus_condition_free );
9921026 g_list_free_full (priv -> gsettings , (GDestroyNotify ) gsettings_condition_free );
9931027
994- g_list_free_full (priv -> allowed_location_patterns , (GDestroyNotify ) g_pattern_spec_free );
995- g_list_free_full (priv -> forbidden_location_patterns , (GDestroyNotify ) g_pattern_spec_free );
996- g_list_free_full (priv -> allowed_patterns , (GDestroyNotify ) g_pattern_spec_free );
997- g_list_free_full (priv -> forbidden_patterns , (GDestroyNotify ) g_pattern_spec_free );
1028+ g_list_free_full (priv -> allowed_location_patterns , (GDestroyNotify ) free_match_pattern );
1029+ g_list_free_full (priv -> forbidden_location_patterns , (GDestroyNotify ) free_match_pattern );
1030+ g_list_free_full (priv -> allowed_patterns , (GDestroyNotify ) free_match_pattern );
1031+ g_list_free_full (priv -> forbidden_patterns , (GDestroyNotify ) free_match_pattern );
9981032 g_list_free_full (priv -> allowed_location_filenames , (GDestroyNotify ) g_free );
9991033 g_list_free_full (priv -> forbidden_location_filenames , (GDestroyNotify ) g_free );
10001034 g_list_free_full (priv -> allowed_filenames , (GDestroyNotify ) g_free );
@@ -1686,7 +1720,10 @@ check_is_allowed (NemoAction *action,
16861720 allowed_allowed = FALSE;
16871721
16881722 for (ll = allowed_patterns ; ll != NULL ; ll = ll -> next ) {
1689- if (g_pattern_spec_match ((GPatternSpec * ) ll -> data , strlen (name ), name , NULL )) {
1723+ MatchPattern * mp = (MatchPattern * ) ll -> data ;
1724+ const gchar * test_str = mp -> absolute ? path : name ;
1725+
1726+ if (g_pattern_spec_match (mp -> pattern , strlen (test_str ), test_str , NULL )) {
16901727 allowed_allowed = TRUE;
16911728 break ;
16921729 }
@@ -1711,7 +1748,10 @@ check_is_allowed (NemoAction *action,
17111748 // (forbidden_allowed = TRUE;)
17121749
17131750 for (ll = forbidden_patterns ; ll != NULL ; ll = ll -> next ) {
1714- if (g_pattern_spec_match ((GPatternSpec * ) ll -> data , strlen (name ), name , NULL )) {
1751+ MatchPattern * mp = (MatchPattern * ) ll -> data ;
1752+ const gchar * test_str = mp -> absolute ? path : name ;
1753+
1754+ if (g_pattern_spec_match (mp -> pattern , strlen (test_str ), test_str , NULL )) {
17151755 forbidden_allowed = FALSE;
17161756 break ;
17171757 }
0 commit comments