Skip to content

Commit

Permalink
Merge branch 'android-transfer-issue-1743' into 'master'
Browse files Browse the repository at this point in the history
file-helpers: make parent dir creation thread safe

Closes #1743

See merge request GNOME/rhythmbox!109
  • Loading branch information
Jonathan Matthew committed Apr 10, 2021
2 parents 6bb7ff5 + e3b7d5a commit 5475530
Showing 1 changed file with 9 additions and 31 deletions.
40 changes: 9 additions & 31 deletions lib/rb-file-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1383,34 +1383,6 @@ rb_uri_get_mount_point (const char *uri)
return mountpoint;
}

static gboolean
check_file_is_directory (GFile *file, GError **error)
{
GFileInfo *info;

info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, error);
if (*error == NULL) {
/* check it's a directory */
GFileType filetype;
gboolean ret = TRUE;

filetype = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE);
if (filetype != G_FILE_TYPE_DIRECTORY) {
/* um.. */
ret = FALSE;
}

g_object_unref (info);
return ret;
}

if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
g_clear_error (error);
}
return FALSE;
}


/**
* rb_uri_create_parent_dirs:
* @uri: a URI for which to create parent directories
Expand All @@ -1427,6 +1399,7 @@ rb_uri_create_parent_dirs (const char *uri, GError **error)
GFile *file;
GFile *parent;
gboolean ret;
GError *err = NULL;

/* ignore internal URI schemes */
if (g_str_has_prefix (uri, "xrb")) {
Expand All @@ -1441,9 +1414,14 @@ rb_uri_create_parent_dirs (const char *uri, GError **error)
return TRUE;
}

ret = check_file_is_directory (parent, error);
if (ret == FALSE && *error == NULL) {
ret = g_file_make_directory_with_parents (parent, NULL, error);
ret = g_file_make_directory_with_parents (parent, NULL, &err);
if (err != NULL) {
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
g_error_free (err);
ret = TRUE;
} else {
g_propagate_error (error, err);
}
}

g_object_unref (parent);
Expand Down

0 comments on commit 5475530

Please sign in to comment.