Use vfs_path_get_last_path_str() where it is resonable.

This commit is contained in:
Andrew Borodin 2023-07-16 11:12:15 +03:00
parent 883f7af560
commit e20d9acecb
12 changed files with 92 additions and 101 deletions

View File

@ -139,7 +139,7 @@ rewrite_backup_content (const vfs_path_t * from_file_name_vpath, const char *to_
gsize length;
const char *from_file_name;
from_file_name = vfs_path_get_by_index (from_file_name_vpath, -1)->path;
from_file_name = vfs_path_get_last_path_str (from_file_name_vpath);
if (!g_file_get_contents (from_file_name, &contents, &length, NULL))
return FALSE;

View File

@ -1826,17 +1826,17 @@ char *
edit_get_write_filter (const vfs_path_t * write_name_vpath, const vfs_path_t * filename_vpath)
{
int i;
char *p, *writename;
const vfs_path_element_t *path_element;
const char *write_name;
char *p, *write_name_quoted;
i = edit_find_filter (filename_vpath);
if (i < 0)
return NULL;
path_element = vfs_path_get_by_index (write_name_vpath, -1);
writename = name_quote (path_element->path, FALSE);
p = g_strdup_printf (all_filters[i].write, writename);
g_free (writename);
write_name = vfs_path_get_last_path_str (write_name_vpath);
write_name_quoted = name_quote (write_name, FALSE);
p = g_strdup_printf (all_filters[i].write, write_name_quoted);
g_free (write_name_quoted);
return p;
}

View File

@ -299,12 +299,12 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
else
{ /* change line breaks */
FILE *file;
const vfs_path_element_t *path_element;
const char *savename;
mc_close (fd);
path_element = vfs_path_get_by_index (savename_vpath, -1);
file = (FILE *) fopen (path_element->path, "w");
savename = vfs_path_get_last_path_str (savename_vpath);
file = (FILE *) fopen (savename, "w");
if (file != NULL)
{
filelen = edit_write_stream (edit, file);
@ -314,7 +314,7 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
{
char *msg;
msg = g_strdup_printf (_("Cannot open file for writing: %s"), path_element->path);
msg = g_strdup_printf (_("Cannot open file for writing: %s"), savename);
edit_error_dialog (_("Error"), msg);
g_free (msg);
goto error_save;

View File

@ -897,11 +897,11 @@ extfs_get_archive_name (const struct extfs_super_t *archive)
{
char *ret_str;
vfs_path_t *vpath;
const vfs_path_element_t *path_element;
const char *path;
vpath = vfs_path_from_str (archive_name);
path_element = vfs_path_get_by_index (vpath, -1);
ret_str = g_strdup (path_element->path);
path = vfs_path_get_last_path_str (vpath);
ret_str = g_strdup (path);
vfs_path_free (vpath, TRUE);
return ret_str;
}
@ -1040,7 +1040,7 @@ extfs_open (const vfs_path_t * vpath, int flags, mode_t mode)
if (local_handle == -1)
return NULL;
close (local_handle);
local_filename = vfs_path_get_by_index (local_filename_vpath, -1)->path;
local_filename = vfs_path_get_last_path_str (local_filename_vpath);
if (!created && ((flags & O_TRUNC) == 0)
&& extfs_cmd (" copyout ", archive, entry, local_filename))

View File

@ -1334,7 +1334,7 @@ fish_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
return -1;
rpath = strutils_shell_escape (crpath);
qsetto = strutils_shell_escape (vfs_path_get_by_index (vpath1, -1)->path);
qsetto = strutils_shell_escape (vfs_path_get_last_path_str (vpath1));
ret =
fish_send_command (path_element->class, super, OPT_FLUSH, FISH_SUPER (super)->scr_ln,

View File

@ -64,10 +64,10 @@ local_open (const vfs_path_t * vpath, int flags, mode_t mode)
{
int *local_info;
int fd;
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
fd = open (path_element->path, NO_LINEAR (flags), mode);
path = vfs_path_get_last_path_str (vpath);
fd = open (path, NO_LINEAR (flags), mode);
if (fd == -1)
return 0;
@ -84,9 +84,9 @@ local_opendir (const vfs_path_t * vpath)
{
DIR **local_info;
DIR *dir = NULL;
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
path = vfs_path_get_last_path_str (vpath);
/* On Linux >= 5.1, MC sometimes shows empty directories on mounted CIFS shares.
* Rereading directory restores the directory content.
@ -95,7 +95,7 @@ local_opendir (const vfs_path_t * vpath)
*/
while (dir == NULL)
{
dir = opendir (path_element->path);
dir = opendir (path);
if (dir == NULL)
return NULL;
@ -143,10 +143,10 @@ local_closedir (void *data)
static int
local_stat (const vfs_path_t * vpath, struct stat *buf)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
return stat (path_element->path, buf);
path = vfs_path_get_last_path_str (vpath);
return stat (path, buf);
}
/* --------------------------------------------------------------------------------------------- */
@ -154,13 +154,13 @@ local_stat (const vfs_path_t * vpath, struct stat *buf)
static int
local_lstat (const vfs_path_t * vpath, struct stat *buf)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
path = vfs_path_get_last_path_str (vpath);
#ifndef HAVE_STATLSTAT
return lstat (path_element->path, buf);
return lstat (path, buf);
#else
return statlstat (path_element->path, buf);
return statlstat (path, buf);
#endif
}
@ -169,10 +169,10 @@ local_lstat (const vfs_path_t * vpath, struct stat *buf)
static int
local_chmod (const vfs_path_t * vpath, mode_t mode)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
return chmod (path_element->path, mode);
path = vfs_path_get_last_path_str (vpath);
return chmod (path, mode);
}
/* --------------------------------------------------------------------------------------------- */
@ -180,10 +180,10 @@ local_chmod (const vfs_path_t * vpath, mode_t mode)
static int
local_chown (const vfs_path_t * vpath, uid_t owner, gid_t group)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
return chown (path_element->path, owner, group);
path = vfs_path_get_last_path_str (vpath);
return chown (path, owner, group);
}
/* --------------------------------------------------------------------------------------------- */
@ -193,10 +193,10 @@ local_chown (const vfs_path_t * vpath, uid_t owner, gid_t group)
static int
local_fgetflags (const vfs_path_t * vpath, unsigned long *flags)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
return fgetflags (path_element->path, flags);
path = vfs_path_get_last_path_str (vpath);
return fgetflags (path, flags);
}
/* --------------------------------------------------------------------------------------------- */
@ -204,10 +204,10 @@ local_fgetflags (const vfs_path_t * vpath, unsigned long *flags)
static int
local_fsetflags (const vfs_path_t * vpath, unsigned long flags)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
return fsetflags (path_element->path, flags);
path = vfs_path_get_last_path_str (vpath);
return fsetflags (path, flags);
}
#endif /* ENABLE_EXT2FS_ATTR */
@ -218,13 +218,13 @@ static int
local_utime (const vfs_path_t * vpath, mc_timesbuf_t * times)
{
int ret;
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
path = vfs_path_get_last_path_str (vpath);
#ifdef HAVE_UTIMENSAT
ret = utimensat (AT_FDCWD, path_element->path, *times, AT_SYMLINK_NOFOLLOW);
ret = utimensat (AT_FDCWD, path, *times, AT_SYMLINK_NOFOLLOW);
#else
ret = utime (path_element->path, times);
ret = utime (path, times);
#endif
return ret;
}
@ -234,10 +234,10 @@ local_utime (const vfs_path_t * vpath, mc_timesbuf_t * times)
static int
local_readlink (const vfs_path_t * vpath, char *buf, size_t size)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
return readlink (path_element->path, buf, size);
path = vfs_path_get_last_path_str (vpath);
return readlink (path, buf, size);
}
/* --------------------------------------------------------------------------------------------- */
@ -245,10 +245,10 @@ local_readlink (const vfs_path_t * vpath, char *buf, size_t size)
static int
local_unlink (const vfs_path_t * vpath)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
return unlink (path_element->path);
path = vfs_path_get_last_path_str (vpath);
return unlink (path);
}
/* --------------------------------------------------------------------------------------------- */
@ -256,11 +256,11 @@ local_unlink (const vfs_path_t * vpath)
static int
local_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
{
const vfs_path_element_t *path_element1, *path_element2;
const char *path1, *path2;
path_element1 = vfs_path_get_by_index (vpath1, -1);
path_element2 = vfs_path_get_by_index (vpath2, -1);
return symlink (path_element1->path, path_element2->path);
path1 = vfs_path_get_last_path_str (vpath1);
path2 = vfs_path_get_last_path_str (vpath2);
return symlink (path1, path2);
}
/* --------------------------------------------------------------------------------------------- */
@ -297,11 +297,11 @@ local_write (void *data, const char *buf, size_t nbyte)
static int
local_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
{
const vfs_path_element_t *path_element1, *path_element2;
const char *path1, *path2;
path_element1 = vfs_path_get_by_index (vpath1, -1);
path_element2 = vfs_path_get_by_index (vpath2, -1);
return rename (path_element1->path, path_element2->path);
path1 = vfs_path_get_last_path_str (vpath1);
path2 = vfs_path_get_last_path_str (vpath2);
return rename (path1, path2);
}
/* --------------------------------------------------------------------------------------------- */
@ -309,10 +309,10 @@ local_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
static int
local_chdir (const vfs_path_t * vpath)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
return chdir (path_element->path);
path = vfs_path_get_last_path_str (vpath);
return chdir (path);
}
/* --------------------------------------------------------------------------------------------- */
@ -320,10 +320,10 @@ local_chdir (const vfs_path_t * vpath)
static int
local_mknod (const vfs_path_t * vpath, mode_t mode, dev_t dev)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
return mknod (path_element->path, mode, dev);
path = vfs_path_get_last_path_str (vpath);
return mknod (path, mode, dev);
}
/* --------------------------------------------------------------------------------------------- */
@ -331,11 +331,11 @@ local_mknod (const vfs_path_t * vpath, mode_t mode, dev_t dev)
static int
local_link (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
{
const vfs_path_element_t *path_element1, *path_element2;
const char *path1, *path2;
path_element1 = vfs_path_get_by_index (vpath1, -1);
path_element2 = vfs_path_get_by_index (vpath2, -1);
return link (path_element1->path, path_element2->path);
path1 = vfs_path_get_last_path_str (vpath1);
path2 = vfs_path_get_last_path_str (vpath2);
return link (path1, path2);
}
/* --------------------------------------------------------------------------------------------- */
@ -343,10 +343,10 @@ local_link (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
static int
local_mkdir (const vfs_path_t * vpath, mode_t mode)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
return mkdir (path_element->path, mode);
path = vfs_path_get_last_path_str (vpath);
return mkdir (path, mode);
}
/* --------------------------------------------------------------------------------------------- */
@ -354,10 +354,10 @@ local_mkdir (const vfs_path_t * vpath, mode_t mode)
static int
local_rmdir (const vfs_path_t * vpath)
{
const vfs_path_element_t *path_element;
const char *path;
path_element = vfs_path_get_by_index (vpath, -1);
return rmdir (path_element->path);
path = vfs_path_get_last_path_str (vpath);
return rmdir (path);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -198,7 +198,7 @@ sfs_vfmake (const vfs_path_t * vpath, vfs_path_t * cache_vpath)
ptr = path_element->path;
break;
case '3':
ptr = vfs_path_get_by_index (cache_vpath, -1)->path;
ptr = vfs_path_get_last_path_str (cache_vpath);
break;
case '%':
COPY_CHAR;
@ -258,9 +258,7 @@ sfs_redirect (const vfs_path_t * vpath)
cachedfile *cf;
vfs_path_t *cache_vpath;
int handle;
const vfs_path_element_t *path_element;
path_element = vfs_path_get_by_index (vpath, -1);
cur = g_slist_find_custom (head, vfs_path_as_str (vpath), cachedfile_compare);
if (cur != NULL)
@ -270,7 +268,7 @@ sfs_redirect (const vfs_path_t * vpath)
return cf->cache;
}
handle = vfs_mkstemps (&cache_vpath, "sfs", path_element->path);
handle = vfs_mkstemps (&cache_vpath, "sfs", vfs_path_get_last_path_str (vpath));
if (handle == -1)
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US";

View File

@ -384,7 +384,6 @@ int
sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** mcerror)
{
sftpfs_super_t *super = NULL;
const vfs_path_element_t *path_element1;
const vfs_path_element_t *path_element2 = NULL;
const char *path1;
size_t path1_len;
@ -400,8 +399,7 @@ sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError **
tmp_path = g_strndup (ctmp_path->str, ctmp_path->len);
tmp_path_len = ctmp_path->len;
path_element1 = vfs_path_get_by_index (vpath1, -1);
path1 = path_element1->path;
path1 = vfs_path_get_last_path_str (vpath1);
path1_len = strlen (path1);
do
@ -582,7 +580,7 @@ int
sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** mcerror)
{
sftpfs_super_t *super = NULL;
const vfs_path_element_t *path_element1;
const char *path1;
const vfs_path_element_t *path_element2 = NULL;
const GString *ctmp_path;
char *tmp_path;
@ -597,9 +595,9 @@ sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** m
tmp_path = g_strndup (ctmp_path->str, ctmp_path->len);
tmp_path_len = ctmp_path->len;
path_element1 = vfs_path_get_by_index (vpath1, -1);
path1 = vfs_path_get_last_path_str (vpath1);
fixfname = sftpfs_fix_filename (path_element1->path);
fixfname = sftpfs_fix_filename (path1);
do
{

View File

@ -149,17 +149,14 @@ static void
undelfs_get_path (const vfs_path_t * vpath, char **fsname, char **file)
{
const char *p, *dirname;
const vfs_path_element_t *path_element;
path_element = vfs_path_get_by_index (vpath, -1);
dirname = vfs_path_get_last_path_str (vpath);
/* To look like filesystem, we have virtual directories
undel://XXX, which have no subdirectories. XXX is replaced with
hda5, sdb8 etc, which is assumed to live under /dev.
-- pavel@ucw.cz */
dirname = path_element->path;
*fsname = NULL;
if (strncmp (dirname, "undel://", 8) != 0)
@ -169,7 +166,7 @@ undelfs_get_path (const vfs_path_t * vpath, char **fsname, char **file)
/* Since we don't allow subdirectories, it's easy to get a filename,
* just scan backwards for a slash */
if (*dirname == 0)
if (*dirname == '\0')
return;
p = dirname + strlen (dirname);

View File

@ -139,19 +139,19 @@ START_PARAMETRIZED_TEST (test_path_recode, test_path_recode_ds)
{
/* given */
vfs_path_t *vpath;
const vfs_path_element_t *element;
const char *element_path;
const char *vpath_str;
test_init_vfs (data->input_codepage);
/* when */
vpath = vfs_path_from_str (data->input_path);
element = vfs_path_get_by_index (vpath, -1);
element_path = vfs_path_get_last_path_str (vpath);
/* then */
vpath_str = vfs_path_as_str (vpath);
mctest_assert_ptr_ne (vpath, NULL);
mctest_assert_str_eq (element->path, data->expected_element_path);
mctest_assert_str_eq (element_path, data->expected_element_path);
mctest_assert_str_eq (vpath_str, data->expected_recoded_path);
vfs_path_free (vpath, TRUE);

View File

@ -144,11 +144,11 @@ START_PARAMETRIZED_TEST (test_relative_cd, test_relative_cd_ds)
/* then */
{
const vfs_path_element_t *element;
const char *element_path;
ck_assert_int_eq (actual_result, 0);
element = vfs_path_get_by_index (vpath, -1);
mctest_assert_str_eq (element->path, data->expected_element_path);
element_path = vfs_path_get_last_path_str (vpath);
mctest_assert_str_eq (element_path, data->expected_element_path);
vfs_path_free (vpath, TRUE);
}
}

View File

@ -64,16 +64,14 @@ static int
test1_mock_archive_same (const vfs_path_element_t * vpath_element, struct vfs_s_super *super,
const vfs_path_t * vpath, void *cookie)
{
const vfs_path_element_t *path_element;
const char *path;
(void) vpath_element;
(void) super;
(void) cookie;
path_element = vfs_path_get_by_index (vpath, -1);
if (strcmp (ARCH_NAME, path_element->path) != 0)
return 0;
return 1;
path = vfs_path_get_last_path_str (vpath);
return (strcmp (ARCH_NAME, path) != 0 ? 0 : 1);
}
/* --------------------------------------------------------------------------------------------- */