From: Olivier Goffart Date: Tue, 20 Oct 2015 15:06:32 +0000 (+0200) Subject: csync_exclude: Use PathMatchSpecA instead of PathMatchSpecW X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~1527 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=71827549d6bc8083baa61d8c2a5f3f3198526002;p=nextcloud-desktop.git 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) --- diff --git a/csync/src/csync_misc.c b/csync/src/csync_misc.c index 824e05444..a93d42213 100644 --- a/csync/src/csync_misc.c +++ b/csync/src/csync_misc.c @@ -57,20 +57,13 @@ int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags) { #else /* HAVE_FNMATCH */ #include -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 diff --git a/csync/tests/csync_tests/check_csync_exclude.c b/csync/tests/csync_tests/check_csync_exclude.c index c73fe5f5c..797542f50 100644 --- a/csync/tests/csync_tests/check_csync_exclude.c +++ b/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)