Create runtime directories if they do not exist

This commit is contained in:
Richard Hughes 2015-03-18 20:55:05 +00:00
parent 0e883ee815
commit d3c0a70b37
2 changed files with 23 additions and 3 deletions

View File

@ -55,13 +55,23 @@ fu_pending_load (FuPending *pending, GError **error)
char *error_msg = NULL;
const char *statement;
gint rc;
_cleanup_free_ gchar *dirname = NULL;
_cleanup_free_ gchar *filename = NULL;
_cleanup_object_unref_ GFile *file = NULL;
g_return_val_if_fail (FU_IS_PENDING (pending), FALSE);
g_return_val_if_fail (pending->priv->db == NULL, FALSE);
filename = g_build_filename (LOCALSTATEDIR, "lib", "fwupd",
"pending.db", NULL);
/* create directory */
dirname = g_build_filename (LOCALSTATEDIR, "lib", "fwupd", NULL);
file = g_file_new_for_path (dirname);
if (!g_file_query_exists (file, NULL)) {
if (!g_file_make_directory_with_parents (file, NULL, error))
return FALSE;
}
/* open */
filename = g_build_filename (dirname, "pending.db", NULL);
g_debug ("FuPending: trying to open database '%s'", filename);
rc = sqlite3_open (filename, &pending->priv->db);
if (rc != SQLITE_OK) {

View File

@ -73,9 +73,11 @@ fu_provider_schedule_update (FuProvider *provider,
gchar tmpname[] = {"XXXXXX.cap"};
guint i;
_cleanup_bytes_unref_ GBytes *fwbin = NULL;
_cleanup_free_ gchar *dirname = NULL;
_cleanup_free_ gchar *filename = NULL;
_cleanup_object_unref_ FuDevice *device_tmp = NULL;
_cleanup_object_unref_ FuPending *pending = NULL;
_cleanup_object_unref_ GFile *file = NULL;
/* id already exists */
pending = fu_pending_new ();
@ -89,10 +91,18 @@ fu_provider_schedule_update (FuProvider *provider,
return FALSE;
}
/* create directory */
dirname = g_build_filename (LOCALSTATEDIR, "lib", "fwupd", NULL);
file = g_file_new_for_path (dirname);
if (!g_file_query_exists (file, NULL)) {
if (!g_file_make_directory_with_parents (file, NULL, error))
return FALSE;
}
/* get a random filename */
for (i = 0; i < 6; i++)
tmpname[i] = g_random_int_range ('A', 'Z');
filename = g_build_filename (LOCALSTATEDIR, "lib", "fwupd", tmpname, NULL);
filename = g_build_filename (dirname, tmpname, NULL);
/* just copy to the temp file */
fu_provider_set_status (provider, FU_STATUS_SCHEDULING);