Skip to content

Commit fafce61

Browse files
committed
Fix usage of g_file_test().
According to the GLib documentation, g_file_test() returns TRUE if any of the tests in the bitfield test are TRUE. For example, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) will return TRUE if the file exists; the check whether it's a directory doesn't matter since the existence test is TRUE. With the current set of available tests, there's no point passing in more than one test at a time. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
1 parent bde922e commit fafce61

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

lib/mcconfig/paths.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ mc_config_mkdir (const char *directory_name, GError **mcerror)
107107
{
108108
mc_return_if_error (mcerror);
109109

110-
if ((!g_file_test (directory_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
111-
&& (g_mkdir_with_parents (directory_name, 0700) != 0))
110+
if (!(g_file_test (directory_name, G_FILE_TEST_EXISTS)
111+
&& g_file_test (directory_name, G_FILE_TEST_IS_DIR))
112+
&& g_mkdir_with_parents (directory_name, 0700) != 0)
112113
mc_propagate_error (mcerror, 0, _ ("Cannot create %s directory"), directory_name);
113114
}
114115

tests/lib/vfs/tempdir.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ START_TEST (test_mc_tmpdir)
7474
env_tmpdir = g_getenv ("MC_TMPDIR");
7575

7676
// then
77-
ck_assert_msg (g_file_test (tmpdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR),
77+
ck_assert_msg (g_file_test (tmpdir, G_FILE_TEST_EXISTS)
78+
&& g_file_test (tmpdir, G_FILE_TEST_IS_DIR),
7879
"\nNo such directory: %s\n", tmpdir);
7980
mctest_assert_str_eq (env_tmpdir, tmpdir);
8081
}
@@ -97,13 +98,15 @@ START_TEST (test_mc_mkstemps)
9798
// then
9899
close (fd);
99100
ck_assert_int_ne (fd, -1);
100-
ck_assert_msg (
101-
g_file_test (vfs_path_as_str (pname_vpath), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR),
102-
"\nNo such file: %s\n", vfs_path_as_str (pname_vpath));
103-
unlink (vfs_path_as_str (pname_vpath));
104-
ck_assert_msg (strncmp (vfs_path_as_str (pname_vpath), begin_pname, strlen (begin_pname)) == 0,
105-
"\nstart of %s should be equal to %s\n", vfs_path_as_str (pname_vpath),
106-
begin_pname);
101+
102+
const char *pname = vfs_path_as_str (pname_vpath);
103+
104+
ck_assert_msg (g_file_test (pname, G_FILE_TEST_EXISTS)
105+
&& g_file_test (pname, G_FILE_TEST_IS_REGULAR),
106+
"\nNo such file: %s\n", pname);
107+
unlink (pname);
108+
ck_assert_msg (strncmp (pname, begin_pname, strlen (begin_pname)) == 0,
109+
"\nstart of %s should be equal to %s\n", pname, begin_pname);
107110
vfs_path_free (pname_vpath, TRUE);
108111
}
109112
END_TEST

0 commit comments

Comments
 (0)