Ticket #2595: Broken panels recode in current master

Fixed path recoding

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2011-08-15 14:37:59 +03:00
parent a02c24e6d9
commit 20a79d52ab
5 changed files with 203 additions and 39 deletions

View File

@ -418,7 +418,8 @@ vfs_path_from_str_deprecated_parser (char *path)
element->path = vfs_translate_path_n (local);
element->encoding = vfs_get_encoding (local);
element->dir.converter = INVALID_CONV;
element->dir.converter =
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
url_params = strchr (op, ':'); /* skip VFS prefix */
if (url_params != NULL)
@ -440,7 +441,8 @@ vfs_path_from_str_deprecated_parser (char *path)
element->path = vfs_translate_path_n (path);
element->encoding = vfs_get_encoding (path);
element->dir.converter = INVALID_CONV;
element->dir.converter =
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
vpath->path = g_list_prepend (vpath->path, element);
}
@ -485,8 +487,6 @@ vfs_path_from_str_uri_parser (char *path)
element->class = vfs_prefix_to_class (vfs_prefix_start);
element->vfs_prefix = g_strdup (vfs_prefix_start);
element->dir.converter = INVALID_CONV;
url_delimiter += strlen (VFS_PATH_URL_DELIMITER);
sub = VFSDATA (element);
if (sub != NULL && sub->flags & VFS_S_REMOTE)
@ -500,6 +500,7 @@ vfs_path_from_str_uri_parser (char *path)
{
element->path = vfs_translate_path_n (slash_pointer + 1);
element->encoding = vfs_get_encoding (slash_pointer);
*slash_pointer = '\0';
}
vfs_path_url_split (element, url_delimiter);
@ -509,6 +510,8 @@ vfs_path_from_str_uri_parser (char *path)
element->path = vfs_translate_path_n (url_delimiter);
element->encoding = vfs_get_encoding (url_delimiter);
}
element->dir.converter =
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
vpath->path = g_list_prepend (vpath->path, element);
if (real_vfs_prefix_start > path && *(real_vfs_prefix_start) == PATH_SEP)
@ -523,7 +526,8 @@ vfs_path_from_str_uri_parser (char *path)
element->class = g_ptr_array_index (vfs__classes_list, 0);
element->path = vfs_translate_path_n (path);
element->encoding = vfs_get_encoding (path);
element->dir.converter = INVALID_CONV;
element->dir.converter =
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
vpath->path = g_list_prepend (vpath->path, element);
}
@ -538,15 +542,25 @@ vfs_path_from_str_uri_parser (char *path)
*
* @param vpath pointer to vfs_path_t object
* @param elements_count count of first elements for convert
* @param flags flags for parser
*
* @return pointer to newly created string.
*/
#define vfs_append_from_path(appendfrom) \
{ \
if ((*appendfrom != PATH_SEP) && (*appendfrom != '\0') \
&& (buffer->str[buffer->len - 1] != PATH_SEP)) \
g_string_append_c (buffer, PATH_SEP); \
g_string_append (buffer, appendfrom); \
}
char *
vfs_path_to_str_elements_count (const vfs_path_t * vpath, int elements_count)
{
int element_index;
GString *buffer;
GString *recode_buffer;
if (vpath == NULL)
return NULL;
@ -558,6 +572,7 @@ vfs_path_to_str_elements_count (const vfs_path_t * vpath, int elements_count)
elements_count = vfs_path_elements_count (vpath) + elements_count;
buffer = g_string_new ("");
recode_buffer = g_string_new ("");
for (element_index = 0; element_index < elements_count; element_index++)
{
@ -580,22 +595,27 @@ vfs_path_to_str_elements_count (const vfs_path_t * vpath, int elements_count)
g_free (url_str);
}
if (element->encoding != NULL)
if (vfs_path_element_need_cleanup_converter (element))
{
if (buffer->str[buffer->len - 1] != PATH_SEP)
g_string_append (buffer, PATH_SEP_STR);
g_string_append (buffer, VFS_ENCODING_PREFIX);
g_string_append (buffer, element->encoding);
str_vfs_convert_from (element->dir.converter, element->path, recode_buffer);
vfs_append_from_path (recode_buffer->str);
g_string_set_size (recode_buffer, 0);
}
else
{
vfs_append_from_path (element->path);
}
if ((*element->path != PATH_SEP) && (*element->path != '\0')
&& (buffer->str[buffer->len - 1] != PATH_SEP))
g_string_append_c (buffer, PATH_SEP);
g_string_append (buffer, element->path);
}
g_string_free (recode_buffer, TRUE);
return g_string_free (buffer, FALSE);
}
#undef vfs_append_from_path
/* --------------------------------------------------------------------------------------------- */
/**
* Convert vfs_path_t to string representation.
@ -604,6 +624,7 @@ vfs_path_to_str_elements_count (const vfs_path_t * vpath, int elements_count)
*
* @return pointer to newly created string.
*/
char *
vfs_path_to_str (const vfs_path_t * vpath)
{
@ -970,7 +991,6 @@ vfs_path_deserialize (const char *data, GError ** error)
}
element = g_new0 (vfs_path_element_t, 1);
element->dir.converter = INVALID_CONV;
cfg_value = mc_config_get_string_raw (cpath, groupname, "class-name", NULL);
element->class = vfs_get_class_by_name (cfg_value);
@ -987,6 +1007,8 @@ vfs_path_deserialize (const char *data, GError ** error)
element->path = mc_config_get_string_raw (cpath, groupname, "path", NULL);
element->encoding = mc_config_get_string_raw (cpath, groupname, "encoding", NULL);
element->dir.converter =
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
element->vfs_prefix = mc_config_get_string_raw (cpath, groupname, "vfs_prefix", NULL);

View File

@ -10,8 +10,8 @@
typedef enum
{
VPF_NONE = 0,
VPF_NO_CANON = 1,
VPF_USE_DEPRECATED_PARSER = 2
VPF_NO_CANON = 1 << 0,
VPF_USE_DEPRECATED_PARSER = 1 << 1
} vfs_path_flag_t;
/*** structures declarations (and typedefs of structures)*****************************************/

View File

@ -520,41 +520,30 @@ _vfs_get_cwd (void)
if (vfs_get_raw_current_dir () == NULL)
{
char *tmp;
tmp = g_get_current_dir ();
vfs_set_raw_current_dir (vfs_path_from_str (tmp));
g_free (tmp);
}
path_element = vfs_path_get_by_index (vfs_get_raw_current_dir (), -1);
if (path_element->class->flags & VFSF_LOCAL)
{
char *tmp;
if (path_element->encoding == NULL)
{
char *tmp;
tmp = g_get_current_dir ();
if (tmp != NULL)
{ /* One of the directories in the path is not readable */
struct stat my_stat, my_stat2;
tmp = g_get_current_dir ();
if (tmp != NULL)
{ /* One of the directories in the path is not readable */
estr_t state;
g_string_set_size (vfs_str_buffer, 0);
state = str_vfs_convert_from (str_cnv_from_term, tmp, vfs_str_buffer);
g_free (tmp);
if (state == ESTR_SUCCESS)
{
struct stat my_stat, my_stat2;
/* Check if it is O.K. to use the current_dir */
if (!(mc_global.vfs.cd_symlinks
&& mc_stat (vfs_str_buffer->str, &my_stat) == 0
&& mc_stat (path_element->path, &my_stat2) == 0
&& my_stat.st_ino == my_stat2.st_ino
&& my_stat.st_dev == my_stat2.st_dev))
{
vfs_set_raw_current_dir (vfs_path_from_str (vfs_str_buffer->str));
}
}
/* Check if it is O.K. to use the current_dir */
if (!(mc_global.vfs.cd_symlinks
&& mc_stat (tmp, &my_stat) == 0
&& mc_stat (path_element->path, &my_stat2) == 0
&& my_stat.st_ino == my_stat2.st_ino && my_stat.st_dev == my_stat2.st_dev))
{
vfs_set_raw_current_dir (vfs_path_from_str (tmp));
}
}
}

View File

@ -9,6 +9,7 @@ LIBS=@CHECK_LIBS@ \
TESTS = \
canonicalize_pathname \
current_dir \
path_recode \
path_serialize \
vfs_parse_ls_lga \
vfs_path_string_convert \
@ -24,6 +25,9 @@ canonicalize_pathname_SOURCES = \
current_dir_SOURCES = \
current_dir.c
path_recode_SOURCES = \
path_recode.c
path_serialize_SOURCES = \
path_serialize.c

149
tests/lib/vfs/path_recode.c Normal file
View File

@ -0,0 +1,149 @@
/* lib/vfs - vfs_path_t charset recode functions
Copyright (C) 2011 Free Software Foundation, Inc.
Written by:
Slava Zanko <slavazanko@gmail.com>, 2011
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License
as published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#define TEST_SUITE_NAME "/lib/vfs"
#include <check.h>
#include "lib/global.c"
#ifndef HAVE_CHARSET
#define HAVE_CHARSET 1
#endif
#include "lib/charsets.h"
#include "lib/strutil.h"
#include "lib/vfs/xdirentry.h"
#include "lib/vfs/path.h"
#include "src/vfs/local/local.c"
struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
static void
setup (void)
{
}
static void
teardown (void)
{
}
/* --------------------------------------------------------------------------------------------- */
#define path_recode_one_check(input, etalon1, etalon2) {\
vpath = vfs_path_from_str (input);\
element = vfs_path_get_by_index(vpath, -1);\
fail_unless ( strcmp (element->path, etalon1) == 0, "expected: %s\nactual: %s\n", etalon1, element->path);\
result = vfs_path_to_str(vpath);\
fail_unless ( strcmp (result, etalon2) == 0, "\nexpected: %s\nactual: %s\n", etalon2, result);\
g_free(result);\
vfs_path_free (vpath);\
}
START_TEST (test_path_recode_base_utf8)
{
vfs_path_t *vpath;
char *result;
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 ();
path_recode_one_check("/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ");
path_recode_one_check("/#enc:KOI8-R/ÑеÑ<C2B5>ÑовÑй/путь", "/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/#enc:KOI8-R/ÑеÑ<C2B5>ÑовÑй/путь");
free_codepages_list ();
str_uninit_strings ();
vfs_shut ();
}
END_TEST
START_TEST (test_path_recode_base_koi8r)
{
vfs_path_t *vpath;
char *result;
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 ();
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 ();
}
END_TEST
/* --------------------------------------------------------------------------------------------- */
int
main (void)
{
int number_failed;
Suite *s = suite_create (TEST_SUITE_NAME);
TCase *tc_core = tcase_create ("Core");
SRunner *sr;
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, test_path_recode_base_utf8);
tcase_add_test (tc_core, test_path_recode_base_koi8r);
/* *********************************** */
suite_add_tcase (s, tc_core);
sr = srunner_create (s);
srunner_set_log (sr, "path_recode.log");
srunner_run_all (sr, CK_NORMAL);
number_failed = srunner_ntests_failed (sr);
srunner_free (sr);
return (number_failed == 0) ? 0 : 1;
}
/* --------------------------------------------------------------------------------------------- */