mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
gfileutils: Try creating complete path first
Try to create the complete path right away and fall back to creating all path elements one by one. This also helps to avoid TOCTTOU problems and avoids walking the path all the time, providing a nice performance gain, by avoiding syscalls.
This commit is contained in:
parent
6f55306e04
commit
ca98741251
@ -226,6 +226,20 @@ g_mkdir_with_parents (const gchar *pathname,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* try to create the full path first */
|
||||
if (g_mkdir (pathname, mode) == 0)
|
||||
return 0;
|
||||
else if (errno == EEXIST)
|
||||
{
|
||||
if (!g_file_test (pathname, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* walk the full path and try creating each element */
|
||||
fn = g_strdup (pathname);
|
||||
|
||||
if (g_path_is_absolute (fn))
|
||||
|
Loading…
Reference in New Issue
Block a user