mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 10:04:32 +03:00
Changes to handle vfs_path_t object:
* removed strip_password () function; * Added new vfs_path flag: VPF_HIDE_CHARSET; * added vfs_path_add_element() function. Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
18d8b06238
commit
2b5c28b316
105
lib/util.c
105
lib/util.c
@ -326,9 +326,15 @@ fake_name_quote (const char *s, int quote_percent)
|
|||||||
const char *
|
const char *
|
||||||
path_trunc (const char *path, size_t trunc_len)
|
path_trunc (const char *path, size_t trunc_len)
|
||||||
{
|
{
|
||||||
char *secure_path = strip_password (g_strdup (path), 1);
|
vfs_path_t *vpath;
|
||||||
|
char *secure_path;
|
||||||
|
const char *ret;
|
||||||
|
|
||||||
const char *ret = str_trunc (secure_path, trunc_len);
|
vpath = vfs_path_from_str (path);
|
||||||
|
secure_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_PASSWORD);
|
||||||
|
vfs_path_free (vpath);
|
||||||
|
|
||||||
|
ret = str_trunc (secure_path, trunc_len);
|
||||||
g_free (secure_path);
|
g_free (secure_path);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -564,101 +570,6 @@ string_perm (mode_t mode_bits)
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
/**
|
|
||||||
* p: string which might contain an url with a password (this parameter is
|
|
||||||
* modified in place).
|
|
||||||
* has_prefix = 0: The first parameter is an url without a prefix
|
|
||||||
* (user[:pass]@]machine[:port][remote-dir). Delete
|
|
||||||
* the password.
|
|
||||||
* has_prefix = 1: Search p for known url prefixes. If found delete
|
|
||||||
* the password from the url.
|
|
||||||
* Caveat: only the first url is found
|
|
||||||
*/
|
|
||||||
|
|
||||||
char *
|
|
||||||
strip_password (char *p, int has_prefix)
|
|
||||||
{
|
|
||||||
static const struct
|
|
||||||
{
|
|
||||||
const char *name;
|
|
||||||
size_t len;
|
|
||||||
} prefixes[] =
|
|
||||||
{
|
|
||||||
/* *INDENT-OFF* */
|
|
||||||
{ "/#ftp:", 6 },
|
|
||||||
{ "ftp://", 6 },
|
|
||||||
{ "/#smb:", 6 },
|
|
||||||
{ "smb://", 6 },
|
|
||||||
{ "/#sh:", 5 },
|
|
||||||
{ "sh://", 5 },
|
|
||||||
{ "ssh://", 6 }
|
|
||||||
/* *INDENT-ON* */
|
|
||||||
};
|
|
||||||
|
|
||||||
char *at, *inner_colon, *dir;
|
|
||||||
size_t i;
|
|
||||||
char *result = p;
|
|
||||||
|
|
||||||
for (i = 0; i < sizeof (prefixes) / sizeof (prefixes[0]); i++)
|
|
||||||
{
|
|
||||||
char *q;
|
|
||||||
|
|
||||||
if (has_prefix)
|
|
||||||
{
|
|
||||||
q = strstr (p, prefixes[i].name);
|
|
||||||
if (q == NULL)
|
|
||||||
continue;
|
|
||||||
else
|
|
||||||
p = q + prefixes[i].len;
|
|
||||||
}
|
|
||||||
|
|
||||||
dir = strchr (p, PATH_SEP);
|
|
||||||
if (dir != NULL)
|
|
||||||
*dir = '\0';
|
|
||||||
|
|
||||||
/* search for any possible user */
|
|
||||||
at = strrchr (p, '@');
|
|
||||||
|
|
||||||
if (dir)
|
|
||||||
*dir = PATH_SEP;
|
|
||||||
|
|
||||||
/* We have a username */
|
|
||||||
if (at)
|
|
||||||
{
|
|
||||||
inner_colon = memchr (p, ':', at - p);
|
|
||||||
if (inner_colon)
|
|
||||||
memmove (inner_colon, at, strlen (at) + 1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
const char *
|
|
||||||
strip_home_and_password (const char *dir)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
static char newdir[MC_MAXPATHLEN];
|
|
||||||
|
|
||||||
len = strlen (mc_config_get_home_dir ());
|
|
||||||
if (mc_config_get_home_dir () != NULL && strncmp (dir, mc_config_get_home_dir (), len) == 0 &&
|
|
||||||
(dir[len] == PATH_SEP || dir[len] == '\0'))
|
|
||||||
{
|
|
||||||
newdir[0] = '~';
|
|
||||||
g_strlcpy (&newdir[1], &dir[len], sizeof (newdir) - 1);
|
|
||||||
return newdir;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We do not strip homes in /#ftp tree, I do not like ~'s there
|
|
||||||
(see ftpfs.c why) */
|
|
||||||
g_strlcpy (newdir, dir, sizeof (newdir));
|
|
||||||
strip_password (newdir, 1);
|
|
||||||
return newdir;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@ -109,12 +109,6 @@ const char *size_trunc_sep (uintmax_t size, gboolean use_si);
|
|||||||
void size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gboolean use_si);
|
void size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gboolean use_si);
|
||||||
const char *string_perm (mode_t mode_bits);
|
const char *string_perm (mode_t mode_bits);
|
||||||
|
|
||||||
/* @modifies path. @returns pointer into path. */
|
|
||||||
char *strip_password (char *path, int has_prefix);
|
|
||||||
|
|
||||||
/* @returns a pointer into a static buffer. */
|
|
||||||
const char *strip_home_and_password (const char *dir);
|
|
||||||
|
|
||||||
const char *extension (const char *);
|
const char *extension (const char *);
|
||||||
const char *unix_error_string (int error_num);
|
const char *unix_error_string (int error_num);
|
||||||
const char *skip_separators (const char *s);
|
const char *skip_separators (const char *s);
|
||||||
|
@ -634,10 +634,13 @@ vfs_path_to_str_flags (const vfs_path_t * vpath, int elements_count, vfs_path_fl
|
|||||||
|
|
||||||
if ((flags & VPF_RECODE) == 0 && vfs_path_element_need_cleanup_converter (element))
|
if ((flags & VPF_RECODE) == 0 && vfs_path_element_need_cleanup_converter (element))
|
||||||
{
|
{
|
||||||
if (buffer->str[buffer->len - 1] != PATH_SEP)
|
if ((flags & VPF_HIDE_CHARSET) == 0)
|
||||||
g_string_append (buffer, PATH_SEP_STR);
|
{
|
||||||
g_string_append (buffer, VFS_ENCODING_PREFIX);
|
if (buffer->len == 0 || buffer->str[buffer->len - 1] != PATH_SEP)
|
||||||
g_string_append (buffer, element->encoding);
|
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);
|
str_vfs_convert_from (element->dir.converter, element->path, recode_buffer);
|
||||||
vfs_append_from_path (recode_buffer->str);
|
vfs_append_from_path (recode_buffer->str);
|
||||||
g_string_set_size (recode_buffer, 0);
|
g_string_set_size (recode_buffer, 0);
|
||||||
@ -769,6 +772,19 @@ vfs_path_elements_count (const vfs_path_t * vpath)
|
|||||||
return (vpath != NULL && vpath->path != NULL) ? vpath->path->len : 0;
|
return (vpath != NULL && vpath->path != NULL) ? vpath->path->len : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Add vfs_path_element_t object to end of list in vfs_path_t object
|
||||||
|
* @param vpath pointer to vfs_path_t object
|
||||||
|
* @param path_element pointer to vfs_path_element_t object
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
vfs_path_add_element (const vfs_path_t * vpath, const vfs_path_element_t * path_element)
|
||||||
|
{
|
||||||
|
g_array_append_val (vpath->path, path_element);
|
||||||
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/*
|
/*
|
||||||
* Get one path element by index.
|
* Get one path element by index.
|
||||||
|
@ -14,7 +14,8 @@ typedef enum
|
|||||||
VPF_USE_DEPRECATED_PARSER = 1 << 1,
|
VPF_USE_DEPRECATED_PARSER = 1 << 1,
|
||||||
VPF_RECODE = 1 << 2,
|
VPF_RECODE = 1 << 2,
|
||||||
VPF_STRIP_HOME = 1 << 3,
|
VPF_STRIP_HOME = 1 << 3,
|
||||||
VPF_STRIP_PASSWORD = 1 << 4
|
VPF_STRIP_PASSWORD = 1 << 4,
|
||||||
|
VPF_HIDE_CHARSET = 1 << 5
|
||||||
} vfs_path_flag_t;
|
} vfs_path_flag_t;
|
||||||
|
|
||||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
@ -68,6 +69,7 @@ size_t vfs_path_tokens_count (const vfs_path_t *);
|
|||||||
char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
|
char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
|
||||||
vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
|
vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
|
||||||
|
|
||||||
|
void vfs_path_add_element (const vfs_path_t * vpath, const vfs_path_element_t * path_element);
|
||||||
vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
|
vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
|
||||||
vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);
|
vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);
|
||||||
void vfs_path_element_free (vfs_path_element_t * element);
|
void vfs_path_element_free (vfs_path_element_t * element);
|
||||||
|
@ -237,14 +237,19 @@ push_history (WInput * in, const char *text)
|
|||||||
if (in->history_name != NULL)
|
if (in->history_name != NULL)
|
||||||
{
|
{
|
||||||
/* FIXME: It is the strange code. Rewrite is needed. */
|
/* FIXME: It is the strange code. Rewrite is needed. */
|
||||||
|
|
||||||
const char *p = in->history_name + 3;
|
const char *p = in->history_name + 3;
|
||||||
|
|
||||||
for (i = 0; i < ELEMENTS; i++)
|
for (i = 0; i < ELEMENTS; i++)
|
||||||
if (strcmp (p, password_input_fields[i]) == 0)
|
if (strcmp (p, password_input_fields[i]) == 0)
|
||||||
break;
|
{
|
||||||
|
vfs_path_t *vpath;
|
||||||
|
|
||||||
strip_password (t, i >= ELEMENTS);
|
vpath = vfs_path_from_str (t);
|
||||||
|
g_free (t);
|
||||||
|
t = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_PASSWORD);
|
||||||
|
vfs_path_free (vpath);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in->history == NULL || in->history->data == NULL || strcmp (in->history->data, t) != 0 ||
|
if (in->history == NULL || in->history->data == NULL || strcmp (in->history->data, t) != 0 ||
|
||||||
|
@ -2718,6 +2718,8 @@ dview_status (const WDiff * dview, int ord, int width, int c)
|
|||||||
const char *buf;
|
const char *buf;
|
||||||
int filename_width;
|
int filename_width;
|
||||||
int linenum, lineofs;
|
int linenum, lineofs;
|
||||||
|
vfs_path_t *vpath;
|
||||||
|
char *path;
|
||||||
|
|
||||||
tty_setcolor (STATUSBAR_COLOR);
|
tty_setcolor (STATUSBAR_COLOR);
|
||||||
|
|
||||||
@ -2728,12 +2730,16 @@ dview_status (const WDiff * dview, int ord, int width, int c)
|
|||||||
if (filename_width < 8)
|
if (filename_width < 8)
|
||||||
filename_width = 8;
|
filename_width = 8;
|
||||||
|
|
||||||
buf = str_term_trim (strip_home_and_password (dview->label[ord]), filename_width);
|
vpath = vfs_path_from_str (dview->label[ord]);
|
||||||
|
path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
|
||||||
|
vfs_path_free (vpath);
|
||||||
|
buf = str_term_trim (path, filename_width);
|
||||||
if (ord == 0)
|
if (ord == 0)
|
||||||
tty_printf ("%-*s %6d+%-4d Col %-4d ", filename_width, buf, linenum, lineofs,
|
tty_printf ("%-*s %6d+%-4d Col %-4d ", filename_width, buf, linenum, lineofs,
|
||||||
dview->skip_cols);
|
dview->skip_cols);
|
||||||
else
|
else
|
||||||
tty_printf ("%-*s %6d+%-4d Dif %-4d ", filename_width, buf, linenum, lineofs, dview->ndiff);
|
tty_printf ("%-*s %6d+%-4d Dif %-4d ", filename_width, buf, linenum, lineofs, dview->ndiff);
|
||||||
|
g_free (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -1693,17 +1693,18 @@ dirsizes_cmd (void)
|
|||||||
void
|
void
|
||||||
save_setup_cmd (void)
|
save_setup_cmd (void)
|
||||||
{
|
{
|
||||||
char *d1;
|
vfs_path_t *vpath;
|
||||||
const char *d2;
|
char *path;
|
||||||
|
|
||||||
d1 = mc_config_get_full_path (MC_CONFIG_FILE);
|
vpath = mc_config_get_full_vpath (MC_CONFIG_FILE);
|
||||||
d2 = strip_home_and_password (d1);
|
path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME);
|
||||||
g_free (d1);
|
vfs_path_free (vpath);
|
||||||
|
|
||||||
if (save_setup (TRUE, TRUE))
|
if (save_setup (TRUE, TRUE))
|
||||||
message (D_NORMAL, _("Setup"), _("Setup saved to %s"), d2);
|
message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
|
||||||
else
|
else
|
||||||
message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), d2);
|
message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
|
||||||
|
g_free (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -436,9 +436,10 @@ do_cd_command (char *orig_cmd)
|
|||||||
{
|
{
|
||||||
char *d;
|
char *d;
|
||||||
|
|
||||||
d = strip_password (path, 1);
|
d = vfs_path_to_str_flags (q_vpath, 0, VPF_STRIP_PASSWORD);
|
||||||
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), d,
|
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), d,
|
||||||
unix_error_string (errno));
|
unix_error_string (errno));
|
||||||
|
g_free (d);
|
||||||
}
|
}
|
||||||
|
|
||||||
vfs_path_free (q_vpath);
|
vfs_path_free (q_vpath);
|
||||||
|
@ -341,9 +341,10 @@ overwrite_query_dialog (FileOpContext * ctx, enum OperationMode mode)
|
|||||||
|
|
||||||
char buffer[BUF_SMALL];
|
char buffer[BUF_SMALL];
|
||||||
const char *title;
|
const char *title;
|
||||||
const char *stripped_name = strip_home_and_password (ui->replace_filename);
|
|
||||||
int stripped_name_len;
|
int stripped_name_len;
|
||||||
|
vfs_path_t *stripped_vpath;
|
||||||
|
const char *stripped_name;
|
||||||
|
char *stripped_name_orig;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
widgets_len = g_new0 (int, num);
|
widgets_len = g_new0 (int, num);
|
||||||
@ -353,6 +354,10 @@ overwrite_query_dialog (FileOpContext * ctx, enum OperationMode mode)
|
|||||||
else
|
else
|
||||||
title = _("Background process: File exists");
|
title = _("Background process: File exists");
|
||||||
|
|
||||||
|
stripped_vpath = vfs_path_from_str (ui->replace_filename);
|
||||||
|
stripped_name = stripped_name_orig =
|
||||||
|
vfs_path_to_str_flags (stripped_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
|
||||||
|
vfs_path_free (stripped_vpath);
|
||||||
stripped_name_len = str_term_width1 (stripped_name);
|
stripped_name_len = str_term_width1 (stripped_name);
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -454,6 +459,7 @@ overwrite_query_dialog (FileOpContext * ctx, enum OperationMode mode)
|
|||||||
destroy_dlg (ui->replace_dlg);
|
destroy_dlg (ui->replace_dlg);
|
||||||
|
|
||||||
g_free (widgets_len);
|
g_free (widgets_len);
|
||||||
|
g_free (stripped_name_orig);
|
||||||
|
|
||||||
return (result == B_CANCEL) ? REPLACE_ABORT : (replace_action_t) result;
|
return (result == B_CANCEL) ? REPLACE_ABORT : (replace_action_t) result;
|
||||||
#undef ADD_RD_LABEL
|
#undef ADD_RD_LABEL
|
||||||
@ -1060,7 +1066,13 @@ file_mask_dialog (FileOpContext * ctx, FileOperation operation,
|
|||||||
ctx->op_preserve = filegui__check_attrs_on_fs (def_text);
|
ctx->op_preserve = filegui__check_attrs_on_fs (def_text);
|
||||||
|
|
||||||
/* filter out a possible password from def_text */
|
/* filter out a possible password from def_text */
|
||||||
tmp = strip_password (g_strdup (def_text), 1);
|
{
|
||||||
|
vfs_path_t *vpath;
|
||||||
|
|
||||||
|
vpath = vfs_path_from_str (def_text);
|
||||||
|
tmp = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_PASSWORD);
|
||||||
|
vfs_path_free (vpath);
|
||||||
|
}
|
||||||
if (source_easy_patterns)
|
if (source_easy_patterns)
|
||||||
def_text_secure = strutils_glob_escape (tmp);
|
def_text_secure = strutils_glob_escape (tmp);
|
||||||
else
|
else
|
||||||
|
@ -1092,7 +1092,7 @@ add_new_entry_cmd (void)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Take current directory as default value for input fields */
|
/* Take current directory as default value for input fields */
|
||||||
to_free = title = url = strip_password (vfs_path_to_str (current_panel->cwd_vpath), 1);
|
to_free = title = url = vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_PASSWORD);
|
||||||
|
|
||||||
ret = add_new_entry_input (_("New hotlist entry"), _("Directory label:"),
|
ret = add_new_entry_input (_("New hotlist entry"), _("Directory label:"),
|
||||||
_("Directory path:"), "[Hotlist]", &title, &url);
|
_("Directory path:"), "[Hotlist]", &title, &url);
|
||||||
@ -1694,19 +1694,18 @@ add_dotdot_to_list (void)
|
|||||||
void
|
void
|
||||||
add2hotlist_cmd (void)
|
add2hotlist_cmd (void)
|
||||||
{
|
{
|
||||||
char *lc_prompt, *label;
|
char *lc_prompt;
|
||||||
const char *cp = N_("Label for \"%s\":");
|
const char *cp = N_("Label for \"%s\":");
|
||||||
int l;
|
int l;
|
||||||
char *label_string;
|
char *label_string, *label;
|
||||||
|
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
cp = _(cp);
|
cp = _(cp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
l = str_term_width1 (cp);
|
l = str_term_width1 (cp);
|
||||||
label_string = vfs_path_to_str (current_panel->cwd_vpath);
|
label_string = vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_PASSWORD);
|
||||||
lc_prompt = g_strdup_printf (cp, path_trunc (label_string, COLS - 2 * UX - (l + 8)));
|
lc_prompt = g_strdup_printf (cp, str_trunc (label_string, COLS - 2 * UX - (l + 8)));
|
||||||
strip_password (label_string, 1);
|
|
||||||
label = input_dialog (_("Add to hotlist"), lc_prompt, MC_HISTORY_HOTLIST_ADD, label_string);
|
label = input_dialog (_("Add to hotlist"), lc_prompt, MC_HISTORY_HOTLIST_ADD, label_string);
|
||||||
g_free (lc_prompt);
|
g_free (lc_prompt);
|
||||||
|
|
||||||
@ -1718,6 +1717,7 @@ add2hotlist_cmd (void)
|
|||||||
}
|
}
|
||||||
add2hotlist (label, label_string, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END);
|
add2hotlist (label, label_string, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END);
|
||||||
hotlist_state.modified = 1;
|
hotlist_state.modified = 1;
|
||||||
|
g_free (label_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -431,18 +431,18 @@ midnight_get_title (const Dlg_head * h, size_t len)
|
|||||||
{
|
{
|
||||||
/* TODO: share code with update_xterm_title_path() */
|
/* TODO: share code with update_xterm_title_path() */
|
||||||
|
|
||||||
const char *path;
|
char *path_origin, *p;
|
||||||
|
char *path;
|
||||||
char host[BUF_TINY];
|
char host[BUF_TINY];
|
||||||
char *p;
|
|
||||||
struct passwd *pw = NULL;
|
struct passwd *pw = NULL;
|
||||||
char *login = NULL;
|
char *login = NULL;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
(void) h;
|
(void) h;
|
||||||
|
|
||||||
p = vfs_path_to_str (current_panel->cwd_vpath);
|
path_origin =
|
||||||
path = strip_home_and_password (p);
|
vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
|
||||||
g_free (p);
|
|
||||||
res = gethostname (host, sizeof (host));
|
res = gethostname (host, sizeof (host));
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
host[0] = '\0';
|
host[0] = '\0';
|
||||||
@ -455,12 +455,13 @@ midnight_get_title (const Dlg_head * h, size_t len)
|
|||||||
else
|
else
|
||||||
login = g_strdup (host);
|
login = g_strdup (host);
|
||||||
|
|
||||||
p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
|
p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path_origin);
|
||||||
path = str_trunc (p, len - 4);
|
g_free (path_origin);
|
||||||
|
path = g_strdup (str_trunc (p, len - 4));
|
||||||
g_free (login);
|
g_free (login);
|
||||||
g_free (p);
|
g_free (p);
|
||||||
|
|
||||||
return g_strdup (path);
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -1156,37 +1156,19 @@ show_free_space (WPanel * panel)
|
|||||||
static char *
|
static char *
|
||||||
panel_correct_path_to_show (WPanel * panel)
|
panel_correct_path_to_show (WPanel * panel)
|
||||||
{
|
{
|
||||||
|
vfs_path_t *last_vpath;
|
||||||
const vfs_path_element_t *path_element;
|
const vfs_path_element_t *path_element;
|
||||||
GString *ret_str;
|
char *return_path;
|
||||||
|
|
||||||
path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
|
last_vpath = vfs_path_new ();
|
||||||
ret_str = g_string_new ("");
|
path_element = vfs_path_element_clone (vfs_path_get_by_index (panel->cwd_vpath, -1));
|
||||||
|
vfs_path_add_element (last_vpath, path_element);
|
||||||
|
return_path =
|
||||||
|
vfs_path_to_str_flags (last_vpath, 0,
|
||||||
|
VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET);
|
||||||
|
vfs_path_free (last_vpath);
|
||||||
|
|
||||||
if ((path_element->class->flags & VFSF_LOCAL) == 0)
|
return return_path;
|
||||||
{
|
|
||||||
char *url_str;
|
|
||||||
|
|
||||||
g_string_append (ret_str, path_element->vfs_prefix);
|
|
||||||
g_string_append (ret_str, VFS_PATH_URL_DELIMITER);
|
|
||||||
|
|
||||||
url_str = vfs_path_build_url_params_str (path_element, FALSE);
|
|
||||||
if (*url_str != '\0')
|
|
||||||
{
|
|
||||||
g_string_append (ret_str, url_str);
|
|
||||||
g_string_append_c (ret_str, PATH_SEP);
|
|
||||||
}
|
|
||||||
g_free (url_str);
|
|
||||||
g_string_append (ret_str, path_element->path);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char *tmp_path;
|
|
||||||
|
|
||||||
tmp_path = g_strdup (path_element->path);
|
|
||||||
g_string_append (ret_str, strip_home_and_password (tmp_path));
|
|
||||||
g_free (tmp_path);
|
|
||||||
}
|
|
||||||
return g_string_free (ret_str, FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -3365,7 +3347,7 @@ panel_callback (Widget * w, widget_msg_t msg, int parm)
|
|||||||
{
|
{
|
||||||
char *cwd;
|
char *cwd;
|
||||||
|
|
||||||
cwd = strip_password (vfs_path_to_str (panel->cwd_vpath), 1);
|
cwd = vfs_path_to_str_flags (panel->cwd_vpath, 0, VPF_STRIP_PASSWORD);
|
||||||
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"),
|
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"),
|
||||||
cwd, unix_error_string (errno));
|
cwd, unix_error_string (errno));
|
||||||
g_free (cwd);
|
g_free (cwd);
|
||||||
@ -4556,11 +4538,12 @@ update_panels (panel_update_flags_t flags, const char *current_file)
|
|||||||
void
|
void
|
||||||
directory_history_add (struct WPanel *panel, const char *dir)
|
directory_history_add (struct WPanel *panel, const char *dir)
|
||||||
{
|
{
|
||||||
|
vfs_path_t *vpath;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
tmp = g_strdup (dir);
|
vpath = vfs_path_from_str (dir);
|
||||||
strip_password (tmp, 1);
|
tmp = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_PASSWORD);
|
||||||
|
vfs_path_free (vpath);
|
||||||
panel->dir_history = list_append_unique (panel->dir_history, tmp);
|
panel->dir_history = list_append_unique (panel->dir_history, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
61
src/main.c
61
src/main.c
@ -340,46 +340,43 @@ update_xterm_title_path (void)
|
|||||||
{
|
{
|
||||||
/* TODO: share code with midnight_get_title () */
|
/* TODO: share code with midnight_get_title () */
|
||||||
|
|
||||||
const char *path;
|
char *path;
|
||||||
char host[BUF_TINY];
|
char host[BUF_TINY];
|
||||||
char *p;
|
char *p;
|
||||||
struct passwd *pw = NULL;
|
struct passwd *pw = NULL;
|
||||||
char *login = NULL;
|
char *login = NULL;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
if (mc_global.tty.xterm_flag && xterm_title)
|
if (!(mc_global.tty.xterm_flag && xterm_title))
|
||||||
{
|
return;
|
||||||
char *path_str;
|
|
||||||
|
|
||||||
path_str = vfs_path_to_str (current_panel->cwd_vpath);
|
path = vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
|
||||||
path = strip_home_and_password (path_str);
|
res = gethostname (host, sizeof (host));
|
||||||
g_free (path_str);
|
if (res)
|
||||||
res = gethostname (host, sizeof (host));
|
{ /* On success, res = 0 */
|
||||||
if (res)
|
host[0] = '\0';
|
||||||
{ /* On success, res = 0 */
|
|
||||||
host[0] = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
host[sizeof (host) - 1] = '\0';
|
|
||||||
}
|
|
||||||
pw = getpwuid (getuid ());
|
|
||||||
if (pw)
|
|
||||||
{
|
|
||||||
login = g_strdup_printf ("%s@%s", pw->pw_name, host);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
login = g_strdup (host);
|
|
||||||
}
|
|
||||||
p = g_strdup_printf ("mc [%s]:%s", login, path);
|
|
||||||
fprintf (stdout, "\33]0;%s\7", str_term_form (p));
|
|
||||||
g_free (login);
|
|
||||||
g_free (p);
|
|
||||||
if (!mc_global.tty.alternate_plus_minus)
|
|
||||||
numeric_keypad_mode ();
|
|
||||||
(void) fflush (stdout);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
host[sizeof (host) - 1] = '\0';
|
||||||
|
}
|
||||||
|
pw = getpwuid (getuid ());
|
||||||
|
if (pw)
|
||||||
|
{
|
||||||
|
login = g_strdup_printf ("%s@%s", pw->pw_name, host);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
login = g_strdup (host);
|
||||||
|
}
|
||||||
|
p = g_strdup_printf ("mc [%s]:%s", login, path);
|
||||||
|
fprintf (stdout, "\33]0;%s\7", str_term_form (p));
|
||||||
|
g_free (login);
|
||||||
|
g_free (p);
|
||||||
|
if (!mc_global.tty.alternate_plus_minus)
|
||||||
|
numeric_keypad_mode ();
|
||||||
|
(void) fflush (stdout);
|
||||||
|
g_free (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -1170,13 +1170,11 @@ subshell_name_quote (const char *s)
|
|||||||
void
|
void
|
||||||
do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt, gboolean reset_prompt)
|
do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt, gboolean reset_prompt)
|
||||||
{
|
{
|
||||||
char *pcwd, *cwd_str;
|
char *pcwd;
|
||||||
char *temp;
|
char *temp;
|
||||||
char *directory;
|
char *directory;
|
||||||
|
|
||||||
cwd_str = vfs_path_to_str (current_panel->cwd_vpath);
|
pcwd = vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_RECODE);
|
||||||
pcwd = vfs_translate_path_n (cwd_str);
|
|
||||||
g_free (cwd_str);
|
|
||||||
|
|
||||||
if (!(subshell_state == INACTIVE && strcmp (subshell_cwd, pcwd) != 0))
|
if (!(subshell_state == INACTIVE && strcmp (subshell_cwd, pcwd) != 0))
|
||||||
{
|
{
|
||||||
@ -1250,9 +1248,11 @@ do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt, gboolean re
|
|||||||
bPathNotEq = strcmp (p_subshell_cwd, p_current_panel_cwd);
|
bPathNotEq = strcmp (p_subshell_cwd, p_current_panel_cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bPathNotEq && strcmp (pcwd, "."))
|
if (bPathNotEq && strcmp (pcwd, ".") != 0)
|
||||||
{
|
{
|
||||||
char *cwd = strip_password (g_strdup (pcwd), 1);
|
char *cwd;
|
||||||
|
|
||||||
|
cwd = vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_PASSWORD);
|
||||||
vfs_print_message (_("Warning: Cannot change to %s.\n"), cwd);
|
vfs_print_message (_("Warning: Cannot change to %s.\n"), cwd);
|
||||||
g_free (cwd);
|
g_free (cwd);
|
||||||
}
|
}
|
||||||
|
@ -185,6 +185,9 @@ START_TEST(test_path_to_str_flags)
|
|||||||
str_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
|
str_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
|
||||||
fail_unless (strcmp ("~/test1://user@host.name/#enc:KOI8-R/теÑ<C2B5>товый/путь", str_path) == 0, "\nstr=%s\n", str_path);
|
fail_unless (strcmp ("~/test1://user@host.name/#enc:KOI8-R/теÑ<C2B5>товый/путь", str_path) == 0, "\nstr=%s\n", str_path);
|
||||||
g_free (str_path);
|
g_free (str_path);
|
||||||
|
str_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET);
|
||||||
|
fail_unless (strcmp ("~/test1://user@host.name/тестовый/путь", str_path) == 0, "\nstr=%s\n", str_path);
|
||||||
|
g_free (str_path);
|
||||||
str_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME | VPF_RECODE);
|
str_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME | VPF_RECODE);
|
||||||
fail_unless (strcmp ("~/test1://user:passwd@host.name/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", str_path) == 0, "\nstr=%s\n", str_path);
|
fail_unless (strcmp ("~/test1://user:passwd@host.name/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", str_path) == 0, "\nstr=%s\n", str_path);
|
||||||
g_free (str_path);
|
g_free (str_path);
|
||||||
|
Loading…
Reference in New Issue
Block a user