mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
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 <slavazanko@gmail.com>
This commit is contained in:
parent
4e64456ee2
commit
949d257f37
@ -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.
|
||||
*/
|
||||
|
@ -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/теÑ<C2B5>товый/путь", "/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/#enc:KOI8-R/теÑ<C2B5>товый/путь");
|
||||
|
||||
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("/теÑ<C2B5>товый/путь", "/теÑ<C2B5>товый/путь", "/теÑ<C2B5>товый/путь");
|
||||
|
||||
path_recode_one_check("/#enc:UTF-8/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/теÑ<C2B5>товый/путь", "/#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);
|
||||
|
Loading…
Reference in New Issue
Block a user