mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
changed interface of function mc_chdir() for handle vfs_path_t object as parameter
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
19201165a2
commit
aecdc1a32e
@ -698,20 +698,20 @@ mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* VFS chdir.
|
||||
* Return 0 on success, -1 on failure.
|
||||
*
|
||||
* @param vpath VFS-path
|
||||
*
|
||||
* @return 0 on success, -1 on failure.
|
||||
*/
|
||||
|
||||
int
|
||||
mc_chdir (const char *path)
|
||||
mc_chdir (const vfs_path_t * vpath)
|
||||
{
|
||||
struct vfs_class *old_vfs;
|
||||
vfsid old_vfsid;
|
||||
int result;
|
||||
vfs_path_t *vpath;
|
||||
vfs_path_element_t *path_element;
|
||||
|
||||
vpath = vfs_path_from_str (path);
|
||||
|
||||
if (vpath == NULL)
|
||||
return -1;
|
||||
|
||||
@ -719,7 +719,6 @@ mc_chdir (const char *path)
|
||||
|
||||
if (!vfs_path_element_valid (path_element) || path_element->class->chdir == NULL)
|
||||
{
|
||||
vfs_path_free (vpath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -728,7 +727,6 @@ mc_chdir (const char *path)
|
||||
if (result == -1)
|
||||
{
|
||||
errno = vfs_ferrno (path_element->class);
|
||||
vfs_path_free (vpath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -736,7 +734,7 @@ mc_chdir (const char *path)
|
||||
old_vfs = current_vfs;
|
||||
|
||||
/* Actually change directory */
|
||||
vfs_set_raw_current_dir (vpath);
|
||||
vfs_set_raw_current_dir (vfs_path_clone (vpath));
|
||||
current_vfs = path_element->class;
|
||||
|
||||
/* This function uses the new current_dir implicitly */
|
||||
|
@ -295,7 +295,7 @@ int mc_symlink (const char *name1, const char *name2);
|
||||
int mc_rename (const char *original, const char *target);
|
||||
int mc_chmod (const char *path, mode_t mode);
|
||||
int mc_chown (const char *path, uid_t owner, gid_t group);
|
||||
int mc_chdir (const char *path);
|
||||
int mc_chdir (const vfs_path_t * vpath);
|
||||
int mc_unlink (const char *path);
|
||||
int mc_ctl (int fd, int ctlop, void *arg);
|
||||
int mc_setctl (const char *path, int ctlop, void *arg);
|
||||
|
@ -197,9 +197,13 @@ do_execute (const char *lc_shell, const char *command, int flags)
|
||||
|
||||
#endif /* HAVE_SUBSHELL_SUPPORT */
|
||||
|
||||
if (old_vfs_dir)
|
||||
if (old_vfs_dir != NULL)
|
||||
{
|
||||
mc_chdir (old_vfs_dir);
|
||||
vfs_path_t *vpath;
|
||||
|
||||
vpath = vfs_path_from_str (old_vfs_dir);
|
||||
mc_chdir (vpath);
|
||||
vfs_path_free (vpath);
|
||||
g_free (old_vfs_dir);
|
||||
}
|
||||
|
||||
|
@ -2666,11 +2666,19 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
|
||||
/* We now have ETA in all cases */
|
||||
|
||||
/* One file: FIXME mc_chdir will take user out of any vfs */
|
||||
if ((operation != OP_COPY) && (get_current_type () == view_tree) &&
|
||||
(mc_chdir (PATH_SEP_STR) < 0))
|
||||
if ((operation != OP_COPY) && (get_current_type () == view_tree))
|
||||
{
|
||||
ret_val = FALSE;
|
||||
goto clean_up;
|
||||
vfs_path_t *vpath;
|
||||
int chdir_retcode;
|
||||
|
||||
vpath = vfs_path_from_str (PATH_SEP_STR);
|
||||
chdir_retcode = mc_chdir (vpath);
|
||||
vfs_path_free (vpath);
|
||||
if (chdir_retcode < 0)
|
||||
{
|
||||
ret_val = FALSE;
|
||||
goto clean_up;
|
||||
}
|
||||
}
|
||||
|
||||
/* The source and src_stat variables have been initialized before */
|
||||
|
@ -609,6 +609,8 @@ create_panels (void)
|
||||
/* Creates the left panel */
|
||||
if (mc_run_param0 != NULL)
|
||||
{
|
||||
vfs_path_t *vpath;
|
||||
|
||||
if (mc_run_param1 != NULL)
|
||||
{
|
||||
/* Ok, user has specified two dirs, save the original one,
|
||||
@ -617,16 +619,21 @@ create_panels (void)
|
||||
*/
|
||||
mc_get_current_wd (original_dir, sizeof (original_dir) - 2);
|
||||
}
|
||||
mc_chdir (mc_run_param0);
|
||||
vpath = vfs_path_from_str (mc_run_param0);
|
||||
mc_chdir (vpath);
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
set_display_type (current_index, current_mode);
|
||||
|
||||
/* The other panel */
|
||||
if (mc_run_param1 != NULL)
|
||||
{
|
||||
if (original_dir[0] != '\0')
|
||||
mc_chdir (original_dir);
|
||||
mc_chdir (mc_run_param1);
|
||||
const char *cd_dir = (original_dir != NULL) ? original_dir : mc_run_param1;
|
||||
vfs_path_t *vpath;
|
||||
|
||||
vpath = vfs_path_from_str (cd_dir);
|
||||
mc_chdir (vpath);
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
set_display_type (other_index, other_mode);
|
||||
|
||||
@ -843,12 +850,15 @@ setup_mc (void)
|
||||
static void
|
||||
setup_dummy_mc (void)
|
||||
{
|
||||
vfs_path_t *vpath;
|
||||
char d[MC_MAXPATHLEN];
|
||||
int ret;
|
||||
|
||||
mc_get_current_wd (d, MC_MAXPATHLEN);
|
||||
setup_mc ();
|
||||
ret = mc_chdir (d);
|
||||
vpath = vfs_path_from_str (d);
|
||||
ret = mc_chdir (vpath);
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -80,7 +80,7 @@
|
||||
/* The hook list for the select file function */
|
||||
hook_t *select_file_hook = NULL;
|
||||
|
||||
panelized_panel_t panelized_panel = { {NULL, 0}, -1, {'\0'} };
|
||||
panelized_panel_t panelized_panel = { { NULL, 0 }, -1, { '\0' } };
|
||||
|
||||
static const char *string_file_name (file_entry *, int);
|
||||
static const char *string_file_size (file_entry *, int);
|
||||
@ -1104,8 +1104,8 @@ show_dir (WPanel * panel)
|
||||
tty_printf (" %s ", _("Panelize"));
|
||||
else
|
||||
tty_printf (" %s ",
|
||||
str_term_trim (strip_home_and_password (panel->cwd),
|
||||
min (max (panel->widget.cols - 12, 0), panel->widget.cols)));
|
||||
str_term_trim (strip_home_and_password (panel->cwd),
|
||||
min (max (panel->widget.cols - 12, 0), panel->widget.cols)));
|
||||
|
||||
if (!panels_options.show_mini_info)
|
||||
{
|
||||
@ -2736,7 +2736,7 @@ subshell_chdir (const char *directory)
|
||||
static gboolean
|
||||
_do_panel_cd (WPanel * panel, const char *new_dir, enum cd_enum cd_type)
|
||||
{
|
||||
const char *directory;
|
||||
vfs_path_t *vpath;
|
||||
char *olddir;
|
||||
char temp[MC_MAXPATHLEN];
|
||||
|
||||
@ -2758,14 +2758,16 @@ _do_panel_cd (WPanel * panel, const char *new_dir, enum cd_enum cd_type)
|
||||
new_dir = temp;
|
||||
}
|
||||
}
|
||||
directory = *new_dir ? new_dir : mc_config_get_home_dir ();
|
||||
vpath = vfs_path_from_str (*new_dir ? new_dir : mc_config_get_home_dir ());
|
||||
|
||||
if (mc_chdir (directory) == -1)
|
||||
if (mc_chdir (vpath) == -1)
|
||||
{
|
||||
strcpy (panel->cwd, olddir);
|
||||
g_free (olddir);
|
||||
vfs_path_free (vpath);
|
||||
return FALSE;
|
||||
}
|
||||
vfs_path_free (vpath);
|
||||
|
||||
/* Success: save previous directory, shutdown status of previous dir */
|
||||
strcpy (panel->lwd, olddir);
|
||||
@ -3050,6 +3052,7 @@ panel_key (WPanel * panel, int key)
|
||||
static cb_ret_t
|
||||
panel_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
{
|
||||
vfs_path_t *vpath;
|
||||
WPanel *panel = (WPanel *) w;
|
||||
WButtonBar *bb;
|
||||
|
||||
@ -3075,7 +3078,8 @@ panel_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
state_mark = -1;
|
||||
current_panel = panel;
|
||||
panel->active = 1;
|
||||
if (mc_chdir (panel->cwd) != 0)
|
||||
vpath = vfs_path_from_str (panel->cwd);
|
||||
if (mc_chdir (vpath) != 0)
|
||||
{
|
||||
char *cwd = strip_password (g_strdup (panel->cwd), 1);
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"),
|
||||
@ -3085,6 +3089,7 @@ panel_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
else
|
||||
subshell_chdir (panel->cwd);
|
||||
|
||||
vfs_path_free (vpath);
|
||||
update_xterm_title_path ();
|
||||
select_item (panel);
|
||||
show_dir (panel);
|
||||
@ -3383,7 +3388,11 @@ reload_panelized (WPanel * panel)
|
||||
if (panel != current_panel)
|
||||
{
|
||||
int ret;
|
||||
ret = mc_chdir (panel->cwd);
|
||||
vfs_path_t *vpath;
|
||||
|
||||
vpath = vfs_path_from_str (panel->cwd);
|
||||
ret = mc_chdir (vpath);
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
|
||||
for (i = 0, j = 0; i < panel->count; i++)
|
||||
@ -3417,7 +3426,11 @@ reload_panelized (WPanel * panel)
|
||||
if (panel != current_panel)
|
||||
{
|
||||
int ret;
|
||||
ret = mc_chdir (current_panel->cwd);
|
||||
vfs_path_t *vpath;
|
||||
|
||||
vpath = vfs_path_from_str (current_panel->cwd);
|
||||
ret = mc_chdir (vpath);
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3774,10 +3787,16 @@ panel_new_with_dir (const char *panel_name, const char *wpath)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (mc_chdir (panel->cwd) != 0)
|
||||
{
|
||||
panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
|
||||
mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
|
||||
vfs_path_t *vpath;
|
||||
|
||||
vpath = vfs_path_from_str (panel->cwd);
|
||||
if (mc_chdir (vpath) != 0)
|
||||
{
|
||||
panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
|
||||
mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
|
||||
}
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
|
||||
/* Load the default format */
|
||||
@ -3788,7 +3807,13 @@ panel_new_with_dir (const char *panel_name, const char *wpath)
|
||||
|
||||
/* Restore old right path */
|
||||
if (curdir[0] != '\0')
|
||||
err = mc_chdir (curdir);
|
||||
{
|
||||
vfs_path_t *vpath;
|
||||
|
||||
vpath = vfs_path_from_str (curdir);
|
||||
err = mc_chdir (vpath);
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
|
||||
return panel;
|
||||
}
|
||||
@ -3805,10 +3830,18 @@ panel_reload (WPanel * panel)
|
||||
&& current_stat.st_mtime == panel->dir_stat.st_mtime)
|
||||
return;
|
||||
|
||||
while (mc_chdir (panel->cwd) == -1)
|
||||
do
|
||||
{
|
||||
vfs_path_t *vpath;
|
||||
gboolean ok;
|
||||
char *last_slash;
|
||||
|
||||
vpath = vfs_path_from_str (panel->cwd);
|
||||
ok = (mc_chdir (vpath) != -1);
|
||||
vfs_path_free (vpath);
|
||||
if (ok)
|
||||
break;
|
||||
|
||||
if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0)
|
||||
{
|
||||
panel_clean_dir (panel);
|
||||
@ -3823,6 +3856,7 @@ panel_reload (WPanel * panel)
|
||||
memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
|
||||
show_dir (panel);
|
||||
}
|
||||
while (TRUE);
|
||||
|
||||
panel->count =
|
||||
do_reload_dir (panel->cwd, &panel->dir, panel->sort_info.sort_field->sort_routine,
|
||||
@ -4196,6 +4230,7 @@ update_panels (panel_update_flags_t flags, const char *current_file)
|
||||
{
|
||||
gboolean reload_other = (flags & UP_ONLY_CURRENT) == 0;
|
||||
WPanel *panel;
|
||||
vfs_path_t *vpath;
|
||||
int ret;
|
||||
|
||||
update_one_panel (get_current_index (), flags, current_file);
|
||||
@ -4208,7 +4243,11 @@ update_panels (panel_update_flags_t flags, const char *current_file)
|
||||
panel = (WPanel *) get_panel_widget (get_other_index ());
|
||||
|
||||
if (!panel->is_panelized)
|
||||
ret = mc_chdir (panel->cwd);
|
||||
{
|
||||
vpath = vfs_path_from_str (panel->cwd);
|
||||
ret = mc_chdir (vpath);
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -712,16 +712,26 @@ tree_do_search (WTree * tree, int key)
|
||||
static void
|
||||
tree_rescan (void *data)
|
||||
{
|
||||
char old_dir[MC_MAXPATHLEN];
|
||||
WTree *tree = data;
|
||||
char old_dir[MC_MAXPATHLEN];
|
||||
vfs_path_t *vpath;
|
||||
gboolean ok;
|
||||
int ret;
|
||||
|
||||
if (tree->selected_ptr == NULL || mc_get_current_wd (old_dir, MC_MAXPATHLEN) == NULL
|
||||
|| mc_chdir (tree->selected_ptr->name))
|
||||
if (tree->selected_ptr == NULL || mc_get_current_wd (old_dir, MC_MAXPATHLEN) == NULL)
|
||||
return;
|
||||
|
||||
tree_store_rescan (tree->selected_ptr->name);
|
||||
ret = mc_chdir (old_dir);
|
||||
vpath = vfs_path_from_str (tree->selected_ptr->name);
|
||||
ok = (mc_chdir (vpath) == 0);
|
||||
vfs_path_free (vpath);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
tree_store_rescan (tree->selected_ptr->name);
|
||||
vpath = vfs_path_from_str (old_dir);
|
||||
ret = mc_chdir (vpath);
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -53,12 +53,12 @@ teardown (void)
|
||||
}
|
||||
|
||||
static int
|
||||
test_chdir(const vfs_path_t * vpath)
|
||||
test_chdir (const vfs_path_t * vpath)
|
||||
{
|
||||
#if 0
|
||||
char *path = vfs_path_to_str(vpath);
|
||||
printf("test_chdir: %s\n", path);
|
||||
g_free(path);
|
||||
char *path = vfs_path_to_str (vpath);
|
||||
printf ("test_chdir: %s\n", path);
|
||||
g_free (path);
|
||||
#else
|
||||
(void) vpath;
|
||||
#endif
|
||||
@ -68,13 +68,16 @@ test_chdir(const vfs_path_t * vpath)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#define cd_and_check( cd_dir, etalon ) \
|
||||
mc_chdir(cd_dir); \
|
||||
vpath = vfs_path_from_str (cd_dir); \
|
||||
mc_chdir(vpath); \
|
||||
vfs_path_free (vpath); \
|
||||
fail_unless( \
|
||||
strcmp(etalon, mc_get_current_wd(buffer,MC_MAXPATHLEN)) == 0, \
|
||||
"\n expected(%s) doesn't equal \nto actual(%s)", etalon, buffer);
|
||||
|
||||
START_TEST (set_up_current_dir_url)
|
||||
{
|
||||
vfs_path_t *vpath;
|
||||
static struct vfs_s_subclass test_subclass;
|
||||
static struct vfs_class vfs_test_ops;
|
||||
char buffer[MC_MAXPATHLEN];
|
||||
@ -108,11 +111,10 @@ START_TEST (set_up_current_dir_url)
|
||||
cd_and_check ("..", "/");
|
||||
|
||||
}
|
||||
|
||||
END_TEST
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int number_failed;
|
||||
|
Loading…
Reference in New Issue
Block a user