updated: [master] [a3ce493] vfs: fix tempdir path building to account for trailing slash on macOS

1 view
Skip to first unread message

Yury V. Zaytsev

unread,
Sep 3, 2024, 1:40:35 AM9/3/24
to mc-co...@googlegroups.com
The following commit has been merged in the master branch:
commit a3ce493ae25f35f29919332d4794c17109f56901
Author: Yury V. Zaytsev <yu...@shurup.com>
Date: Thu Aug 29 12:13:40 2024 +0200

vfs: fix tempdir path building to account for trailing slash on macOS

Signed-off-by: Yury V. Zaytsev <yu...@shurup.com>

diff --git a/lib/vfs/interface.c b/lib/vfs/interface.c
index 63bbdde..0bd0ba2 100644
--- a/lib/vfs/interface.c
+++ b/lib/vfs/interface.c
@@ -775,6 +775,7 @@ mc_tmpdir (void)
static const char *tmpdir = NULL;
const char *sys_tmp;
struct stat st;
+ gchar *template;

/* Check if already correctly initialized */
if (tmpdir != NULL && lstat (tmpdir, &st) == 0 && S_ISDIR (st.st_mode) &&
@@ -789,7 +790,10 @@ mc_tmpdir (void)
sys_tmp = TMPDIR_DEFAULT;
}

- g_snprintf (buffer, sizeof (buffer), "%s/mc-XXXXXX", sys_tmp);
+ template = g_build_filename (sys_tmp, "mc-XXXXXX", (char *) NULL);
+ g_strlcpy (buffer, template, sizeof (buffer));
+ g_free (template);
+
tmpdir = g_mkdtemp (buffer);
if (tmpdir != NULL)
g_setenv ("MC_TMPDIR", tmpdir, TRUE);
diff --git a/tests/lib/vfs/tempdir.c b/tests/lib/vfs/tempdir.c
index 2a499d1..a09c473 100644
--- a/tests/lib/vfs/tempdir.c
+++ b/tests/lib/vfs/tempdir.c
@@ -45,6 +45,9 @@
static void
setup (void)
{
+ /* Ensure that tests behave consistently irrespectively of the environment */
+ g_unsetenv ("MC_TMPDIR");
+
str_init_strings (NULL);

vfs_init ();

--
Midnight Commander Development
Reply all
Reply to author
Forward
0 new messages