From 32c6bde08092c14e62f9e6b6df094cf4f914bde8 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Mon, 18 Jul 2011 00:30:58 +0300 Subject: [PATCH] Changed interface of mc_stat() and mc_lstat() functions ...to handle vfs_path_t object as parameter. Signed-off-by: Slava Zanko --- lib/mcconfig.h | 3 + lib/mcconfig/common.c | 13 ++- lib/mcconfig/paths.c | 21 ++++ lib/util.c | 17 +++- lib/vfs/interface.c | 15 ++- lib/vfs/vfs.c | 25 ++--- lib/vfs/vfs.h | 4 +- lib/widget/input_complete.c | 10 +- src/args.c | 7 +- src/diffviewer/ydiff.c | 8 +- src/editor/edit.c | 5 +- src/editor/editcmd.c | 28 ++++-- src/execute.c | 7 +- src/filemanager/achown.c | 16 ++- src/filemanager/chmod.c | 16 ++- src/filemanager/chown.c | 6 +- src/filemanager/dir.c | 38 +++++--- src/filemanager/ext.c | 20 +++- src/filemanager/file.c | 233 ++++++++++++++++++++++++++++++++++---------- src/filemanager/filegui.c | 9 +- src/filemanager/fileopctx.h | 3 +- src/filemanager/find.c | 22 +++-- src/filemanager/midnight.c | 12 ++- src/filemanager/panel.c | 18 +++- src/filemanager/treestore.c | 17 ++-- src/vfs/cpio/cpio.c | 29 +++--- src/vfs/extfs/extfs.c | 23 +++-- src/vfs/tar/tar.c | 6 +- 28 files changed, 464 insertions(+), 167 deletions(-) diff --git a/lib/mcconfig.h b/lib/mcconfig.h index 11114386e..0518ac152 100644 --- a/lib/mcconfig.h +++ b/lib/mcconfig.h @@ -1,6 +1,8 @@ #ifndef MC_CONFIG_H #define MC_CONFIG_H +#include "lib/vfs/vfs.h" /* vfs_path_t */ + /*** typedefs(not structures) and defined constants **********************************************/ #define CONFIG_APP_SECTION "Midnight-Commander" @@ -112,6 +114,7 @@ const char *mc_config_get_home_dir (void); char *mc_config_get_full_path (const char *config_name); +vfs_path_t *mc_config_get_full_vpath (const char *config_name); /*** inline functions ****************************************************************************/ diff --git a/lib/mcconfig/common.c b/lib/mcconfig/common.c index 4e8329be4..73330e445 100644 --- a/lib/mcconfig/common.c +++ b/lib/mcconfig/common.c @@ -115,10 +115,17 @@ mc_config_init (const gchar * ini_path) if (ini_path == NULL) return mc_config; - if (exist_file (ini_path) && mc_stat (ini_path, &st) == 0 && st.st_size != 0) + if (exist_file (ini_path)) { - /* file exists and not empty */ - g_key_file_load_from_file (mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL); + vfs_path_t *vpath; + + vpath = vfs_path_from_str (ini_path); + if (mc_stat (vpath, &st) == 0 && st.st_size != 0) + { + /* file exists and not empty */ + g_key_file_load_from_file (mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL); + } + vfs_path_free (vpath); } mc_config->ini_path = g_strdup (ini_path); diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c index ca10a0e31..a8b5d37ba 100644 --- a/lib/mcconfig/paths.c +++ b/lib/mcconfig/paths.c @@ -525,3 +525,24 @@ mc_config_get_full_path (const char *config_name) } /* --------------------------------------------------------------------------------------------- */ +/** + * Get full path to config file by short name. + * + * @param config_name short name + * @return object with full path to config file + */ + +vfs_path_t * +mc_config_get_full_vpath (const char *config_name) +{ + vfs_path_t *ret_vpath; + char *str_path; + + str_path = mc_config_get_full_path (config_name); + + ret_vpath = vfs_path_from_str(str_path); + g_free (str_path); + return ret_vpath; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/util.c b/lib/util.c index cb6835fee..f6bedfc5d 100644 --- a/lib/util.c +++ b/lib/util.c @@ -116,14 +116,18 @@ resolve_symlinks (const char *path) int len; struct stat mybuf; const char *p; + vfs_path_t *vpath; if (*path != PATH_SEP) return NULL; + + vpath = vfs_path_from_str (path); r = buf = g_malloc (MC_MAXPATHLEN); buf2 = g_malloc (MC_MAXPATHLEN); *r++ = PATH_SEP; *r = 0; p = path; + for (;;) { q = strchr (p + 1, PATH_SEP); @@ -135,12 +139,12 @@ resolve_symlinks (const char *path) } c = *q; *q = 0; - if (mc_lstat (path, &mybuf) < 0) + if (mc_lstat (vpath, &mybuf) < 0) { g_free (buf); - g_free (buf2); + buf = NULL; *q = c; - return NULL; + goto ret; } if (!S_ISLNK (mybuf.st_mode)) strcpy (r, p + 1); @@ -150,9 +154,9 @@ resolve_symlinks (const char *path) if (len < 0) { g_free (buf); - g_free (buf2); + buf = NULL; *q = c; - return NULL; + goto ret; } buf2[len] = 0; if (*buf2 == PATH_SEP) @@ -176,7 +180,10 @@ resolve_symlinks (const char *path) strcpy (buf, PATH_SEP_STR); else if (*(r - 1) == PATH_SEP && r != buf + 1) *(r - 1) = 0; + + ret: g_free (buf2); + vfs_path_free (vpath); return buf; } diff --git a/lib/vfs/interface.c b/lib/vfs/interface.c index c7b8ac132..c41cf29e8 100644 --- a/lib/vfs/interface.c +++ b/lib/vfs/interface.c @@ -80,6 +80,7 @@ mc_def_getlocalcopy (const char *filename) ssize_t i; char buffer[8192]; struct stat mystat; + vfs_path_t *vpath = vfs_path_from_str (filename); fdin = mc_open (filename, O_RDONLY | O_LINEAR); if (fdin == -1) @@ -106,12 +107,14 @@ mc_def_getlocalcopy (const char *filename) goto fail; } - if (mc_stat (filename, &mystat) != -1) + if (mc_stat (vpath, &mystat) != -1) chmod (tmp, mystat.st_mode); + vfs_path_free (vpath); return tmp; fail: + vfs_path_free (vpath); if (fdout != -1) close (fdout); if (fdin != -1) @@ -556,13 +559,11 @@ mc_closedir (DIR * dirp) /* --------------------------------------------------------------------------------------------- */ int -mc_stat (const char *filename, struct stat *buf) +mc_stat (const vfs_path_t * vpath, struct stat *buf) { int result = -1; - vfs_path_t *vpath; vfs_path_element_t *path_element; - vpath = vfs_path_from_str (filename); if (vpath == NULL) return -1; @@ -575,20 +576,17 @@ mc_stat (const char *filename, struct stat *buf) errno = path_element->class->name ? vfs_ferrno (path_element->class) : E_NOTSUPP; } - vfs_path_free (vpath); return result; } /* --------------------------------------------------------------------------------------------- */ int -mc_lstat (const char *filename, struct stat *buf) +mc_lstat (const vfs_path_t * vpath, struct stat *buf) { int result = -1; - vfs_path_t *vpath; vfs_path_element_t *path_element; - vpath = vfs_path_from_str (filename); if (vpath == NULL) return -1; @@ -601,7 +599,6 @@ mc_lstat (const char *filename, struct stat *buf) errno = path_element->class->name ? vfs_ferrno (path_element->class) : E_NOTSUPP; } - vfs_path_free (vpath); return result; } diff --git a/lib/vfs/vfs.c b/lib/vfs/vfs.c index 438d41fbc..97b6ef8d6 100644 --- a/lib/vfs/vfs.c +++ b/lib/vfs/vfs.c @@ -538,28 +538,29 @@ _vfs_get_cwd (void) path_element = vfs_path_get_by_index (vfs_get_raw_current_dir (), -1); - if (path_element->class->flags & VFSF_LOCAL) + if ((path_element->class->flags & VFSF_LOCAL) != 0) { - char *tmp; + char *current_dir; + vfs_path_t *tmp_vpath; - tmp = g_get_current_dir (); - if (tmp != NULL) + current_dir = g_get_current_dir (); + tmp_vpath = vfs_path_from_str (current_dir); + g_free (current_dir); + + if (tmp_vpath != NULL) { /* One of the directories in the path is not readable */ 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 (tmp, &my_stat) == 0 - && mc_stat (path_element->path, &my_stat2) == 0 + && mc_stat (tmp_vpath, &my_stat) == 0 + && mc_stat (vfs_get_raw_current_dir (), &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)); - } - - g_free (tmp); + vfs_set_raw_current_dir (tmp_vpath); + else + vfs_path_free (tmp_vpath); } } - return vfs_path_to_str (vfs_get_raw_current_dir ()); } diff --git a/lib/vfs/vfs.h b/lib/vfs/vfs.h index f9ec5e96d..fb6801f54 100644 --- a/lib/vfs/vfs.h +++ b/lib/vfs/vfs.h @@ -284,13 +284,13 @@ off_t mc_lseek (int fd, off_t offset, int whence); DIR *mc_opendir (const char *dirname); struct dirent *mc_readdir (DIR * dirp); int mc_closedir (DIR * dir); -int mc_stat (const char *path, struct stat *buf); +int mc_stat (const vfs_path_t * vpath, struct stat *buf); int mc_mknod (const char *path, mode_t mode, dev_t dev); int mc_link (const char *name1, const char *name2); int mc_mkdir (const char *path, mode_t mode); int mc_rmdir (const char *path); int mc_fstat (int fd, struct stat *buf); -int mc_lstat (const char *path, struct stat *buf); +int mc_lstat (const vfs_path_t * vpath, struct stat *buf); 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); diff --git a/lib/widget/input_complete.c b/lib/widget/input_complete.c index 05f1d7baa..ffbeafb74 100644 --- a/lib/widget/input_complete.c +++ b/lib/widget/input_complete.c @@ -209,13 +209,13 @@ filename_completion_function (const char *text, int state, input_complete_t flag isdir = 1; isexec = 0; { - char *tmp; + vfs_path_t *vpath; struct stat tempstat; - tmp = g_strconcat (dirname, PATH_SEP_STR, entry->d_name, (char *) NULL); - canonicalize_pathname (tmp); + vpath = vfs_path_build_filename (dirname, entry->d_name, (char *) NULL); + /* Unix version */ - if (!mc_stat (tmp, &tempstat)) + if (mc_stat (vpath, &tempstat) == 0) { uid_t my_uid = getuid (); gid_t my_gid = getgid (); @@ -235,7 +235,7 @@ filename_completion_function (const char *text, int state, input_complete_t flag /* stat failed, strange. not a dir in any case */ isdir = 0; } - g_free (tmp); + vfs_path_free (vpath); } if ((flags & INPUT_COMPLETE_COMMANDS) && (isexec || isdir)) break; diff --git a/src/args.c b/src/args.c index f8d58b4bf..c54dd009b 100644 --- a/src/args.c +++ b/src/args.c @@ -648,13 +648,16 @@ mc_setup_by_args (int argc, char **argv, GError ** error) { char *fname; struct stat st; + vfs_path_t *tmp_vpath, *fname_vpath; fname = g_strndup (tmp, p - 1 - tmp); + tmp_vpath = vfs_path_from_str (tmp); + fname_vpath = vfs_path_from_str (fname); /* * Check that the file before the colon actually exists. * If it doesn't exist, revert to the old behavior. */ - if (mc_stat (tmp, &st) == -1 && mc_stat (fname, &st) != -1) + if (mc_stat (tmp_vpath, &st) == -1 && mc_stat (fname_vpath, &st) != -1) { mc_run_param0 = fname; mc_args__edit_start_line = atoi (p); @@ -664,6 +667,8 @@ mc_setup_by_args (int argc, char **argv, GError ** error) g_free (fname); goto try_plus_filename; } + vfs_path_free (tmp_vpath); + vfs_path_free (fname_vpath); } else { diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index 024b2c288..20b28d6a4 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -3335,9 +3335,11 @@ do \ real_file##n = mc_getlocalcopy (file##n); \ if (real_file##n != NULL) \ { \ + vfs_path_t *tmp_vpath = vfs_path_from_str (real_file##n); \ use_copy##n = 1; \ - if (mc_stat (real_file##n, &st##n) != 0) \ + if (mc_stat (tmp_vpath, &st##n) != 0) \ use_copy##n = -1; \ + vfs_path_free (tmp_vpath); \ } \ } \ vfs_path_free(vpath); \ @@ -3353,9 +3355,11 @@ do \ if (use_copy##n > 0) \ { \ time_t mtime; \ + vfs_path_t *tmp_vpath = vfs_path_from_str (real_file##n); \ mtime = st##n.st_mtime; \ - if (mc_stat (real_file##n, &st##n) == 0) \ + if (mc_stat (tmp_vpath, &st##n) == 0) \ changed = (mtime != st##n.st_mtime); \ + vfs_path_free (tmp_vpath); \ } \ mc_ungetlocalcopy (file##n, real_file##n, changed); \ g_free (real_file##n); \ diff --git a/src/editor/edit.c b/src/editor/edit.c index e934c63e0..02e2e3565 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -1833,8 +1833,10 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry) long curs; long start_mark, end_mark; struct stat status; + vfs_path_t *block_file_vpath; block_file = mc_config_get_full_path (EDIT_BLOCK_FILE); + block_file_vpath = vfs_path_from_str (block_file); curs = edit->curs1; nomark = eval_marks (edit, &start_mark, &end_mark); if (nomark == 0) @@ -1842,7 +1844,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry) /* run shell scripts from menu */ if (user_menu_cmd (edit, menu_file, selected_entry) - && (mc_stat (block_file, &status) == 0) && (status.st_size != 0)) + && (mc_stat (block_file_vpath, &status) == 0) && (status.st_size != 0)) { int rc = 0; FILE *fd; @@ -1869,6 +1871,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry) edit->force |= REDRAW_COMPLETELY; g_free (block_file); + vfs_path_free (block_file_vpath); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index b9aa099a9..887c04653 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -126,6 +126,7 @@ edit_save_file (WEdit * edit, const char *filename) char *savename = 0; gchar *real_filename; int this_save_mode, fd = -1; + vfs_path_t *real_filename_vpath; if (!filename) return 0; @@ -140,12 +141,13 @@ edit_save_file (WEdit * edit, const char *filename) { real_filename = g_strdup (filename); } + real_filename_vpath = vfs_path_from_str (real_filename); this_save_mode = option_save_mode; if (this_save_mode != EDIT_QUICK_SAVE) { - vfs_path_t *vpath = vfs_path_from_str (real_filename); - if (!vfs_file_is_local (vpath) || (fd = mc_open (real_filename, O_RDONLY | O_BINARY)) == -1) + if (!vfs_file_is_local (real_filename_vpath) + || (fd = mc_open (real_filename, O_RDONLY | O_BINARY)) == -1) { /* * The file does not exists yet, so no safe save or @@ -153,7 +155,6 @@ edit_save_file (WEdit * edit, const char *filename) */ this_save_mode = EDIT_QUICK_SAVE; } - vfs_path_free (vpath); if (fd != -1) mc_close (fd); } @@ -163,7 +164,7 @@ edit_save_file (WEdit * edit, const char *filename) int rv; struct stat sb; - rv = mc_stat (real_filename, &sb); + rv = mc_stat (real_filename_vpath, &sb); if (rv == 0 && sb.st_nlink > 1) { rv = edit_query_dialog3 (_("Warning"), @@ -179,6 +180,7 @@ edit_save_file (WEdit * edit, const char *filename) break; default: g_free (real_filename); + vfs_path_free (real_filename_vpath); return -1; } } @@ -196,6 +198,7 @@ edit_save_file (WEdit * edit, const char *filename) if (rv != 0) { g_free (real_filename); + vfs_path_free (real_filename_vpath); return -1; } } @@ -220,6 +223,7 @@ edit_save_file (WEdit * edit, const char *filename) if (!savename) { g_free (real_filename); + vfs_path_free (real_filename_vpath); return 0; } /* FIXME: @@ -278,6 +282,7 @@ edit_save_file (WEdit * edit, const char *filename) } else if (edit->lb == LB_ASIS) { /* do not change line breaks */ + vfs_path_t *savename_vpath; long buf; buf = 0; filelen = edit->last_byte; @@ -325,8 +330,13 @@ edit_save_file (WEdit * edit, const char *filename) goto error_save; /* Update the file information, especially the mtime. */ - if (mc_stat (savename, &edit->stat1) == -1) + savename_vpath = vfs_path_from_str (savename); + if (mc_stat (savename_vpath, &edit->stat1) == -1) + { + vfs_path_free (savename_vpath); goto error_save; + } + vfs_path_free (savename_vpath); } else { /* change line breaks */ @@ -373,6 +383,7 @@ edit_save_file (WEdit * edit, const char *filename) goto error_save; g_free (savename); g_free (real_filename); + vfs_path_free (real_filename_vpath); return 1; error_save: /* FIXME: Is this safe ? @@ -380,6 +391,7 @@ edit_save_file (WEdit * edit, const char *filename) * mc_unlink (savename); */ g_free (real_filename); + vfs_path_free (real_filename_vpath); g_free (savename); return 0; } @@ -1661,6 +1673,7 @@ edit_save_as_cmd (WEdit * edit) { /* This heads the 'Save As' dialog box */ char *exp; + vfs_path_t *exp_vpath; int save_lock = 0; int different_filename = 0; @@ -1686,15 +1699,18 @@ edit_save_as_cmd (WEdit * edit) int file; struct stat sb; - if (mc_stat (exp, &sb) == 0 && !S_ISREG (sb.st_mode)) + exp_vpath = vfs_path_from_str (exp); + if (mc_stat (exp_vpath, &sb) == 0 && !S_ISREG (sb.st_mode)) { edit_error_dialog (_("Save as"), get_sys_error (_ ("Cannot save: destination is not a regular file"))); g_free (exp); edit->force |= REDRAW_COMPLETELY; + vfs_path_free (exp_vpath); return 0; } + vfs_path_free (exp_vpath); different_filename = 1; file = mc_open (exp, O_RDONLY | O_BINARY); diff --git a/src/execute.c b/src/execute.c index 13839e125..05db007a6 100644 --- a/src/execute.c +++ b/src/execute.c @@ -443,6 +443,7 @@ execute_with_vfs_arg (const char *command, const char *filename) struct stat st; time_t mtime; vfs_path_t *vpath = vfs_path_from_str (filename); + vfs_path_t *localcopy_vpath; /* Simplest case, this file is local */ if (!filename || vfs_file_is_local (vpath)) @@ -465,6 +466,7 @@ execute_with_vfs_arg (const char *command, const char *filename) message (D_ERROR, MSG_ERROR, _("Cannot fetch a local copy of %s"), filename); return; } + localcopy_vpath = vfs_path_from_str (localcopy); /* * filename can be an entry on panel, it can be changed by executing @@ -472,12 +474,13 @@ execute_with_vfs_arg (const char *command, const char *filename) * below unnecessary. */ fn = g_strdup (filename); - mc_stat (localcopy, &st); + mc_stat (localcopy_vpath, &st); mtime = st.st_mtime; do_execute (command, localcopy, EXECUTE_INTERNAL); - mc_stat (localcopy, &st); + mc_stat (localcopy_vpath, &st); mc_ungetlocalcopy (fn, localcopy, mtime != st.st_mtime); g_free (localcopy); + vfs_path_free (localcopy_vpath); g_free (fn); } diff --git a/src/filemanager/achown.c b/src/filemanager/achown.c index 148ef4432..8c79d4951 100644 --- a/src/filemanager/achown.c +++ b/src/filemanager/achown.c @@ -743,10 +743,16 @@ apply_advanced_chowns (struct stat *sf) do { + vfs_path_t *vpath; + lc_fname = next_file (); + vpath = vfs_path_from_str (lc_fname); - if (mc_stat (lc_fname, sf) != 0) + if (mc_stat (vpath, sf) != 0) + { + vfs_path_free (vpath); break; + } ch_cmode = sf->st_mode; if (mc_chmod (lc_fname, get_mode ()) == -1) message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"), @@ -758,6 +764,7 @@ apply_advanced_chowns (struct stat *sf) lc_fname, unix_error_string (errno)); do_file_mark (current_panel, current_file, 0); + vfs_path_free (vpath); } while (current_panel->marked); } @@ -774,16 +781,19 @@ chown_advanced_cmd (void) do { /* do while any files remaining */ + vfs_path_t *vpath; init_chown_advanced (); if (current_panel->marked) fname = next_file (); /* next marked file */ else fname = selection (current_panel)->fname; /* single file */ + vpath = vfs_path_from_str (fname); - if (mc_stat (fname, sf_stat) != 0) + if (mc_stat (vpath, sf_stat) != 0) { /* get status of file */ destroy_dlg (ch_dlg); + vfs_path_free (vpath); break; } ch_cmode = sf_stat->st_mode; @@ -827,6 +837,8 @@ chown_advanced_cmd (void) need_update = 1; } destroy_dlg (ch_dlg); + vfs_path_free (vpath); + } while (current_panel->marked && !end_chown); diff --git a/src/filemanager/chmod.c b/src/filemanager/chmod.c index 8bd464e4e..97ebdaa43 100644 --- a/src/filemanager/chmod.c +++ b/src/filemanager/chmod.c @@ -389,9 +389,14 @@ apply_mask (struct stat *sf) do { char *fname; + vfs_path_t *vpath; + gboolean ok; fname = next_file (); - if (mc_stat (fname, sf) != 0) + vpath = vfs_path_from_str (fname); + ok = (mc_stat (vpath, sf) == 0); + vfs_path_free (vpath); + if (!ok) return; c_stat = sf->st_mode; @@ -412,6 +417,7 @@ chmod_cmd (void) do { /* do while any files remaining */ + vfs_path_t *vpath; Dlg_head *ch_dlg; struct stat sf_stat; char *fname; @@ -430,8 +436,14 @@ chmod_cmd (void) else fname = selection (current_panel)->fname; /* single file */ - if (mc_stat (fname, &sf_stat) != 0) + vpath = vfs_path_from_str (fname); + + if (mc_stat (vpath, &sf_stat) != 0) + { + vfs_path_free (vpath); break; + } + vfs_path_free (vpath); c_stat = sf_stat.st_mode; diff --git a/src/filemanager/chown.c b/src/filemanager/chown.c index b6b5e7687..54d6c281b 100644 --- a/src/filemanager/chown.c +++ b/src/filemanager/chown.c @@ -284,6 +284,7 @@ chown_cmd (void) do { /* do while any files remaining */ + vfs_path_t *vpath; ch_dlg = init_chown (); new_user = new_group = -1; @@ -292,11 +293,14 @@ chown_cmd (void) else fname = selection (current_panel)->fname; /* single file */ - if (mc_stat (fname, &sf_stat) != 0) + vpath = vfs_path_from_str (fname); + if (mc_stat (vpath, &sf_stat) != 0) { /* get status of file */ destroy_dlg (ch_dlg); + vfs_path_free (vpath); break; } + vfs_path_free (vpath); /* select in listboxes */ listbox_select_entry (l_user, listbox_search_text (l_user, get_owner (sf_stat.st_uid))); diff --git a/src/filemanager/dir.c b/src/filemanager/dir.c index 477025b38..89cededc2 100644 --- a/src/filemanager/dir.c +++ b/src/filemanager/dir.c @@ -141,6 +141,8 @@ static int handle_dirent (dir_list * list, const char *fltr, struct dirent *dp, struct stat *buf1, int next_free, int *link_to_dir, int *stale_link) { + vfs_path_t *vpath; + if (dp->d_name[0] == '.' && dp->d_name[1] == 0) return 0; if (dp->d_name[0] == '.' && dp->d_name[1] == '.' && dp->d_name[2] == 0) @@ -150,7 +152,8 @@ handle_dirent (dir_list * list, const char *fltr, struct dirent *dp, if (!panels_options.show_backups && dp->d_name[NLENGTH (dp) - 1] == '~') return 0; - if (mc_lstat (dp->d_name, buf1) == -1) + vpath = vfs_path_from_str (dp->d_name); + if (mc_lstat (vpath, buf1) == -1) { /* * lstat() fails - such entries should be identified by @@ -169,11 +172,12 @@ handle_dirent (dir_list * list, const char *fltr, struct dirent *dp, if (S_ISLNK (buf1->st_mode)) { struct stat buf2; - if (!mc_stat (dp->d_name, &buf2)) + if (mc_stat (vpath, &buf2) == 0) *link_to_dir = S_ISDIR (buf2.st_mode) != 0; else *stale_link = 1; } + vfs_path_free (vpath); if (!(S_ISDIR (buf1->st_mode) || *link_to_dir) && (fltr != NULL) && !mc_search (fltr, dp->d_name, MC_SEARCH_T_GLOB)) return 0; @@ -199,13 +203,12 @@ get_dotdot_dir_stat (const char *path, struct stat *st) if ((path != NULL) && (path[0] != '\0') && (st != NULL)) { - char *dotdot_dir; + vfs_path_t *vpath; struct stat s; - dotdot_dir = g_strdup_printf ("%s/../", path); - canonicalize_pathname (dotdot_dir); - ret = mc_stat (dotdot_dir, &s) == 0; - g_free (dotdot_dir); + vpath = vfs_path_build_filename (path, "..", NULL); + ret = mc_stat (vpath, &s) == 0; + vfs_path_free (vpath); *st = s; } @@ -480,12 +483,19 @@ int handle_path (dir_list * list, const char *path, struct stat *buf1, int next_free, int *link_to_dir, int *stale_link) { + vfs_path_t *vpath; + if (path[0] == '.' && path[1] == 0) return 0; if (path[0] == '.' && path[1] == '.' && path[2] == 0) return 0; - if (mc_lstat (path, buf1) == -1) + + vpath = vfs_path_from_str (path); + if (mc_lstat (vpath, buf1) == -1) + { + vfs_path_free (vpath); return 0; + } if (S_ISDIR (buf1->st_mode)) tree_store_mark_checked (path); @@ -496,17 +506,18 @@ handle_path (dir_list * list, const char *path, if (S_ISLNK (buf1->st_mode)) { struct stat buf2; - if (!mc_stat (path, &buf2)) + if (mc_stat (vpath, &buf2) == 0) *link_to_dir = S_ISDIR (buf2.st_mode) != 0; else *stale_link = 1; } + vfs_path_free (vpath); + /* Need to grow the *list? */ if (next_free == list->size) { list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS)); - if (list->list == NULL) return -1; list->size += RESIZE_STEPS; } @@ -587,9 +598,14 @@ gboolean if_link_is_exe (const char *full_name, const file_entry * file) { struct stat b; + vfs_path_t *vpath = vfs_path_from_str (full_name); - if (S_ISLNK (file->st.st_mode) && mc_stat (full_name, &b) == 0) + if (S_ISLNK (file->st.st_mode) && mc_stat (vpath, &b) == 0) + { + vfs_path_free (vpath); return is_exe (b.st_mode); + } + vfs_path_free (vpath); return TRUE; } diff --git a/src/filemanager/ext.c b/src/filemanager/ext.c index ca6196582..a30cc4ba1 100644 --- a/src/filemanager/ext.c +++ b/src/filemanager/ext.c @@ -228,6 +228,7 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st { if (do_local_copy) { + vfs_path_t *vpath_local; localcopy = mc_getlocalcopy (filename); if (localcopy == NULL) { @@ -237,9 +238,11 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st vfs_path_free (vpath); return; } - mc_stat (localcopy, &mystat); + vpath_local = vfs_path_from_str (localcopy); + mc_stat (vpath_local, &mystat); localmtime = mystat.st_mtime; text = quote_func (localcopy, 0); + vfs_path_free (vpath_local); } else { @@ -377,8 +380,12 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st if (localcopy) { - mc_stat (localcopy, &mystat); + vfs_path_t *vpath_local; + + vpath_local = vfs_path_from_str (localcopy); + mc_stat (vpath_local, &mystat); mc_ungetlocalcopy (filename, localcopy, localmtime != mystat.st_mtime); + vfs_path_free (vpath_local); g_free (localcopy); } vfs_path_free (vpath); @@ -698,7 +705,14 @@ regex_command (const char *filename, const char *action, int *move_dir) g_free (title); } } - mc_stat (filename, &mystat); + + { + vfs_path_t *vpath; + + vpath = vfs_path_from_str (filename); + mc_stat (vpath, &mystat); + vfs_path_free (vpath); + } include_target = NULL; include_target_len = 0; diff --git a/src/filemanager/file.c b/src/filemanager/file.c index 474c2338f..fd868fdbf 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -295,12 +295,14 @@ check_hardlinks (const char *src_name, const char *dst_name, struct stat *pstat) if (lp->vfs == my_vfs && lp->ino == ino && lp->dev == dev) { struct vfs_class *lp_name_class; + int stat_result; vpath = vfs_path_from_str (lp->name); lp_name_class = vfs_path_get_by_index (vpath, -1)->class; + stat_result = mc_stat (vpath, &link_stat); vfs_path_free (vpath); - if (!mc_stat (lp->name, &link_stat) && link_stat.st_ino == ino + if (!stat_result && link_stat.st_ino == ino && link_stat.st_dev == dev && lp_name_class == my_vfs) { struct vfs_class *p_class, *dst_name_class; @@ -308,22 +310,26 @@ check_hardlinks (const char *src_name, const char *dst_name, struct stat *pstat) p = strchr (lp->name, 0) + 1; /* i.e. where the `name' file was copied to */ - vpath = vfs_path_from_str (p); - p_class = vfs_path_get_by_index (vpath, -1)->class; - vfs_path_free (vpath); - vpath = vfs_path_from_str (dst_name); dst_name_class = vfs_path_get_by_index (vpath, -1)->class; vfs_path_free (vpath); + vpath = vfs_path_from_str (p); + p_class = vfs_path_get_by_index (vpath, -1)->class; + if (dst_name_class == p_class) { - if (!mc_stat (p, &link_stat)) + if (!mc_stat (vpath, &link_stat)) { if (!mc_link (p, dst_name)) + { + vfs_path_free (vpath); return TRUE; + } } } + vfs_path_free (vpath); + } message (D_ERROR, MSG_ERROR, _("Cannot make the hardlink")); return FALSE; @@ -363,7 +369,10 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) struct stat sb; gboolean dst_is_symlink; - dst_is_symlink = (mc_lstat (dst_path, &sb) == 0) && S_ISLNK (sb.st_mode); + vfs_path_t *src_vpath = vfs_path_from_str (src_path); + vfs_path_t *dst_vpath = vfs_path_from_str (dst_path); + + dst_is_symlink = (mc_lstat (dst_vpath, &sb) == 0) && S_ISLNK (sb.st_mode); retry_src_readlink: len = mc_readlink (src_path, link_target, MC_MAXPATHLEN - 1); @@ -385,18 +394,14 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) if (ctx->stable_symlinks) { - vfs_path_t *vpath1 = vfs_path_from_str (src_path); - vfs_path_t *vpath2 = vfs_path_from_str (dst_path); - if (!vfs_file_is_local (vpath1) || !vfs_file_is_local (vpath2)) + if (!vfs_file_is_local (src_vpath) || !vfs_file_is_local (dst_vpath)) { message (D_ERROR, MSG_ERROR, _("Cannot make stable symlinks across" "non-local filesystems:\n\nOption Stable Symlinks will be disabled")); ctx->stable_symlinks = FALSE; } - vfs_path_free (vpath1); - vfs_path_free (vpath2); } if (ctx->stable_symlinks && !g_path_is_absolute (link_target)) @@ -434,8 +439,12 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) } retry_dst_symlink: if (mc_symlink (link_target, dst_path) == 0) + { /* Success */ + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return FILE_CONT; + } /* * if dst_exists, it is obvious that this had failed. * We can delete the old symlink and try again... @@ -444,8 +453,13 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) { if (!mc_unlink (dst_path)) if (mc_symlink (link_target, dst_path) == 0) + { /* Success */ + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); + return FILE_CONT; + } } if (ctx->skip_all) return_status = FILE_SKIPALL; @@ -457,6 +471,8 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) if (return_status == FILE_RETRY) goto retry_dst_symlink; } + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return return_status; } @@ -776,6 +792,7 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c FileProgressStatus return_status = FILE_CONT; gboolean copy_done = FALSE; gboolean old_ask_overwrite; + vfs_path_t *src_vpath, *dst_vpath; file_progress_show_source (ctx, s); file_progress_show_target (ctx, d); @@ -783,8 +800,10 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c return FILE_ABORT; mc_refresh (); + src_vpath = vfs_path_from_str (s); + dst_vpath = vfs_path_from_str (d); - while (mc_lstat (s, &src_stats) != 0) + while (mc_lstat (src_vpath, &src_stats) != 0) { /* Source doesn't exist */ if (ctx->skip_all) @@ -796,10 +815,14 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c ctx->skip_all = TRUE; } if (return_status != FILE_RETRY) + { + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return return_status; + } } - if (mc_lstat (d, &dst_stats) == 0) + if (mc_lstat (dst_vpath, &dst_stats) == 0) { if (src_stats.st_dev == dst_stats.st_dev && src_stats.st_ino == dst_stats.st_ino) return warn_same_file (_("\"%s\"\nand\n\"%s\"\nare the same file"), s, d); @@ -808,6 +831,8 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c { message (D_ERROR, MSG_ERROR, _("Cannot overwrite directory \"%s\""), d); do_refresh (); + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return FILE_SKIP; } @@ -815,7 +840,11 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c { return_status = query_replace (ctx, d, &src_stats, &dst_stats); if (return_status != FILE_CONT) + { + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return return_status; + } } /* Ok to overwrite */ } @@ -828,11 +857,19 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c if (return_status == FILE_CONT) goto retry_src_remove; else + { + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return return_status; + } } if (mc_rename (s, d) == 0) + { + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return progress_update_one (tctx, ctx, src_stats.st_size); + } } #if 0 /* Comparison to EXDEV seems not to work in nfs if you're moving from @@ -854,6 +891,9 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c if (return_status == FILE_RETRY) goto retry_rename; } + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); + return return_status; } #endif @@ -864,7 +904,11 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c return_status = copy_file_file (tctx, ctx, s, d); tctx->ask_overwrite = old_ask_overwrite; if (return_status != FILE_CONT) + { + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return return_status; + } copy_done = TRUE; @@ -873,7 +917,11 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c return_status = check_progress_buttons (ctx); if (return_status != FILE_CONT) + { + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return return_status; + } mc_refresh (); @@ -885,12 +933,18 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c goto retry_src_remove; if (return_status == FILE_SKIPALL) ctx->skip_all = TRUE; + + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return return_status; } if (!copy_done) return_status = progress_update_one (tctx, ctx, src_stats.st_size); + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); + return return_status; } @@ -905,13 +959,14 @@ erase_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s) { int return_status; struct stat buf; + vfs_path_t *vpath = vfs_path_from_str (s); file_progress_show_deleting (ctx, s); if (check_progress_buttons (ctx) == FILE_ABORT) return FILE_ABORT; mc_refresh (); - if (tctx->progress_count != 0 && mc_lstat (s, &buf) != 0) + if (tctx->progress_count != 0 && mc_lstat (vpath, &buf) != 0) { /* ignore, most likely the mc_unlink fails, too */ buf.st_size = 0; @@ -921,7 +976,10 @@ erase_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s) { return_status = file_error (_("Cannot delete file \"%s\"\n%s"), s); if (return_status == FILE_ABORT) + { + vfs_path_free (vpath); return return_status; + } if (return_status == FILE_RETRY) continue; if (return_status == FILE_SKIPALL) @@ -929,6 +987,7 @@ erase_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s) break; } + vfs_path_free (vpath); if (tctx->progress_count == 0) return FILE_CONT; return progress_update_one (tctx, ctx, buf.st_size); @@ -950,40 +1009,55 @@ recursive_erase (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s) DIR *reading; char *path; FileProgressStatus return_status = FILE_CONT; + vfs_path_t *vpath; - if (!strcmp (s, "..")) + if (strcmp (s, "..") == 0) return FILE_RETRY; + vpath = vfs_path_from_str (s); reading = mc_opendir (s); - if (!reading) - return FILE_RETRY; + if (reading == NULL) + { + return_status = FILE_RETRY; + goto ret; + } while ((next = mc_readdir (reading)) && return_status != FILE_ABORT) { + vfs_path_t *tmp_vpath; + if (!strcmp (next->d_name, ".")) continue; if (!strcmp (next->d_name, "..")) continue; path = concat_dir_and_file (s, next->d_name); - if (mc_lstat (path, &buf)) + tmp_vpath = vfs_path_from_str (path); + if (mc_lstat (tmp_vpath, &buf) != 0) { g_free (path); mc_closedir (reading); - return FILE_RETRY; + vfs_path_free (tmp_vpath); + return_status = FILE_RETRY; + goto ret; } if (S_ISDIR (buf.st_mode)) return_status = recursive_erase (tctx, ctx, path); else return_status = erase_file (tctx, ctx, path); + vfs_path_free (tmp_vpath); g_free (path); } mc_closedir (reading); if (return_status == FILE_ABORT) - return return_status; + goto ret; + file_progress_show_deleting (ctx, s); if (check_progress_buttons (ctx) == FILE_ABORT) - return FILE_ABORT; + { + return_status = FILE_ABORT; + goto ret; + } mc_refresh (); while (my_rmdir (s) != 0 && !ctx->skip_all) @@ -992,13 +1066,15 @@ recursive_erase (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s) if (return_status == FILE_RETRY) continue; if (return_status == FILE_ABORT) - return return_status; + goto ret; if (return_status == FILE_SKIPALL) ctx->skip_all = TRUE; break; } - return FILE_CONT; + ret: + vfs_path_free (vpath); + return return_status; } /* --------------------------------------------------------------------------------------------- */ @@ -1336,6 +1412,7 @@ copy_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, dest_status_t dst_status = DEST_NONE; int open_flags; gboolean is_first_time = TRUE; + vfs_path_t *src_vpath, *dst_vpath; /* FIXME: We should not be using global variables! */ ctx->do_reget = 0; @@ -1348,7 +1425,8 @@ copy_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, mc_refresh (); - while (mc_stat (dst_path, &sb2) == 0) + dst_vpath = vfs_path_from_str (dst_path); + while (mc_stat (dst_vpath, &sb2) == 0) { if (S_ISDIR (sb2.st_mode)) { @@ -1367,8 +1445,10 @@ copy_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, dst_exists = TRUE; break; } + vfs_path_free (dst_vpath); - while ((*ctx->stat_func) (src_path, &sb) != 0) + src_vpath = vfs_path_from_str (src_path); + while ((*ctx->stat_func) (src_vpath, &sb) != 0) { if (ctx->skip_all) return_status = FILE_SKIPALL; @@ -1379,8 +1459,12 @@ copy_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, ctx->skip_all = TRUE; } if (return_status != FILE_RETRY) + { + vfs_path_free (src_vpath); return return_status; + } } + vfs_path_free (src_vpath); if (dst_exists) { @@ -1809,12 +1893,17 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con struct utimbuf utb; struct link *lp; char *d; + vfs_path_t *src_vpath, *dst_vpath; d = g_strdup (_d); + src_vpath = vfs_path_from_str (s); + dst_vpath = vfs_path_from_str (_d); + /* First get the mode of the source dir */ + retry_src_stat: - if ((*ctx->stat_func) (s, &cbuf) != 0) + if ((*ctx->stat_func) (src_vpath, &cbuf) != 0) { if (ctx->skip_all) return_status = FILE_SKIPALL; @@ -1872,11 +1961,7 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con } lp = g_new (struct link, 1); - { - vfs_path_t *vpath = vfs_path_from_str (s); - lp->vfs = vfs_path_get_by_index (vpath, -1)->class; - vfs_path_free (vpath); - } + lp->vfs = vfs_path_get_by_index (src_vpath, -1)->class; lp->ino = cbuf.st_ino; lp->dev = cbuf.st_dev; lp->next = parent_dirs; @@ -1884,7 +1969,7 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con retry_dst_stat: /* Now, check if the dest dir exists, if not, create it. */ - if (mc_stat (d, &buf)) + if (mc_stat (dst_vpath, &buf) != 0) { /* Here the dir doesn't exist : make it ! */ if (move_over) @@ -1949,11 +2034,12 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con } lp = g_new (struct link, 1); - mc_stat (dest_dir, &buf); { - vfs_path_t *vpath = vfs_path_from_str (dest_dir); - lp->vfs = vfs_path_get_by_index (vpath, -1)->class; - vfs_path_free (vpath); + vfs_path_t *tmp_vpath = vfs_path_from_str (dest_dir); + mc_stat (tmp_vpath, &buf); + + lp->vfs = vfs_path_get_by_index (tmp_vpath, -1)->class; + vfs_path_free (tmp_vpath); } lp->ino = buf.st_ino; lp->dev = buf.st_dev; @@ -1987,6 +2073,7 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con while ((next = mc_readdir (reading)) && return_status != FILE_ABORT) { char *path; + vfs_path_t *tmp_vpath; /* * Now, we don't want '.' and '..' to be created / copied at any time */ @@ -1997,8 +2084,9 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con /* get the filename and add it to the src directory */ path = concat_dir_and_file (s, next->d_name); + tmp_vpath = vfs_path_from_str (path); - (*ctx->stat_func) (path, &buf); + (*ctx->stat_func) (tmp_vpath, &buf); if (S_ISDIR (buf.st_mode)) { char *mdpath; @@ -2051,6 +2139,7 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con } } g_free (path); + vfs_path_free (tmp_vpath); } mc_closedir (reading); @@ -2074,6 +2163,8 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con g_free (parent_dirs); ret_fast: g_free (d); + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return return_status; } @@ -2091,6 +2182,10 @@ move_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con FileProgressStatus return_status; gboolean move_over = FALSE; gboolean dstat_ok; + vfs_path_t *src_vpath, *dst_vpath, *destdir_vpath; + + src_vpath = vfs_path_from_str (s); + dst_vpath = vfs_path_from_str (d); file_progress_show_source (ctx, s); file_progress_show_target (ctx, d); @@ -2099,8 +2194,9 @@ move_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con mc_refresh (); - mc_stat (s, &sbuf); - dstat_ok = (mc_stat (d, &dbuf) == 0); + mc_stat (src_vpath, &sbuf); + + dstat_ok = (mc_stat (dst_vpath, &dbuf) == 0); if (dstat_ok && sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) return warn_same_file (_("\"%s\"\nand\n\"%s\"\nare the same directory"), s, d); @@ -2115,9 +2211,11 @@ move_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con else destdir = concat_dir_and_file (d, x_basename (s)); + destdir_vpath = vfs_path_from_str (destdir); + /* Check if the user inputted an existing dir */ retry_dst_stat: - if (mc_stat (destdir, &destbuf) == 0) + if (mc_stat (destdir_vpath, &destbuf) == 0) { if (move_over) { @@ -2141,6 +2239,9 @@ move_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con goto retry_dst_stat; } g_free (destdir); + vfs_path_free (destdir_vpath); + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return return_status; } @@ -2196,12 +2297,15 @@ move_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con ret: g_free (destdir); + vfs_path_free (destdir_vpath); while (erase_list) { lp = erase_list; erase_list = erase_list->next; g_free (lp); } + vfs_path_free (src_vpath); + vfs_path_free (dst_vpath); return return_status; } @@ -2356,30 +2460,34 @@ compute_dir_size (const char *dirname, const void *ui, DIR *dir; struct dirent *dirent; FileProgressStatus ret = FILE_CONT; + vfs_path_t *vpath; + + vpath = vfs_path_from_str (dirname); if (!compute_symlinks) { - res = mc_lstat (dirname, &s); + res = mc_lstat (vpath, &s); if (res != 0) - return ret; + goto ret; /* don't scan symlink to directory */ if (S_ISLNK (s.st_mode)) { (*ret_marked)++; *ret_total += (uintmax_t) s.st_size; - return ret; + goto ret; } } dir = mc_opendir (dirname); if (dir == NULL) - return ret; + goto ret; while ((dirent = mc_readdir (dir)) != NULL) { char *fullname; + vfs_path_t *tmp_vpath; ret = (cback != NULL) ? cback (ui, dirname) : FILE_CONT; @@ -2392,11 +2500,13 @@ compute_dir_size (const char *dirname, const void *ui, continue; fullname = concat_dir_and_file (dirname, dirent->d_name); - res = mc_lstat (fullname, &s); + tmp_vpath = vfs_path_from_str (fullname); + res = mc_lstat (tmp_vpath, &s); if (res != 0) { g_free (fullname); + vfs_path_free (tmp_vpath); continue; } @@ -2412,6 +2522,7 @@ compute_dir_size (const char *dirname, const void *ui, if (ret != FILE_CONT) { g_free (fullname); + vfs_path_free (tmp_vpath); break; } @@ -2425,10 +2536,12 @@ compute_dir_size (const char *dirname, const void *ui, } g_free (fullname); + vfs_path_free (tmp_vpath); } mc_closedir (dir); - + ret: + vfs_path_free (vpath); return ret; } @@ -2484,6 +2597,8 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl if (single_entry) { + vfs_path_t *source_vpath; + if (force_single) source = selection (panel)->fname; else @@ -2495,8 +2610,9 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl return FALSE; } + source_vpath = vfs_path_from_str (source); /* Update stat to get actual info */ - if (mc_lstat (source, &src_stat) != 0) + if (mc_lstat (source_vpath, &src_stat) != 0) { message (D_ERROR, MSG_ERROR, _("Cannot stat \"%s\"\n%s"), path_trunc (source, 30), unix_error_string (errno)); @@ -2512,9 +2628,10 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl update_panels (flags, UP_KEEPSEL); } - + vfs_path_free (source_vpath); return FALSE; } + vfs_path_free (source_vpath); } ctx = file_op_context_new (operation); @@ -2718,7 +2835,11 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl { case OP_COPY: /* we use file_mask_op_follow_links only with OP_COPY */ - ctx->stat_func (source_with_path, &src_stat); + { + vfs_path_t *vpath = vfs_path_from_str (source_with_path); + ctx->stat_func (vpath, &src_stat); + vfs_path_free (vpath); + } if (S_ISDIR (src_stat.st_mode)) value = copy_dir_dir (tctx, ctx, source_with_path, dest, @@ -2754,8 +2875,10 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl { int dst_result; struct stat dst_stat; + vfs_path_t *vpath = vfs_path_from_str (dest); - dst_result = mc_stat (dest, &dst_stat); + dst_result = mc_stat (vpath, &dst_stat); + vfs_path_free (vpath); if ((dst_result != 0) || S_ISDIR (dst_stat.st_mode)) break; @@ -2816,7 +2939,13 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl { case OP_COPY: /* we use file_mask_op_follow_links only with OP_COPY */ - ctx->stat_func (source_with_path, &src_stat); + { + vfs_path_t *vpath; + + vpath = vfs_path_from_str (source_with_path); + ctx->stat_func (vpath, &src_stat); + vfs_path_free (vpath); + } if (S_ISDIR (src_stat.st_mode)) value = copy_dir_dir (tctx, ctx, source_with_path, temp2, TRUE, FALSE, FALSE, NULL); diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index c6e4f1e3b..18ef3cafe 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -1073,6 +1073,7 @@ file_mask_dialog (FileOpContext * ctx, FileOperation operation, { struct stat buf; + vfs_path_t *vpath; QuickDialog Quick_input = { fmd_xlen, FMDY, -1, -1, op_names[operation], @@ -1137,6 +1138,7 @@ file_mask_dialog (FileOpContext * ctx, FileOperation operation, tmp = dest_dir; dest_dir = tilde_expand (tmp); g_free (tmp); + vpath = vfs_path_from_str (dest_dir); ctx->dest_mask = strrchr (dest_dir, PATH_SEP); if (ctx->dest_mask == NULL) @@ -1144,13 +1146,13 @@ file_mask_dialog (FileOpContext * ctx, FileOperation operation, else ctx->dest_mask++; orig_mask = ctx->dest_mask; - if (!*ctx->dest_mask + if (*ctx->dest_mask == '\0' || (!ctx->dive_into_subdirs && !is_wildcarded (ctx->dest_mask) && (!only_one - || (!mc_stat (dest_dir, &buf) && S_ISDIR (buf.st_mode)))) + || (mc_stat (vpath, &buf) == 0 && S_ISDIR (buf.st_mode)))) || (ctx->dive_into_subdirs && ((!only_one && !is_wildcarded (ctx->dest_mask)) - || (only_one && !mc_stat (dest_dir, &buf) && S_ISDIR (buf.st_mode))))) + || (only_one && mc_stat (vpath, &buf) == 0 && S_ISDIR (buf.st_mode))))) ctx->dest_mask = g_strdup ("\\0"); else { @@ -1162,6 +1164,7 @@ file_mask_dialog (FileOpContext * ctx, FileOperation operation, g_free (dest_dir); dest_dir = g_strdup ("./"); } + vfs_path_free (vpath); if (val == B_USER) *do_bg = TRUE; } diff --git a/src/filemanager/fileopctx.h b/src/filemanager/fileopctx.h index 24ef9af28..ea9c0cabb 100644 --- a/src/filemanager/fileopctx.h +++ b/src/filemanager/fileopctx.h @@ -20,11 +20,12 @@ #include /* uintmax_t */ #include "lib/global.h" +#include "lib/vfs/vfs.h" /*** typedefs(not structures) and defined constants **********************************************/ -typedef int (*mc_stat_fn) (const char *filename, struct stat * buf); +typedef int (*mc_stat_fn) (const vfs_path_t * vpath, struct stat * buf); /*** enums ***************************************************************************************/ diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 740f9fe99..96ac490e4 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -968,17 +968,21 @@ search_content (Dlg_head * h, const char *directory, const char *filename) char *fname = NULL; int file_fd; gboolean ret_val = FALSE; + vfs_path_t *vpath; fname = mc_build_filename (directory, filename, (char *) NULL); + vpath = vfs_path_from_str (fname); - if (mc_stat (fname, &s) != 0 || !S_ISREG (s.st_mode)) + if (mc_stat (vpath, &s) != 0 || !S_ISREG (s.st_mode)) { g_free (fname); + vfs_path_free (vpath); return FALSE; } file_fd = mc_open (fname, O_RDONLY); g_free (fname); + vfs_path_free (vpath); if (file_fd == -1) return FALSE; @@ -1175,6 +1179,7 @@ do_search (Dlg_head * h) while (dirp == NULL) { char *tmp = NULL; + vfs_path_t *tmp_vpath; tty_setcolor (REVERSE_COLOR); @@ -1210,6 +1215,7 @@ do_search (Dlg_head * h) g_free (directory); directory = tmp; + tmp_vpath = vfs_path_from_str (directory); if (verbose) { @@ -1222,12 +1228,13 @@ do_search (Dlg_head * h) /* mc_stat should not be called after mc_opendir because vfs_s_opendir modifies the st_nlink */ - if (mc_stat (directory, &tmp_stat) == 0) + if (mc_stat (tmp_vpath, &tmp_stat) == 0) subdirs_left = tmp_stat.st_nlink - 2; else subdirs_left = 0; dirp = mc_opendir (directory); + vfs_path_free (tmp_vpath); } /* while (!dirp) */ /* skip invalid filenames */ @@ -1255,17 +1262,18 @@ do_search (Dlg_head * h) ignore_count++; else { - char *tmp_name; + vfs_path_t *tmp_vpath; - tmp_name = mc_build_filename (directory, dp->d_name, (char *) NULL); + tmp_vpath = vfs_path_build_filename (directory, dp->d_name, (char *) NULL); - if (mc_lstat (tmp_name, &tmp_stat) == 0 && S_ISDIR (tmp_stat.st_mode)) + if (mc_lstat (tmp_vpath, &tmp_stat) == 0 && S_ISDIR (tmp_stat.st_mode)) { - push_directory (tmp_name); + push_directory (vfs_path_to_str (tmp_vpath)); + vfs_path_free (tmp_vpath); subdirs_left--; } else - g_free (tmp_name); + vfs_path_free (tmp_vpath); } } diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 946dd81cc..2a43ee618 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -1627,9 +1627,17 @@ save_cwds_stat (void) { if (panels_options.fast_reload) { - mc_stat (current_panel->cwd, &(current_panel->dir_stat)); + vfs_path_t *vpath; + + vpath = vfs_path_from_str (current_panel->cwd); + mc_stat (vpath, &(current_panel->dir_stat)); + vfs_path_free (vpath); if (get_other_type () == view_listing) - mc_stat (other_panel->cwd, &(other_panel->dir_stat)); + { + vpath = vfs_path_from_str (other_panel->cwd); + mc_stat (vpath, &(other_panel->dir_stat)); + vfs_path_free (vpath); + } } } diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 00a385fab..1191ba2f4 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -2467,12 +2467,20 @@ chdir_to_readlink (WPanel * panel) char buffer[MC_MAXPATHLEN], *p; int i; struct stat st; + vfs_path_t *panel_fname_vpath = vfs_path_from_str (selection (panel)->fname); i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1); if (i < 0) + { + vfs_path_free (panel_fname_vpath); return; - if (mc_stat (selection (panel)->fname, &st) < 0) + } + if (mc_stat (panel_fname_vpath, &st) < 0) + { + vfs_path_free (panel_fname_vpath); return; + } + vfs_path_free (panel_fname_vpath); buffer[i] = 0; if (!S_ISDIR (st.st_mode)) { @@ -3384,11 +3392,11 @@ reload_panelized (WPanel * panel) { int i, j; dir_list *list = &panel->dir; + vfs_path_t *vpath; if (panel != current_panel) { int ret; - vfs_path_t *vpath; vpath = vfs_path_from_str (panel->cwd); ret = mc_chdir (vpath); @@ -3407,9 +3415,11 @@ reload_panelized (WPanel * panel) */ do_file_mark (panel, i, 0); } - if (mc_lstat (list->list[i].fname, &list->list[i].st)) + vpath = vfs_path_from_str (list->list[i].fname); + if (mc_lstat (vpath, &list->list[i].st)) { g_free (list->list[i].fname); + vfs_path_free (vpath); continue; } if (list->list[i].f.marked) @@ -3417,6 +3427,7 @@ reload_panelized (WPanel * panel) if (j != i) list->list[j] = list->list[i]; j++; + vfs_path_free (vpath); } if (j == 0) panel->count = set_zero_dir (list) ? 1 : 0; @@ -3426,7 +3437,6 @@ reload_panelized (WPanel * panel) if (panel != current_panel) { int ret; - vfs_path_t *vpath; vpath = vfs_path_from_str (current_panel->cwd); ret = mc_chdir (vpath); diff --git a/src/filemanager/treestore.c b/src/filemanager/treestore.c index 216e74b5d..419b2b575 100644 --- a/src/filemanager/treestore.c +++ b/src/filemanager/treestore.c @@ -795,7 +795,7 @@ tree_entry * tree_store_start_check (const char *path) { tree_entry *current, *retval; - int len; + size_t len; if (!ts.loaded) return NULL; @@ -808,9 +808,14 @@ tree_store_start_check (const char *path) if (!current) { struct stat s; + vfs_path_t *vpath = vfs_path_from_str (path); - if (mc_stat (path, &s) == -1) + if (mc_stat (vpath, &s) == -1) + { + vfs_path_free (vpath); return NULL; + } + vfs_path_free (vpath); if (!S_ISDIR (s.st_mode)) return NULL; @@ -909,7 +914,7 @@ tree_store_rescan (const char *dir) { for (dp = mc_readdir (dirp); dp; dp = mc_readdir (dirp)) { - char *full_name; + vfs_path_t *tmp_vpath; if (dp->d_name[0] == '.') { @@ -917,13 +922,13 @@ tree_store_rescan (const char *dir) continue; } - full_name = concat_dir_and_file (dir, dp->d_name); - if (mc_lstat (full_name, &buf) != -1) + tmp_vpath = vfs_path_build_filename (dir, dp->d_name, NULL); + if (mc_lstat (tmp_vpath, &buf) != -1) { if (S_ISDIR (buf.st_mode)) tree_store_mark_checked (dp->d_name); } - g_free (full_name); + vfs_path_free (tmp_vpath); } mc_closedir (dirp); } diff --git a/src/vfs/cpio/cpio.c b/src/vfs/cpio/cpio.c index 5fca0d564..435412180 100644 --- a/src/vfs/cpio/cpio.c +++ b/src/vfs/cpio/cpio.c @@ -215,17 +215,19 @@ cpio_free_archive (struct vfs_class *me, struct vfs_s_super *super) /* --------------------------------------------------------------------------------------------- */ static int -cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super, const char *name) +cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super, const vfs_path_t * vpath) { int fd, type; cpio_super_data_t *arch; mode_t mode; struct vfs_s_inode *root; + char *name = vfs_path_to_str (vpath); fd = mc_open (name, O_RDONLY); if (fd == -1) { message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), name); + g_free (name); return -1; } @@ -233,7 +235,7 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super, const char super->data = g_new (cpio_super_data_t, 1); arch = (cpio_super_data_t *) super->data; arch->fd = -1; /* for now */ - mc_stat (name, &arch->st); + mc_stat (vpath, &arch->st); arch->type = CPIO_UNKNOWN; arch->deferred = NULL; @@ -249,6 +251,7 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super, const char { message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), s); g_free (s); + g_free (name); return -1; } g_free (s); @@ -268,6 +271,7 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super, const char super->root = root; CPIO_SEEK_SET (super, 0); + g_free (name); return fd; } @@ -723,15 +727,11 @@ cpio_open_archive (struct vfs_s_super *super, const vfs_path_t * vpath, const vfs_path_element_t * vpath_element) { int status = STATUS_START; - char *archive_name = vfs_path_to_str (vpath); (void) vpath_element; - if (cpio_open_cpio_file (vpath_element->class, super, archive_name) == -1) - { - g_free (archive_name); + if (cpio_open_cpio_file (vpath_element->class, super, vpath) == -1) return -1; - } while (TRUE) { @@ -740,8 +740,14 @@ cpio_open_archive (struct vfs_s_super *super, const vfs_path_t * vpath, switch (status) { case STATUS_EOF: - message (D_ERROR, MSG_ERROR, _("Unexpected end of file\n%s"), archive_name); - return 0; + { + char *archive_name; + + archive_name = vfs_path_to_str (vpath); + message (D_ERROR, MSG_ERROR, _("Unexpected end of file\n%s"), archive_name); + g_free (archive_name); + return 0; + } case STATUS_OK: continue; case STATUS_TRAIL: @@ -750,7 +756,6 @@ cpio_open_archive (struct vfs_s_super *super, const vfs_path_t * vpath, break; } - g_free (archive_name); return 0; } @@ -761,11 +766,9 @@ static void * cpio_super_check (const vfs_path_t * vpath) { static struct stat sb; - char *archive_name = vfs_path_to_str (vpath); int stat_result; - stat_result = mc_stat (archive_name, &sb); - g_free (archive_name); + stat_result = mc_stat (vpath, &sb); return (stat_result == 0 ? &sb : NULL); } diff --git a/src/vfs/extfs/extfs.c b/src/vfs/extfs/extfs.c index 785f082b7..18cddf3ba 100644 --- a/src/vfs/extfs/extfs.c +++ b/src/vfs/extfs/extfs.c @@ -375,8 +375,11 @@ extfs_free_archive (struct archive *archive) if (archive->local_name != NULL) { struct stat my; + vfs_path_t *tmp_vpath; - mc_stat (archive->local_name, &my); + tmp_vpath = vfs_path_from_str (archive->local_name); + mc_stat (tmp_vpath, &my); + vfs_path_free (tmp_vpath); mc_ungetlocalcopy (archive->name, archive->local_name, archive->local_stat.st_mtime != my.st_mtime); g_free (archive->local_name); @@ -392,7 +395,7 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc) { const extfs_plugin_info_t *info; static dev_t archive_counter = 0; - FILE *result; + FILE *result = NULL; mode_t mode; char *cmd; struct stat mystat; @@ -410,14 +413,14 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc) if (info->need_archive) { - if (mc_stat (name, &mystat) == -1) - return NULL; + if (mc_stat (vpath, &mystat) == -1) + goto ret; if (!vfs_file_is_local (vpath)) { local_name = mc_getlocalcopy (name); if (local_name == NULL) - return NULL; + goto ret; } tmp = name_quote ((vpath != NULL) ? path_element->path : name, 0); } @@ -437,8 +440,7 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc) mc_ungetlocalcopy (name, local_name, 0); g_free (local_name); } - vfs_path_free (vpath); - return NULL; + goto ret; } #ifdef ___QNXNTO__ @@ -451,7 +453,11 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc) current_archive->local_name = local_name; if (local_name != NULL) - mc_stat (local_name, ¤t_archive->local_stat); + { + vfs_path_t *tmp_vpath = vfs_path_from_str (local_name); + mc_stat (tmp_vpath, ¤t_archive->local_stat); + vfs_path_free (tmp_vpath); + } current_archive->inode_counter = 0; current_archive->fd_usage = 0; current_archive->rdev = archive_counter++; @@ -475,6 +481,7 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc) *pparc = current_archive; + ret: vfs_path_free (vpath); return result; } diff --git a/src/vfs/tar/tar.c b/src/vfs/tar/tar.c index 320325a90..eec42696b 100644 --- a/src/vfs/tar/tar.c +++ b/src/vfs/tar/tar.c @@ -300,7 +300,7 @@ tar_open_archive_int (struct vfs_class *me, const vfs_path_t * vpath, struct vfs archive->name = archive_name; archive->data = g_new (tar_super_data_t, 1); arch = (tar_super_data_t *) archive->data; - mc_stat (archive_name, &arch->st); + mc_stat (vpath, &arch->st); arch->fd = -1; arch->type = TAR_UNKNOWN; @@ -819,11 +819,9 @@ static void * tar_super_check (const vfs_path_t * vpath) { static struct stat stat_buf; - char *archive_name = vfs_path_to_str (vpath); int stat_result; - stat_result = mc_stat (archive_name, &stat_buf); - g_free (archive_name); + stat_result = mc_stat (vpath, &stat_buf); return (stat_result != 0) ? NULL : &stat_buf; } -- 2.11.4.GIT