core: Make mkdir -p function safer
Recursing here is just a more obvious way to do it, rather than relying on the semantics of g_file_make_directory_with_parents().
This commit is contained in:
parent
238da603b8
commit
4436ed34d8
|
|
@ -57,9 +57,11 @@ ot_gfile_ensure_directory (GFile *dir,
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
GError *temp_error = NULL;
|
GError *temp_error = NULL;
|
||||||
|
|
||||||
again:
|
|
||||||
if (with_parents)
|
if (with_parents)
|
||||||
ret = g_file_make_directory_with_parents (dir, NULL, &temp_error);
|
{
|
||||||
|
ot_lobj GFile *parent = g_file_get_parent (dir);
|
||||||
|
ret = ot_gfile_ensure_directory (parent, TRUE, &temp_error);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ret = g_file_make_directory (dir, NULL, &temp_error);
|
ret = g_file_make_directory (dir, NULL, &temp_error);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
|
|
@ -72,11 +74,6 @@ ot_gfile_ensure_directory (GFile *dir,
|
||||||
else
|
else
|
||||||
g_clear_error (&temp_error);
|
g_clear_error (&temp_error);
|
||||||
}
|
}
|
||||||
/* Work around glib bug where if multiple threads/processes race in
|
|
||||||
* _with_parents, it can error out early
|
|
||||||
*/
|
|
||||||
if (with_parents && !g_file_query_exists (dir, NULL))
|
|
||||||
goto again;
|
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue