Sfoglia il codice sorgente

csync_exclude: Use PathMatchSpecA instead of PathMatchSpecW

So we avoid lots of memory allocation.
We can work with char* directly since both the pattern and the file
name are in UTF-8 and there is no need to understand unicode for
such pattern.

(In fact, '?' would not match anyore non-ascii characters, but I
don't think that's a problem. I don't think anyone use '?' in its
exclude list. And the two allocations per call to csync_fnmatch are
really worth getting rid of)
Olivier Goffart 10 anni fa
parent
commit
71827549d6
2 ha cambiato i file con 19 aggiunte e 10 eliminazioni
  1. 3 10
      csync/src/csync_misc.c
  2. 16 0
      csync/tests/csync_tests/check_csync_exclude.c

+ 3 - 10
csync/src/csync_misc.c

@@ -57,20 +57,13 @@ int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags) {
 #else /* HAVE_FNMATCH */
 
 #include <shlwapi.h>
-int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags) {
-    wchar_t *pat = NULL;
-    wchar_t *name = NULL;
+int csync_fnmatch(const char *pattern, const char *name, int flags) {
     BOOL match;
 
-    (void) __flags;
-
-    name = c_utf8_string_to_locale(__name);
-    pat  = c_utf8_string_to_locale(__pattern);
+    (void) flags;
 
-    match = PathMatchSpecW(name, pat);
+    match = PathMatchSpecA(name, pattern);
 
-    c_free_locale_string(pat);
-    c_free_locale_string(name);
     if(match)
         return 0;
     else

+ 16 - 0
csync/tests/csync_tests/check_csync_exclude.c

@@ -48,6 +48,12 @@ static void setup_init(void **state) {
     rc = csync_exclude_load(EXCLUDE_LIST_FILE, &(csync->excludes));
     assert_int_equal(rc, 0);
 
+    /* and add some unicode stuff */
+    rc = _csync_exclude_add(&(csync->excludes), "*.💩");
+    assert_int_equal(rc, 0);
+    rc = _csync_exclude_add(&(csync->excludes), "пятницы.*");
+    assert_int_equal(rc, 0);
+
     *state = csync;
 }
 
@@ -145,6 +151,16 @@ static void check_csync_excluded(void **state)
     rc = csync_excluded(csync, ".netscape/cache", CSYNC_FTW_TYPE_FILE);
     assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
 
+    /* Not excluded  */
+    rc = csync_excluded(csync, "unicode/中文.hé", CSYNC_FTW_TYPE_FILE);
+    assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
+    /* excluded  */
+    rc = csync_excluded(csync, "unicode/пятницы.txt", CSYNC_FTW_TYPE_FILE);
+    assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
+    rc = csync_excluded(csync, "unicode/中文.💩", CSYNC_FTW_TYPE_FILE);
+    assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
+
+
 }
 
 static void check_csync_excluded_traversal(void **state)