From a337f84dedbe73e282c5d8a0fc879c58b4c9c0bb Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 4 Jan 2012 15:34:05 +0300 Subject: [PATCH] Changed input parameters of mc_mkstemp() and mc_tempdir() functions to handle vfs_path_t type. Signed-off-by: Slava Zanko --- lib/vfs/direntry.c | 11 +++++++++-- lib/vfs/interface.c | 41 ++++++++++++++++++++++++--------------- lib/vfs/utilvfs.c | 4 ++-- lib/vfs/utilvfs.h | 2 +- lib/vfs/vfs.h | 2 +- src/diffviewer/ydiff.c | 20 +++++++++++-------- src/editor/edit-impl.h | 3 ++- src/editor/edit.c | 6 ++++-- src/editor/editcmd.c | 28 ++++++++++++--------------- src/filemanager/ext.c | 48 ++++++++++++++++++++++++++-------------------- src/filemanager/usermenu.c | 25 ++++++++++++++++-------- src/vfs/extfs/extfs.c | 9 ++++++--- src/vfs/fish/fish.c | 11 +++++++++-- src/vfs/ftpfs/ftpfs.c | 15 +++++++++++---- src/vfs/sfs/sfs.c | 26 +++++++++++++++---------- tests/lib/vfs/tempdir.c | 15 +++++++++++++-- 16 files changed, 168 insertions(+), 98 deletions(-) diff --git a/lib/vfs/direntry.c b/lib/vfs/direntry.c index e80028e4d..a4ca04861 100644 --- a/lib/vfs/direntry.c +++ b/lib/vfs/direntry.c @@ -1220,7 +1220,11 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) vfs_s_insert_entry (path_element->class, dir, ent); if ((VFSDATA (path_element)->flags & VFS_S_USETMP) != 0) { - tmp_handle = vfs_mkstemps (&ino->localname, path_element->class->name, name); + vfs_path_t *tmp_vpath; + + tmp_handle = vfs_mkstemps (&tmp_vpath, path_element->class->name, name); + ino->localname = vfs_path_to_str (tmp_vpath); + vfs_path_free (tmp_vpath); if (tmp_handle == -1) { g_free (dirname); @@ -1300,6 +1304,7 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino) int handle, n; off_t stat_size = ino->st.st_size; vfs_file_handler_t fh; + vfs_path_t *tmp_vpath; if ((MEDATA->flags & VFS_S_USETMP) == 0) return -1; @@ -1309,7 +1314,9 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino) fh.ino = ino; fh.handle = -1; - handle = vfs_mkstemps (&ino->localname, me->name, ino->ent->name); + handle = vfs_mkstemps (&tmp_vpath, me->name, ino->ent->name); + ino->localname = vfs_path_to_str (tmp_vpath); + vfs_path_free (tmp_vpath); if (handle == -1) { me->verrno = errno; diff --git a/lib/vfs/interface.c b/lib/vfs/interface.c index f3e634541..50f3667cc 100644 --- a/lib/vfs/interface.c +++ b/lib/vfs/interface.c @@ -79,6 +79,7 @@ static char * mc_def_getlocalcopy (const char *filename) { char *tmp = NULL; + vfs_path_t *tmp_vpath = NULL; int fdin = -1, fdout = -1; ssize_t i; char buffer[BUF_1K * 8]; @@ -90,7 +91,7 @@ mc_def_getlocalcopy (const char *filename) if (fdin == -1) goto fail; - fdout = vfs_mkstemps (&tmp, "vfs", filename); + fdout = vfs_mkstemps (&tmp_vpath, "vfs", filename); if (fdout == -1) goto fail; @@ -105,26 +106,27 @@ mc_def_getlocalcopy (const char *filename) fdin = -1; if (i == -1) goto fail; - if (close (fdout) == -1) + i = close (fdout); + fdout = -1; + if (i == -1) { fdout = -1; goto fail; } if (mc_stat (vpath, &mystat) != -1) - chmod (tmp, mystat.st_mode); - vfs_path_free (vpath); + mc_chmod (tmp_vpath, mystat.st_mode); - return tmp; + tmp = vfs_path_to_str (tmp_vpath); fail: vfs_path_free (vpath); + vfs_path_free (tmp_vpath); if (fdout != -1) close (fdout); if (fdin != -1) mc_close (fdin); - g_free (tmp); - return NULL; + return tmp; } /* --------------------------------------------------------------------------------------------- */ @@ -763,7 +765,7 @@ mc_lseek (int fd, off_t offset, int whence) */ int -mc_mkstemps (char **pname, const char *prefix, const char *suffix) +mc_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *suffix) { static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; static unsigned long value; @@ -771,6 +773,7 @@ mc_mkstemps (char **pname, const char *prefix, const char *suffix) char *tmpbase; char *tmpname; char *XXXXXX; + char *ret_path; int count; if (strchr (prefix, PATH_SEP) == NULL) @@ -784,7 +787,7 @@ mc_mkstemps (char **pname, const char *prefix, const char *suffix) } tmpname = g_strconcat (tmpbase, "XXXXXX", suffix, (char *) NULL); - *pname = tmpname; + ret_path = tmpname; XXXXXX = &tmpname[strlen (tmpbase)]; g_free (tmpbase); @@ -814,6 +817,8 @@ mc_mkstemps (char **pname, const char *prefix, const char *suffix) if (fd >= 0) { /* Successfully created. */ + *pname_vpath = vfs_path_from_str (ret_path); + g_free (ret_path); return fd; } @@ -824,8 +829,8 @@ mc_mkstemps (char **pname, const char *prefix, const char *suffix) } /* Unsuccessful. Free the filename. */ - g_free (tmpname); - *pname = NULL; + g_free (ret_path); + *pname_vpath = NULL; return -1; } @@ -894,25 +899,30 @@ mc_tmpdir (void) if (error != NULL) { int test_fd; - char *test_fn, *fallback_prefix; - int fallback_ok = 0; + char *fallback_prefix; + gboolean fallback_ok = FALSE; + vfs_path_t *test_vpath; if (*error) fprintf (stderr, error, buffer); /* Test if sys_tmp is suitable for temporary files */ fallback_prefix = g_strdup_printf ("%s/mctest", sys_tmp); - test_fd = mc_mkstemps (&test_fn, fallback_prefix, NULL); + test_fd = mc_mkstemps (&test_vpath, fallback_prefix, NULL); g_free (fallback_prefix); if (test_fd != -1) { + char *test_fn; + + test_fn = vfs_path_to_str (test_vpath); close (test_fd); test_fd = open (test_fn, O_RDONLY); + g_free (test_fn); if (test_fd != -1) { close (test_fd); unlink (test_fn); - fallback_ok = 1; + fallback_ok = TRUE; } } @@ -928,6 +938,7 @@ mc_tmpdir (void) g_snprintf (buffer, sizeof (buffer), "%s", "/dev/null/"); } + vfs_path_free (test_vpath); fprintf (stderr, "%s\n", _("Press any key to continue...")); getc (stdin); } diff --git a/lib/vfs/utilvfs.c b/lib/vfs/utilvfs.c index 5f9385565..97ac6d1f4 100644 --- a/lib/vfs/utilvfs.c +++ b/lib/vfs/utilvfs.c @@ -166,7 +166,7 @@ vfs_findgid (const char *gname) */ int -vfs_mkstemps (char **pname, const char *prefix, const char *param_basename) +vfs_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *param_basename) { const char *p; char *suffix, *q; @@ -197,7 +197,7 @@ vfs_mkstemps (char **pname, const char *prefix, const char *param_basename) } *q = 0; - fd = mc_mkstemps (pname, prefix, suffix); + fd = mc_mkstemps (pname_vpath, prefix, suffix); g_free (suffix); return fd; } diff --git a/lib/vfs/utilvfs.h b/lib/vfs/utilvfs.h index b6ffd60bc..cc21d26f9 100644 --- a/lib/vfs/utilvfs.h +++ b/lib/vfs/utilvfs.h @@ -42,7 +42,7 @@ int vfs_findgid (const char *name); vfs_path_element_t *vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags); int vfs_split_text (char *p); -int vfs_mkstemps (char **pname, const char *prefix, const char *basename); +int vfs_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *basename); void vfs_die (const char *msg); char *vfs_get_password (const char *msg); diff --git a/lib/vfs/vfs.h b/lib/vfs/vfs.h index 0b592b018..57b599eba 100644 --- a/lib/vfs/vfs.h +++ b/lib/vfs/vfs.h @@ -303,7 +303,7 @@ int mc_open (const vfs_path_t * vpath, int flags, ...); char *mc_get_current_wd (char *buffer, size_t bufsize); char *mc_getlocalcopy (const char *pathname); int mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed); -int mc_mkstemps (char **pname, const char *prefix, const char *suffix); +int mc_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *suffix); /* Creating temporary files safely */ const char *mc_tmpdir (void); diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index 20b28d6a4..042f0cbc7 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -152,14 +152,17 @@ dview_select_encoding (WDiff * dview) #endif } +/* --------------------------------------------------------------------------------------------- */ static gboolean -rewrite_backup_content (const char *from_file_name, const char *to_file_name) +rewrite_backup_content (const vfs_path_t * from_file_name_vpath, const char *to_file_name) { FILE *backup_fd; char *contents; gsize length; + const char *from_file_name; + from_file_name = vfs_path_get_by_index (from_file_name_vpath, -1)->path; if (!g_file_get_contents (from_file_name, &contents, &length, NULL)) return FALSE; @@ -194,7 +197,7 @@ static int open_temp (void **name) { int fd; - char *diff_file_name = NULL; + vfs_path_t *diff_file_name = NULL; fd = mc_mkstemps (&diff_file_name, "mcdiff", NULL); if (fd == -1) @@ -203,7 +206,8 @@ open_temp (void **name) _("Cannot create temporary diff file\n%s"), unix_error_string (errno)); return -1; } - *name = diff_file_name; + *name = vfs_path_to_str (diff_file_name); + vfs_path_free (diff_file_name); return fd; } @@ -2198,7 +2202,7 @@ do_merge_hunk (WDiff * dview) { int merge_file_fd; FILE *merge_file; - char *merge_file_name = NULL; + vfs_path_t *merge_file_name_vpath = NULL; if (!dview->merged) { @@ -2213,7 +2217,7 @@ do_merge_hunk (WDiff * dview) } - merge_file_fd = mc_mkstemps (&merge_file_name, "mcmerge", NULL); + merge_file_fd = mc_mkstemps (&merge_file_name_vpath, "mcmerge", NULL); if (merge_file_fd == -1) { message (D_ERROR, MSG_ERROR, _("Cannot create temporary merge file\n%s"), @@ -2237,9 +2241,9 @@ do_merge_hunk (WDiff * dview) } fflush (merge_file); fclose (merge_file); - res = rewrite_backup_content (merge_file_name, dview->file[0]); - unlink (merge_file_name); - g_free (merge_file_name); + res = rewrite_backup_content (merge_file_name_vpath, dview->file[0]); + mc_unlink (merge_file_name_vpath); + vfs_path_free (merge_file_name_vpath); } } diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index 0ea240f26..e862a4f19 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -15,6 +15,7 @@ #include "lib/search.h" /* mc_search_type_t */ #include "lib/widget.h" /* cb_ret_t */ +#include "lib/vfs/vfs.h" /* vfs_path_t */ #include "edit.h" @@ -219,7 +220,7 @@ void edit_push_redo_action (WEdit * edit, long c, ...); void edit_push_key_press (WEdit * edit); void edit_insert_ahead (WEdit * edit, int c); long edit_write_stream (WEdit * edit, FILE * f); -char *edit_get_write_filter (const char *writename, const char *filename); +char *edit_get_write_filter (const vfs_path_t * write_name_vpath, const char *filename); int edit_save_confirm_cmd (WEdit * edit); int edit_save_as_cmd (WEdit * edit); WEdit *edit_init (WEdit * edit, int y, int x, int lines, int cols, const char *filename, long line); diff --git a/src/editor/edit.c b/src/editor/edit.c index 6fe33ce09..6768b604e 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -1966,16 +1966,18 @@ edit_get_utf (WEdit * edit, long byte_index, int *char_width) /* --------------------------------------------------------------------------------------------- */ char * -edit_get_write_filter (const char *write_name, const char *filename) +edit_get_write_filter (const vfs_path_t * write_name_vpath, const char *filename) { int i; char *p, *writename; + vfs_path_element_t *path_element; i = edit_find_filter (filename); if (i < 0) return NULL; - writename = name_quote (write_name, 0); + path_element = vfs_path_get_by_index (write_name_vpath, -1); + writename = name_quote (path_element->path, 0); p = g_strdup_printf (all_filters[i].write, writename); g_free (writename); return p; diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 6bdd950dc..8e78e7102 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -123,11 +123,10 @@ edit_save_file (WEdit * edit, const char *filename) char *p; gchar *tmp; long filelen = 0; - char *savename = 0; gchar *real_filename; int this_save_mode, fd = -1; vfs_path_t *real_filename_vpath; - vfs_path_t *savename_vpath; + vfs_path_t *savename_vpath = NULL; if (!filename) return 0; @@ -217,11 +216,11 @@ edit_save_file (WEdit * edit, const char *filename) } else savedir = g_strdup ("."); - saveprefix = concat_dir_and_file (savedir, "cooledit"); + saveprefix = mc_build_filename (savedir, "cooledit", NULL); g_free (savedir); - fd = mc_mkstemps (&savename, saveprefix, NULL); + fd = mc_mkstemps (&savename_vpath, saveprefix, NULL); g_free (saveprefix); - if (!savename) + if (savename_vpath == NULL) { g_free (real_filename); vfs_path_free (real_filename_vpath); @@ -235,9 +234,7 @@ edit_save_file (WEdit * edit, const char *filename) close (fd); } else - savename = g_strdup (real_filename); - - savename_vpath = vfs_path_from_str (savename); + savename_vpath = vfs_path_from_str (real_filename); (void) mc_chown (savename_vpath, edit->stat1.st_uid, edit->stat1.st_gid); (void) mc_chmod (savename_vpath, edit->stat1.st_mode); @@ -247,7 +244,7 @@ edit_save_file (WEdit * edit, const char *filename) goto error_save; /* pipe save */ - p = edit_get_write_filter (savename, real_filename); + p = edit_get_write_filter (savename_vpath, real_filename); if (p != NULL) { FILE *file; @@ -330,19 +327,19 @@ edit_save_file (WEdit * edit, const char *filename) goto error_save; /* Update the file information, especially the mtime. */ - savename_vpath = vfs_path_from_str (savename); if (mc_stat (savename_vpath, &edit->stat1) == -1) goto error_save; } else { /* change line breaks */ FILE *file; + vfs_path_element_t *path_element; mc_close (fd); - file = (FILE *) fopen (savename, "w"); - - if (file) + path_element = vfs_path_get_by_index (savename_vpath, -1); + file = (FILE *) fopen (path_element->path, "w"); + if (file != NULL) { filelen = edit_write_stream (edit, file); fclose (file); @@ -351,7 +348,7 @@ edit_save_file (WEdit * edit, const char *filename) { char *msg; - msg = g_strdup_printf (_("Cannot open file for writing: %s"), savename); + msg = g_strdup_printf (_("Cannot open file for writing: %s"), path_element->path); edit_error_dialog (_("Error"), msg); g_free (msg); goto error_save; @@ -379,8 +376,8 @@ edit_save_file (WEdit * edit, const char *filename) if (this_save_mode != EDIT_QUICK_SAVE) if (mc_rename (savename_vpath, real_filename_vpath) == -1) goto error_save; + g_free (real_filename); - g_free (savename); vfs_path_free (real_filename_vpath); vfs_path_free (savename_vpath); return 1; @@ -390,7 +387,6 @@ edit_save_file (WEdit * edit, const char *filename) * mc_unlink (savename); */ g_free (real_filename); - g_free (savename); vfs_path_free (real_filename_vpath); vfs_path_free (savename_vpath); return 0; diff --git a/src/filemanager/ext.c b/src/filemanager/ext.c index a30cc4ba1..001c354f5 100644 --- a/src/filemanager/ext.c +++ b/src/filemanager/ext.c @@ -92,7 +92,7 @@ static char *data = NULL; static void exec_extension (const char *filename, const char *lc_data, int *move_dir, int start_line) { - char *file_name; + vfs_path_t *file_name_vpath; int cmd_file_fd; FILE *cmd_file; char *cmd = NULL; @@ -119,10 +119,7 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st vpath = vfs_path_from_str (filename); /* Avoid making a local copy if we are doing a cd */ - if (!vfs_file_is_local (vpath)) - do_local_copy = 1; - else - do_local_copy = 0; + do_local_copy = vfs_file_is_local (vpath) ? 0 : 1; /* * All commands should be run in /bin/sh regardless of user shell. @@ -130,13 +127,13 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st * Sometimes it's not needed (e.g. for %cd and %view commands), * but it's easier to create it anyway. */ - cmd_file_fd = mc_mkstemps (&file_name, "mcext", SCRIPT_SUFFIX); + cmd_file_fd = mc_mkstemps (&file_name_vpath, "mcext", SCRIPT_SUFFIX); if (cmd_file_fd == -1) { message (D_ERROR, MSG_ERROR, _("Cannot create temporary command file\n%s"), unix_error_string (errno)); - return; + goto ret; } cmd_file = fdopen (cmd_file_fd, "w"); @@ -157,15 +154,13 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st { /* User canceled */ fclose (cmd_file); - unlink (file_name); + mc_unlink (file_name_vpath); if (localcopy) { mc_ungetlocalcopy (filename, localcopy, 0); g_free (localcopy); } - g_free (file_name); - vfs_path_free (vpath); - return; + goto ret; } fputs (parameter, cmd_file); written_nonspace = 1; @@ -229,14 +224,13 @@ 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) { fclose (cmd_file); - unlink (file_name); - g_free (file_name); - vfs_path_free (vpath); - return; + mc_unlink (file_name_vpath); + goto ret; } vpath_local = vfs_path_from_str (localcopy); mc_stat (vpath_local, &mystat); @@ -247,6 +241,7 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st else { vfs_path_element_t *path_element; + path_element = vfs_path_get_by_index (vpath, -1); text = quote_func (path_element->path, 0); } @@ -286,22 +281,32 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st * so we clean up after calling view(). */ if (!run_view) + { + char *file_name; + + file_name = vfs_path_to_str (file_name_vpath); fprintf (cmd_file, "\n/bin/rm -f %s\n", file_name); + g_free (file_name); + } fclose (cmd_file); if ((run_view && !written_nonspace) || is_cd) { - unlink (file_name); - g_free (file_name); - file_name = NULL; + mc_unlink (file_name_vpath); + vfs_path_free (file_name_vpath); + file_name_vpath = NULL; } else { + char *file_name; + + file_name = vfs_path_to_str (file_name_vpath); /* Set executable flag on the command file ... */ - chmod (file_name, S_IRWXU); + mc_chmod (file_name_vpath, S_IRWXU); /* ... but don't rely on it - run /bin/sh explicitly */ cmd = g_strconcat ("/bin/sh ", file_name, (char *) NULL); + g_free (file_name); } if (run_view) @@ -321,7 +326,7 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st if (written_nonspace) { ret = mcview_viewer (cmd, filename, start_line); - unlink (file_name); + mc_unlink (file_name_vpath); } else ret = mcview_viewer (NULL, filename, start_line); @@ -375,7 +380,6 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st } } - g_free (file_name); g_free (cmd); if (localcopy) @@ -388,6 +392,8 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st vfs_path_free (vpath_local); g_free (localcopy); } + ret: + vfs_path_free (file_name_vpath); vfs_path_free (vpath); } diff --git a/src/filemanager/usermenu.c b/src/filemanager/usermenu.c index a35a05e17..ba0006726 100644 --- a/src/filemanager/usermenu.c +++ b/src/filemanager/usermenu.c @@ -418,7 +418,7 @@ execute_menu_command (WEdit * edit_widget, const char *commands, gboolean show_p gboolean do_quote = FALSE; char lc_prompt[80]; int col; - char *file_name; + vfs_path_t *file_name_vpath; int run_view = 0; /* Skip menu entry title line */ @@ -428,12 +428,13 @@ execute_menu_command (WEdit * edit_widget, const char *commands, gboolean show_p return; } - cmd_file_fd = mc_mkstemps (&file_name, "mcusr", SCRIPT_SUFFIX); + cmd_file_fd = mc_mkstemps (&file_name_vpath, "mcusr", SCRIPT_SUFFIX); if (cmd_file_fd == -1) { message (D_ERROR, MSG_ERROR, _("Cannot create temporary command file\n%s"), unix_error_string (errno)); + vfs_path_free (file_name_vpath); return; } cmd_file = fdopen (cmd_file_fd, "w"); @@ -466,8 +467,8 @@ execute_menu_command (WEdit * edit_widget, const char *commands, gboolean show_p { /* User canceled */ fclose (cmd_file); - unlink (file_name); - g_free (file_name); + mc_unlink (file_name_vpath); + vfs_path_free (file_name_vpath); return; } if (do_quote) @@ -528,17 +529,25 @@ execute_menu_command (WEdit * edit_widget, const char *commands, gboolean show_p } } fclose (cmd_file); - chmod (file_name, S_IRWXU); + mc_chmod (file_name_vpath, S_IRWXU); if (run_view) { + char *file_name; + + file_name = vfs_path_to_str (file_name_vpath); mcview_viewer (file_name, NULL, 0); + g_free (file_name); dialog_switch_process_pending (); } else { /* execute the command indirectly to allow execution even * on no-exec filesystems. */ - char *cmd = g_strconcat ("/bin/sh ", file_name, (char *) NULL); + char *file_name, *cmd; + + file_name = vfs_path_to_str (file_name_vpath); + cmd = g_strconcat ("/bin/sh ", file_name, (char *) NULL); + g_free (file_name); if (!show_prompt) { if (system (cmd) == -1) @@ -550,8 +559,8 @@ execute_menu_command (WEdit * edit_widget, const char *commands, gboolean show_p } g_free (cmd); } - unlink (file_name); - g_free (file_name); + mc_unlink (file_name_vpath); + vfs_path_free (file_name_vpath); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/extfs/extfs.c b/src/vfs/extfs/extfs.c index 18cddf3ba..5a67ca519 100644 --- a/src/vfs/extfs/extfs.c +++ b/src/vfs/extfs/extfs.c @@ -921,23 +921,26 @@ extfs_open (const vfs_path_t * vpath, int flags, mode_t mode) if (entry->inode->local_filename == NULL) { + vfs_path_t *local_filename_vpath; char *local_filename; - local_handle = vfs_mkstemps (&local_filename, "extfs", entry->name); + local_handle = vfs_mkstemps (&local_filename_vpath, "extfs", entry->name); if (local_handle == -1) return NULL; close (local_handle); + local_filename = vfs_path_get_by_index (local_filename_vpath, -1)->path; if (!created && ((flags & O_TRUNC) == 0) && extfs_cmd (" copyout ", archive, entry, local_filename)) { unlink (local_filename); - g_free (local_filename); + vfs_path_free (local_filename_vpath); my_errno = EIO; return NULL; } - entry->inode->local_filename = local_filename; + entry->inode->local_filename = g_strdup (local_filename); + vfs_path_free (local_filename_vpath); } local_handle = open (entry->inode->local_filename, NO_LINEAR (flags), mode); diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c index d1a0998f7..84de9540a 100644 --- a/src/vfs/fish/fish.c +++ b/src/vfs/fish/fish.c @@ -1522,10 +1522,17 @@ fish_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t m if (!fh->ino->localname) { - int tmp_handle = vfs_mkstemps (&fh->ino->localname, me->name, - fh->ino->ent->name); + vfs_path_t *vpath; + int tmp_handle; + + tmp_handle = vfs_mkstemps (&vpath, me->name, fh->ino->ent->name); if (tmp_handle == -1) + { + vfs_path_free (vpath); goto fail; + } + fh->ino->localname = vfs_path_to_str (vpath); + vfs_path_free (vpath); close (tmp_handle); } return 0; diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index 25494284c..fe788db00 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -629,7 +629,7 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char reply_up = g_ascii_strup (reply_string, -1); SUP->remote_is_amiga = strstr (reply_up, "AMIGA") != 0; - if (strstr (reply_up, " SPFTP/1.0.0000 SERVER ")) /* handles `LIST -la` in a weird way */ + if (strstr (reply_up, " SPFTP/1.0.0000 SERVER ")) /* handles `LIST -la` in a weird way */ SUP->strict = RFC_STRICT; g_free (reply_up); @@ -2107,7 +2107,7 @@ ftpfs_rmdir (const vfs_path_t * vpath) /* --------------------------------------------------------------------------------------------- */ static void -ftpfs_fh_free_data (vfs_file_handler_t *fh) +ftpfs_fh_free_data (vfs_file_handler_t * fh) { if (fh != NULL) { @@ -2145,11 +2145,18 @@ ftpfs_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t { if (!fh->ino->localname) { - int handle = vfs_mkstemps (&fh->ino->localname, me->name, - fh->ino->ent->name); + vfs_path_t *vpath; + int handle; + + handle = vfs_mkstemps (&vpath, me->name, fh->ino->ent->name); if (handle == -1) + { + vfs_path_free (vpath); goto fail; + } close (handle); + fh->ino->localname = vfs_path_to_str (vpath); + vfs_path_free (vpath); ftp->append = flags & O_APPEND; } return 0; diff --git a/src/vfs/sfs/sfs.c b/src/vfs/sfs/sfs.c index bc81f332a..b34d74a99 100644 --- a/src/vfs/sfs/sfs.c +++ b/src/vfs/sfs/sfs.c @@ -120,7 +120,7 @@ cachedfile_compare (const void *a, const void *b) /* --------------------------------------------------------------------------------------------- */ static int -sfs_vfmake (const vfs_path_t * vpath, char *cache) +sfs_vfmake (const vfs_path_t * vpath, vfs_path_t * cache_vpath) { int w; char pad[10240]; @@ -178,8 +178,13 @@ sfs_vfmake (const vfs_path_t * vpath, char *cache) ptr = path_element->path; break; case '3': - ptr = cache; - break; + { + vfs_path_element_t *tmp_path_element; + + tmp_path_element = vfs_path_get_by_index (cache_vpath, -1); + ptr = tmp_path_element->path; + break; + } case '%': COPY_CHAR; continue; @@ -214,7 +219,7 @@ sfs_redirect (const vfs_path_t * vpath) { GSList *cur; cachedfile *cf; - char *cache; + vfs_path_t *cache_vpath; int handle; vfs_path_element_t *path_element; char *path = vfs_path_to_str (vpath); @@ -230,26 +235,27 @@ sfs_redirect (const vfs_path_t * vpath) return cf->cache; } - handle = vfs_mkstemps (&cache, "sfs", path_element->path); + handle = vfs_mkstemps (&cache_vpath, "sfs", path_element->path); if (handle == -1) return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US"; close (handle); - if (sfs_vfmake (vpath, cache) == 0) + if (sfs_vfmake (vpath, cache_vpath) == 0) { cf = g_new (cachedfile, 1); cf->name = vfs_path_to_str (vpath); - cf->cache = cache; + cf->cache = vfs_path_to_str (cache_vpath); head = g_slist_prepend (head, cf); + vfs_path_free (cache_vpath); vfs_stamp_create (&vfs_sfs_ops, (cachedfile *) head->data); - return cache; + return cf->cache; } - unlink (cache); - g_free (cache); + mc_unlink (cache_vpath); + vfs_path_free (cache_vpath); return "/I_MUST_NOT_EXIST"; } diff --git a/tests/lib/vfs/tempdir.c b/tests/lib/vfs/tempdir.c index 328d108ee..2a23d973a 100644 --- a/tests/lib/vfs/tempdir.c +++ b/tests/lib/vfs/tempdir.c @@ -50,11 +50,18 @@ struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3; static void setup (void) { + str_init_strings (NULL); + + vfs_init (); + init_localfs (); + vfs_setup_work_dir (); } static void teardown (void) { + vfs_shut (); + str_uninit_strings (); } /* --------------------------------------------------------------------------------------------- */ @@ -79,16 +86,20 @@ END_TEST START_TEST (test_mc_mkstemps) { - char *pname = NULL; + vfs_path_t *pname_vpath = NULL; + char *pname; char *begin_pname; int fd; - fd = mc_mkstemps (&pname, "mctest-", NULL); + fd = mc_mkstemps (&pname_vpath, "mctest-", NULL); if (fd == -1) { fail ("\nerror creating temp file!\n"); } + pname = vfs_path_to_str (pname_vpath); + vfs_path_free (pname_vpath); close (fd); + fail_unless ( g_file_test (pname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR), "\nNo such file: %s\n", pname -- 2.11.4.GIT