From 949d257f37c2d2502a2456c226be703c810c5c13 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Tue, 28 Aug 2012 13:20:30 +0300 Subject: [PATCH] Ticket #2791: Fixed: cannot Copy/Move files with filename encoding change Steps to reproduce: * run mc * change encoding one of panels to any different from system encoding * try to copy any file to panel with changed encoding Expected result: files should be copied. Actual result: error box here. Signed-off-by: Slava Zanko --- lib/vfs/path.c | 27 +++++++++---- tests/lib/vfs/path_recode.c | 97 ++++++++++++++++++++++++++------------------- 2 files changed, 76 insertions(+), 48 deletions(-) diff --git a/lib/vfs/path.c b/lib/vfs/path.c index 25696e1ea..3a6eb8b88 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -142,17 +142,27 @@ vfs_canon (const char *path) { char *result, *local; - local = tilde_expand (path); - if (*local != PATH_SEP) + if (g_str_has_prefix (path, VFS_ENCODING_PREFIX)) { - char *curr_dir; - - g_free (local); - curr_dir = vfs_get_current_dir (); - local = mc_build_filename (curr_dir, path, NULL); - g_free (curr_dir); + /* + encoding prefix placed at start of string without the leading slash + should be autofixed by adding the leading slash + */ + local = mc_build_filename (PATH_SEP_STR, path, NULL); } + else + { + local = tilde_expand (path); + if (*local != PATH_SEP) + { + char *curr_dir; + g_free (local); + curr_dir = vfs_get_current_dir (); + local = mc_build_filename (curr_dir, path, NULL); + g_free (curr_dir); + } + } result = vfs_canon (local); g_free (local); return result; @@ -423,6 +433,7 @@ vfs_path_from_str_deprecated_parser (char *path, vfs_path_flag_t flags) /** Split path string to path elements by URL algorithm. * * @param path_str VFS-path + * @param flags flags for converter * * @return pointer to newly created vfs_path_t object with filled path elements array. */ diff --git a/tests/lib/vfs/path_recode.c b/tests/lib/vfs/path_recode.c index 1f5b3571b..31f11fb28 100644 --- a/tests/lib/vfs/path_recode.c +++ b/tests/lib/vfs/path_recode.c @@ -60,6 +60,31 @@ teardown (void) /* --------------------------------------------------------------------------------------------- */ +static void test_init_vfs(const char *encoding) +{ + str_init_strings (encoding); + + vfs_init (); + init_localfs (); + vfs_setup_work_dir (); + + mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR; + + mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR; + load_codepages_list (); +} + +/* --------------------------------------------------------------------------------------------- */ + +static void test_deinit_vfs() +{ + free_codepages_list (); + str_uninit_strings (); + vfs_shut (); +} + +/* --------------------------------------------------------------------------------------------- */ + #define path_recode_one_check(input, etalon1, etalon2) {\ vpath = vfs_path_from_str (input);\ element = vfs_path_get_by_index(vpath, -1);\ @@ -76,25 +101,13 @@ START_TEST (test_path_recode_base_utf8) char *result; const vfs_path_element_t *element; - str_init_strings ("UTF-8"); - - vfs_init (); - init_localfs (); - vfs_setup_work_dir (); - - mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR; - - mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR; - load_codepages_list (); + test_init_vfs("UTF-8"); path_recode_one_check("/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ"); path_recode_one_check("/#enc:KOI8-R/теÑ�товый/путь", "/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/#enc:KOI8-R/теÑ�товый/путь"); - free_codepages_list (); - str_uninit_strings (); - vfs_shut (); - + test_deinit_vfs(); } END_TEST @@ -106,25 +119,13 @@ START_TEST (test_path_recode_base_koi8r) char *result; const vfs_path_element_t *element; - str_init_strings ("KOI8-R"); - - vfs_init (); - init_localfs (); - vfs_setup_work_dir (); - - mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR; - - mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR; - load_codepages_list (); + test_init_vfs("KOI8-R"); path_recode_one_check("/тестовый/путь", "/тестовый/путь", "/тестовый/путь"); path_recode_one_check("/#enc:UTF-8/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/теÑ�товый/путь", "/#enc:UTF-8/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ"); - free_codepages_list (); - str_uninit_strings (); - vfs_shut (); - + test_deinit_vfs(); } END_TEST @@ -138,15 +139,7 @@ START_TEST(test_path_to_str_flags) vfs_path_t *vpath; char *str_path; - str_init_strings ("UTF-8"); - - vfs_init (); - init_localfs (); - - vfs_setup_work_dir (); - mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR; - mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR; - load_codepages_list (); + test_init_vfs("UTF-8"); test_subclass1.flags = VFS_S_REMOTE; vfs_s_init_class (&vfs_test_ops1, &test_subclass1); @@ -197,10 +190,33 @@ START_TEST(test_path_to_str_flags) g_free (str_path); vfs_path_free (vpath); - free_codepages_list (); - str_uninit_strings (); - vfs_shut (); + test_deinit_vfs(); +} +END_TEST + +/* --------------------------------------------------------------------------------------------- */ + +START_TEST(test_encode_info_at_start) +{ + vfs_path_t *vpath; + char *actual; + const vfs_path_element_t *vpath_element; + + test_init_vfs("UTF-8"); + + vpath = vfs_path_from_str ("#enc:KOI8-R/bla-bla/some/path"); + actual = vfs_path_to_str (vpath); + + fail_unless (strcmp ("/#enc:KOI8-R/bla-bla/some/path", actual) == 0, "\nactual=%s\n", actual); + + vpath_element = vfs_path_get_by_index (vpath, -1); + + fail_unless (strcmp ("/bla-bla/some/path", vpath_element->path) == 0, "\nvpath_element->path=%s\n", vpath_element->path); + + g_free (actual); + vfs_path_free (vpath); + test_deinit_vfs(); } END_TEST @@ -222,6 +238,7 @@ main (void) tcase_add_test (tc_core, test_path_recode_base_utf8); tcase_add_test (tc_core, test_path_recode_base_koi8r); tcase_add_test (tc_core, test_path_to_str_flags); + tcase_add_test (tc_core, test_encode_info_at_start); /* *********************************** */ suite_add_tcase (s, tc_core); -- 2.11.4.GIT