repo/core: Convert some functions to new code style

I was planning to change one here, decided to do a conversion
of some of the simpler functions in this file to keep up momentum.

Closes: #776
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-04-04 16:46:31 -04:00 committed by Atomic Bot
parent c937305c0e
commit a0e15ecbed
1 changed files with 105 additions and 217 deletions

View File

@ -892,26 +892,21 @@ ostree_repo_write_config (OstreeRepo *self,
GKeyFile *new_config, GKeyFile *new_config,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autofree char *data = NULL;
gsize len;
g_return_val_if_fail (self->inited, FALSE); g_return_val_if_fail (self->inited, FALSE);
data = g_key_file_to_data (new_config, &len, error); gsize len;
g_autofree char *data = g_key_file_to_data (new_config, &len, error);
if (!glnx_file_replace_contents_at (self->repo_dir_fd, "config", if (!glnx_file_replace_contents_at (self->repo_dir_fd, "config",
(guint8*)data, len, 0, (guint8*)data, len, 0,
NULL, error)) NULL, error))
goto out; return FALSE;
g_key_file_free (self->config); g_key_file_free (self->config);
self->config = g_key_file_new (); self->config = g_key_file_new ();
if (!g_key_file_load_from_data (self->config, data, len, 0, error)) if (!g_key_file_load_from_data (self->config, data, len, 0, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }
/* Bind a subset of an a{sv} to options in a given GKeyfile section */ /* Bind a subset of an a{sv} to options in a given GKeyfile section */
@ -954,34 +949,24 @@ impl_repo_remote_add (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
g_autoptr(OstreeRemote) remote = NULL;
gboolean different_sysroot = FALSE;
gboolean ret = FALSE;
g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (url != NULL, FALSE); g_return_val_if_fail (url != NULL, FALSE);
g_return_val_if_fail (options == NULL || g_variant_is_of_type (options, G_VARIANT_TYPE ("a{sv}")), FALSE); g_return_val_if_fail (options == NULL || g_variant_is_of_type (options, G_VARIANT_TYPE ("a{sv}")), FALSE);
if (strchr (name, '/') != NULL) if (strchr (name, '/') != NULL)
{ return glnx_throw (error, "Invalid character '/' in remote name: %s", name);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Invalid character '/' in remote name: %s",
name);
goto out;
}
remote = ost_repo_get_remote (self, name, NULL); g_autoptr(OstreeRemote) remote = ost_repo_get_remote (self, name, NULL);
if (remote != NULL && if_not_exists) if (remote != NULL && if_not_exists)
{ {
ret = TRUE; /* Note early return */
goto out; return TRUE;
} }
else if (remote != NULL) else if (remote != NULL)
{ {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, return glnx_throw (error,
"Remote configuration for \"%s\" already exists: %s", "Remote configuration for \"%s\" already exists: %s",
name, remote->file ? gs_file_get_path_cached (remote->file) : "(in config)"); name, remote->file ? gs_file_get_path_cached (remote->file) : "(in config)");
goto out;
} }
remote = ost_remote_new (); remote = ost_remote_new ();
@ -995,20 +980,18 @@ impl_repo_remote_add (OstreeRepo *self,
* *
* XXX Having API regret about the "sysroot" argument now. * XXX Having API regret about the "sysroot" argument now.
*/ */
gboolean different_sysroot = FALSE;
if (sysroot != NULL) if (sysroot != NULL)
different_sysroot = !g_file_equal (sysroot, self->sysroot_dir); different_sysroot = !g_file_equal (sysroot, self->sysroot_dir);
if (different_sysroot || ostree_repo_is_system (self)) if (different_sysroot || ostree_repo_is_system (self))
{ {
g_autofree char *basename = g_strconcat (name, ".conf", NULL); g_autoptr(GError) local_error = NULL;
g_autoptr(GFile) etc_ostree_remotes_d = NULL;
GError *local_error = NULL;
if (sysroot == NULL) if (sysroot == NULL)
sysroot = self->sysroot_dir; sysroot = self->sysroot_dir;
etc_ostree_remotes_d = g_file_resolve_relative_path (sysroot, SYSCONF_REMOTES); g_autoptr(GFile) etc_ostree_remotes_d = g_file_resolve_relative_path (sysroot, SYSCONF_REMOTES);
if (!g_file_make_directory_with_parents (etc_ostree_remotes_d, if (!g_file_make_directory_with_parents (etc_ostree_remotes_d,
cancellable, &local_error)) cancellable, &local_error))
{ {
@ -1018,11 +1001,12 @@ impl_repo_remote_add (OstreeRepo *self,
} }
else else
{ {
g_propagate_error (error, local_error); g_propagate_error (error, g_steal_pointer (&local_error));
goto out; return FALSE;
} }
} }
g_autofree char *basename = g_strconcat (name, ".conf", NULL);
remote->file = g_file_get_child (etc_ostree_remotes_d, basename); remote->file = g_file_get_child (etc_ostree_remotes_d, basename);
} }
@ -1036,16 +1020,14 @@ impl_repo_remote_add (OstreeRepo *self,
if (remote->file != NULL) if (remote->file != NULL)
{ {
g_autofree char *data = NULL;
gsize length; gsize length;
g_autofree char *data = g_key_file_to_data (remote->options, &length, NULL);
data = g_key_file_to_data (remote->options, &length, NULL);
if (!g_file_replace_contents (remote->file, if (!g_file_replace_contents (remote->file,
data, length, data, length,
NULL, FALSE, 0, NULL, NULL, FALSE, 0, NULL,
cancellable, error)) cancellable, error))
goto out; return FALSE;
} }
else else
{ {
@ -1055,15 +1037,12 @@ impl_repo_remote_add (OstreeRepo *self,
ot_keyfile_copy_group (remote->options, config, remote->group); ot_keyfile_copy_group (remote->options, config, remote->group);
if (!ostree_repo_write_config (self, config, error)) if (!ostree_repo_write_config (self, config, error))
goto out; return FALSE;
} }
ost_repo_add_remote (self, remote); ost_repo_add_remote (self, remote);
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
@ -1104,67 +1083,52 @@ impl_repo_remote_delete (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
g_autoptr(OstreeRemote) remote = NULL;
gboolean ret = FALSE;
g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (name != NULL, FALSE);
if (strchr (name, '/') != NULL) if (strchr (name, '/') != NULL)
{ return glnx_throw (error, "Invalid character '/' in remote name: %s", name);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Invalid character '/' in remote name: %s",
name);
goto out;
}
g_autoptr(OstreeRemote) remote = NULL;
if (if_exists) if (if_exists)
{ {
remote = ost_repo_get_remote (self, name, NULL); remote = ost_repo_get_remote (self, name, NULL);
if (!remote) if (!remote)
{ {
ret = TRUE; /* Note early return */
goto out; return TRUE;
} }
} }
else else
remote = ost_repo_get_remote (self, name, error); remote = ost_repo_get_remote (self, name, error);
if (remote == NULL) if (remote == NULL)
goto out; return FALSE;
if (remote->file != NULL) if (remote->file != NULL)
{ {
if (unlink (gs_file_get_path_cached (remote->file)) != 0) if (unlink (gs_file_get_path_cached (remote->file)) != 0)
{ return glnx_throw_errno (error);
glnx_set_error_from_errno (error);
goto out;
}
} }
else else
{ {
g_autoptr(GKeyFile) config = NULL; g_autoptr(GKeyFile) config = ostree_repo_copy_config (self);
config = ostree_repo_copy_config (self);
/* XXX Not sure it's worth failing if the group to remove /* XXX Not sure it's worth failing if the group to remove
* isn't found. It's the end result we want, after all. */ * isn't found. It's the end result we want, after all. */
if (g_key_file_remove_group (config, remote->group, NULL)) if (g_key_file_remove_group (config, remote->group, NULL))
{ {
if (!ostree_repo_write_config (self, config, error)) if (!ostree_repo_write_config (self, config, error))
goto out; return FALSE;
} }
} }
/* Delete the remote's keyring file, if it exists. */ /* Delete the remote's keyring file, if it exists. */
if (!ot_ensure_unlinked_at (self->repo_dir_fd, remote->keyring, error)) if (!ot_ensure_unlinked_at (self->repo_dir_fd, remote->keyring, error))
goto out; return FALSE;
ost_repo_remove_remote (self, remote); ost_repo_remove_remote (self, remote);
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
@ -1320,11 +1284,9 @@ ostree_repo_remote_get_url (OstreeRepo *self,
char **out_url, char **out_url,
GError **error) GError **error)
{ {
g_autofree char *url = NULL;
gboolean ret = FALSE;
g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (name != NULL, FALSE);
g_autofree char *url = NULL;
if (_ostree_repo_remote_name_is_file (name)) if (_ostree_repo_remote_name_is_file (name))
{ {
url = g_strdup (name); url = g_strdup (name);
@ -1332,23 +1294,19 @@ ostree_repo_remote_get_url (OstreeRepo *self,
else else
{ {
if (!ostree_repo_get_remote_option (self, name, "url", NULL, &url, error)) if (!ostree_repo_get_remote_option (self, name, "url", NULL, &url, error))
goto out; return FALSE;
if (url == NULL) if (url == NULL)
{ {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
"No \"url\" option in remote \"%s\"", name); "No \"url\" option in remote \"%s\"", name);
goto out; return FALSE;
} }
} }
if (out_url != NULL) if (out_url != NULL)
*out_url = g_steal_pointer (&url); *out_url = g_steal_pointer (&url);
return TRUE;
ret = TRUE;
out:
return ret;
} }
/** /**
@ -1743,7 +1701,6 @@ ostree_repo_mode_to_string (OstreeRepoMode mode,
const char **out_mode, const char **out_mode,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
const char *ret_mode; const char *ret_mode;
switch (mode) switch (mode)
@ -1761,15 +1718,11 @@ ostree_repo_mode_to_string (OstreeRepoMode mode,
ret_mode ="archive-z2"; ret_mode ="archive-z2";
break; break;
default: default:
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, return glnx_throw (error, "Invalid mode '%d'", mode);
"Invalid mode '%d'", mode);
goto out;
} }
ret = TRUE;
*out_mode = ret_mode; *out_mode = ret_mode;
out: return TRUE;
return ret;
} }
gboolean gboolean
@ -1777,7 +1730,6 @@ ostree_repo_mode_from_string (const char *mode,
OstreeRepoMode *out_mode, OstreeRepoMode *out_mode,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
OstreeRepoMode ret_mode; OstreeRepoMode ret_mode;
if (strcmp (mode, "bare") == 0) if (strcmp (mode, "bare") == 0)
@ -1790,16 +1742,10 @@ ostree_repo_mode_from_string (const char *mode,
strcmp (mode, "archive") == 0) strcmp (mode, "archive") == 0)
ret_mode = OSTREE_REPO_MODE_ARCHIVE_Z2; ret_mode = OSTREE_REPO_MODE_ARCHIVE_Z2;
else else
{ return glnx_throw (error, "Invalid mode '%s' in repository configuration", mode);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Invalid mode '%s' in repository configuration", mode);
goto out;
}
ret = TRUE;
*out_mode = ret_mode; *out_mode = ret_mode;
out: return TRUE;
return ret;
} }
#define DEFAULT_CONFIG_CONTENTS ("[core]\n" \ #define DEFAULT_CONFIG_CONTENTS ("[core]\n" \
@ -1847,11 +1793,12 @@ ostree_repo_create (OstreeRepo *self,
{ {
if (errno == ENOENT) if (errno == ENOENT)
{ {
const char *mode_str; const char *mode_str = NULL;
g_autoptr(GString) config_data = g_string_new (DEFAULT_CONFIG_CONTENTS); g_autoptr(GString) config_data = g_string_new (DEFAULT_CONFIG_CONTENTS);
if (!ostree_repo_mode_to_string (mode, &mode_str, error)) if (!ostree_repo_mode_to_string (mode, &mode_str, error))
return FALSE; return FALSE;
g_assert (mode_str);
g_string_append_printf (config_data, "mode=%s\n", mode_str); g_string_append_printf (config_data, "mode=%s\n", mode_str);
@ -1888,8 +1835,7 @@ enumerate_directory_allow_noent (GFile *dirpath,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; g_autoptr(GError) temp_error = NULL;
GError *temp_error = NULL;
g_autoptr(GFileEnumerator) ret_direnum = NULL; g_autoptr(GFileEnumerator) ret_direnum = NULL;
ret_direnum = g_file_enumerate_children (dirpath, queryargs, queryflags, ret_direnum = g_file_enumerate_children (dirpath, queryargs, queryflags,
@ -1897,21 +1843,17 @@ enumerate_directory_allow_noent (GFile *dirpath,
if (!ret_direnum) if (!ret_direnum)
{ {
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{ g_clear_error (&temp_error);
g_clear_error (&temp_error);
ret = TRUE;
}
else else
g_propagate_error (error, temp_error); {
g_propagate_error (error, g_steal_pointer (&temp_error));
goto out; return FALSE;
}
} }
ret = TRUE;
if (out_direnum) if (out_direnum)
*out_direnum = g_steal_pointer (&ret_direnum); *out_direnum = g_steal_pointer (&ret_direnum);
out: return TRUE;
return ret;
} }
static gboolean static gboolean
@ -1977,17 +1919,12 @@ append_one_remote_config (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autoptr(GKeyFile) remotedata = g_key_file_new (); g_autoptr(GKeyFile) remotedata = g_key_file_new ();
if (!g_key_file_load_from_file (remotedata, gs_file_get_path_cached (path), if (!g_key_file_load_from_file (remotedata, gs_file_get_path_cached (path),
0, error)) 0, error))
goto out; return FALSE;
ret = add_remotes_from_keyfile (self, remotedata, path, error); return add_remotes_from_keyfile (self, remotedata, path, error);
out:
return ret;
} }
static GFile * static GFile *
@ -2031,11 +1968,7 @@ reload_core_config (OstreeRepo *self,
return FALSE; return FALSE;
if (strcmp (version, "1") != 0) if (strcmp (version, "1") != 0)
{ return glnx_throw (error, "Invalid repository version '%s'", version);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Invalid repository version '%s'", version);
return FALSE;
}
if (!ot_keyfile_get_boolean_with_default (self->config, "core", "archive", if (!ot_keyfile_get_boolean_with_default (self->config, "core", "archive",
FALSE, &is_archive, error)) FALSE, &is_archive, error))
@ -2128,25 +2061,23 @@ reload_remote_config (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autoptr(GFile) remotes_d = NULL;
g_autoptr(GFileEnumerator) direnum = NULL;
g_mutex_lock (&self->remotes_lock); g_mutex_lock (&self->remotes_lock);
g_hash_table_remove_all (self->remotes); g_hash_table_remove_all (self->remotes);
g_mutex_unlock (&self->remotes_lock); g_mutex_unlock (&self->remotes_lock);
if (!add_remotes_from_keyfile (self, self->config, NULL, error)) if (!add_remotes_from_keyfile (self, self->config, NULL, error))
goto out; return FALSE;
remotes_d = get_remotes_d_dir (self); g_autoptr(GFile) remotes_d = get_remotes_d_dir (self);
if (remotes_d == NULL) if (remotes_d == NULL)
return TRUE; return TRUE;
g_autoptr(GFileEnumerator) direnum = NULL;
if (!enumerate_directory_allow_noent (remotes_d, OSTREE_GIO_FAST_QUERYINFO, 0, if (!enumerate_directory_allow_noent (remotes_d, OSTREE_GIO_FAST_QUERYINFO, 0,
&direnum, &direnum,
cancellable, error)) cancellable, error))
goto out; return FALSE;
if (direnum) if (direnum)
{ {
while (TRUE) while (TRUE)
@ -2158,7 +2089,7 @@ reload_remote_config (OstreeRepo *self,
if (!g_file_enumerator_iterate (direnum, &file_info, &path, if (!g_file_enumerator_iterate (direnum, &file_info, &path,
NULL, error)) NULL, error))
goto out; return FALSE;
if (file_info == NULL) if (file_info == NULL)
break; break;
@ -2169,14 +2100,12 @@ reload_remote_config (OstreeRepo *self,
g_str_has_suffix (name, ".conf")) g_str_has_suffix (name, ".conf"))
{ {
if (!append_one_remote_config (self, path, cancellable, error)) if (!append_one_remote_config (self, path, cancellable, error))
goto out; return FALSE;
} }
} }
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
@ -2205,7 +2134,6 @@ ostree_repo_open (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
struct stat stbuf; struct stat stbuf;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@ -2228,7 +2156,7 @@ ostree_repo_open (OstreeRepo *self,
&boot_id, &boot_id,
NULL, NULL,
error)) error))
goto out; return FALSE;
g_strdelimit (boot_id, "\n", '\0'); g_strdelimit (boot_id, "\n", '\0');
} }
@ -2239,14 +2167,14 @@ ostree_repo_open (OstreeRepo *self,
&self->repo_dir_fd, error)) &self->repo_dir_fd, error))
{ {
g_prefix_error (error, "%s: ", gs_file_get_path_cached (self->repodir)); g_prefix_error (error, "%s: ", gs_file_get_path_cached (self->repodir));
goto out; return FALSE;
} }
if (!glnx_opendirat (self->repo_dir_fd, "objects", TRUE, if (!glnx_opendirat (self->repo_dir_fd, "objects", TRUE,
&self->objects_dir_fd, error)) &self->objects_dir_fd, error))
{ {
g_prefix_error (error, "Opening objects/ directory: "); g_prefix_error (error, "Opening objects/ directory: ");
goto out; return FALSE;
} }
self->writable = faccessat (self->objects_dir_fd, ".", W_OK, 0) == 0; self->writable = faccessat (self->objects_dir_fd, ".", W_OK, 0) == 0;
@ -2254,13 +2182,11 @@ ostree_repo_open (OstreeRepo *self,
{ {
/* This is returned through ostree_repo_is_writable(). */ /* This is returned through ostree_repo_is_writable(). */
glnx_set_error_from_errno (&self->writable_error); glnx_set_error_from_errno (&self->writable_error);
/* Note - we don't return this error yet! */
} }
if (fstat (self->objects_dir_fd, &stbuf) != 0) if (fstat (self->objects_dir_fd, &stbuf) != 0)
{ return glnx_throw_errno (error);
glnx_set_error_from_errno (error);
goto out;
}
if (stbuf.st_uid != getuid () || stbuf.st_gid != getgid ()) if (stbuf.st_uid != getuid () || stbuf.st_gid != getgid ())
{ {
@ -2273,37 +2199,34 @@ ostree_repo_open (OstreeRepo *self,
} }
if (!glnx_opendirat (self->repo_dir_fd, "tmp", TRUE, &self->tmp_dir_fd, error)) if (!glnx_opendirat (self->repo_dir_fd, "tmp", TRUE, &self->tmp_dir_fd, error))
goto out; return FALSE;
if (self->writable) if (self->writable)
{ {
if (!glnx_shutil_mkdir_p_at (self->tmp_dir_fd, _OSTREE_CACHE_DIR, 0775, cancellable, error)) if (!glnx_shutil_mkdir_p_at (self->tmp_dir_fd, _OSTREE_CACHE_DIR, 0775, cancellable, error))
goto out; return FALSE;
if (!glnx_opendirat (self->tmp_dir_fd, _OSTREE_CACHE_DIR, TRUE, &self->cache_dir_fd, error)) if (!glnx_opendirat (self->tmp_dir_fd, _OSTREE_CACHE_DIR, TRUE, &self->cache_dir_fd, error))
goto out; return FALSE;
} }
if (!ostree_repo_reload_config (self, cancellable, error)) if (!ostree_repo_reload_config (self, cancellable, error))
goto out; return FALSE;
/* TODO - delete this */ /* TODO - delete this */
if (self->mode == OSTREE_REPO_MODE_ARCHIVE_Z2 && self->enable_uncompressed_cache) if (self->mode == OSTREE_REPO_MODE_ARCHIVE_Z2 && self->enable_uncompressed_cache)
{ {
if (!glnx_shutil_mkdir_p_at (self->repo_dir_fd, "uncompressed-objects-cache", 0755, if (!glnx_shutil_mkdir_p_at (self->repo_dir_fd, "uncompressed-objects-cache", 0755,
cancellable, error)) cancellable, error))
goto out; return FALSE;
if (!glnx_opendirat (self->repo_dir_fd, "uncompressed-objects-cache", TRUE, if (!glnx_opendirat (self->repo_dir_fd, "uncompressed-objects-cache", TRUE,
&self->uncompressed_objects_dir_fd, &self->uncompressed_objects_dir_fd,
error)) error))
goto out; return FALSE;
} }
self->inited = TRUE; self->inited = TRUE;
return TRUE;
ret = TRUE;
out:
return ret;
} }
/** /**
@ -2371,8 +2294,8 @@ ostree_repo_get_disable_fsync (OstreeRepo *self)
/* Replace the contents of a file, honoring the repository's fsync /* Replace the contents of a file, honoring the repository's fsync
* policy. * policy.
*/ */
gboolean gboolean
_ostree_repo_file_replace_contents (OstreeRepo *self, _ostree_repo_file_replace_contents (OstreeRepo *self,
int dfd, int dfd,
const char *path, const char *path,
@ -2532,7 +2455,6 @@ list_loose_objects (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
guint c; guint c;
int dfd = -1; int dfd = -1;
static const gchar hexchars[] = "0123456789abcdef"; static const gchar hexchars[] = "0123456789abcdef";
@ -2549,21 +2471,16 @@ list_loose_objects (OstreeRepo *self,
if (errno == ENOENT) if (errno == ENOENT)
continue; continue;
else else
{ return glnx_throw_errno (error);
glnx_set_error_from_errno (error);
goto out;
}
} }
/* Takes ownership of dfd */ /* Takes ownership of dfd */
if (!list_loose_objects_at (self, inout_objects, buf, dfd, if (!list_loose_objects_at (self, inout_objects, buf, dfd,
commit_starting_with, commit_starting_with,
cancellable, error)) cancellable, error))
goto out; return FALSE;
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
static gboolean static gboolean
@ -2577,7 +2494,6 @@ load_metadata_internal (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; char loose_path_buf[_OSTREE_LOOSE_PATH_MAX];
struct stat stbuf; struct stat stbuf;
glnx_fd_close int fd = -1; glnx_fd_close int fd = -1;
@ -2590,22 +2506,19 @@ load_metadata_internal (OstreeRepo *self,
if (!ot_openat_ignore_enoent (self->objects_dir_fd, loose_path_buf, &fd, if (!ot_openat_ignore_enoent (self->objects_dir_fd, loose_path_buf, &fd,
error)) error))
goto out; return FALSE;
if (fd < 0 && self->commit_stagedir_fd != -1) if (fd < 0 && self->commit_stagedir_fd != -1)
{ {
if (!ot_openat_ignore_enoent (self->commit_stagedir_fd, loose_path_buf, &fd, if (!ot_openat_ignore_enoent (self->commit_stagedir_fd, loose_path_buf, &fd,
error)) error))
goto out; return FALSE;
} }
if (fd != -1) if (fd != -1)
{ {
if (fstat (fd, &stbuf) < 0) if (fstat (fd, &stbuf) < 0)
{ return glnx_throw_errno (error);
glnx_set_error_from_errno (error);
goto out;
}
if (out_variant) if (out_variant)
{ {
@ -2616,7 +2529,7 @@ load_metadata_internal (OstreeRepo *self,
mfile = g_mapped_file_new_from_fd (fd, FALSE, error); mfile = g_mapped_file_new_from_fd (fd, FALSE, error);
if (!mfile) if (!mfile)
goto out; return FALSE;
ret_variant = g_variant_new_from_data (ostree_metadata_variant_type (objtype), ret_variant = g_variant_new_from_data (ostree_metadata_variant_type (objtype),
g_mapped_file_get_contents (mfile), g_mapped_file_get_contents (mfile),
g_mapped_file_get_length (mfile), g_mapped_file_get_length (mfile),
@ -2629,7 +2542,7 @@ load_metadata_internal (OstreeRepo *self,
{ {
g_autoptr(GBytes) data = glnx_fd_readall_bytes (fd, cancellable, error); g_autoptr(GBytes) data = glnx_fd_readall_bytes (fd, cancellable, error);
if (!data) if (!data)
goto out; return FALSE;
ret_variant = g_variant_new_from_bytes (ostree_metadata_variant_type (objtype), ret_variant = g_variant_new_from_bytes (ostree_metadata_variant_type (objtype),
data, TRUE); data, TRUE);
g_variant_ref_sink (ret_variant); g_variant_ref_sink (ret_variant);
@ -2639,7 +2552,7 @@ load_metadata_internal (OstreeRepo *self,
{ {
ret_stream = g_unix_input_stream_new (fd, TRUE); ret_stream = g_unix_input_stream_new (fd, TRUE);
if (!ret_stream) if (!ret_stream)
goto out; return FALSE;
fd = -1; /* Transfer ownership */ fd = -1; /* Transfer ownership */
} }
@ -2649,21 +2562,19 @@ load_metadata_internal (OstreeRepo *self,
else if (self->parent_repo) else if (self->parent_repo)
{ {
if (!ostree_repo_load_variant (self->parent_repo, objtype, sha256, &ret_variant, error)) if (!ostree_repo_load_variant (self->parent_repo, objtype, sha256, &ret_variant, error))
goto out; return FALSE;
} }
else if (error_if_not_found) else if (error_if_not_found)
{ {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
"No such metadata object %s.%s", "No such metadata object %s.%s",
sha256, ostree_object_type_to_string (objtype)); sha256, ostree_object_type_to_string (objtype));
goto out; return FALSE;
} }
ret = TRUE;
ot_transfer_out_value (out_variant, &ret_variant); ot_transfer_out_value (out_variant, &ret_variant);
ot_transfer_out_value (out_stream, &ret_stream); ot_transfer_out_value (out_stream, &ret_stream);
out: return TRUE;
return ret;
} }
static gboolean static gboolean
@ -3513,26 +3424,20 @@ ostree_repo_query_object_storage_size (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
char loose_path[_OSTREE_LOOSE_PATH_MAX]; char loose_path[_OSTREE_LOOSE_PATH_MAX];
int res; int res;
struct stat stbuf; struct stat stbuf;
_ostree_loose_path (loose_path, sha256, objtype, self->mode); _ostree_loose_path (loose_path, sha256, objtype, self->mode);
do do
res = fstatat (self->objects_dir_fd, loose_path, &stbuf, AT_SYMLINK_NOFOLLOW); res = fstatat (self->objects_dir_fd, loose_path, &stbuf, AT_SYMLINK_NOFOLLOW);
while (G_UNLIKELY (res == -1 && errno == EINTR)); while (G_UNLIKELY (res == -1 && errno == EINTR));
if (G_UNLIKELY (res == -1)) if (G_UNLIKELY (res == -1))
{ return glnx_throw_errno_prefix (error, "Querying object %s.%s", sha256, ostree_object_type_to_string (objtype));
glnx_set_prefix_error_from_errno (error, "Querying object %s.%s", sha256, ostree_object_type_to_string (objtype));
goto out;
}
*out_size = stbuf.st_size; *out_size = stbuf.st_size;
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
@ -3600,13 +3505,11 @@ ostree_repo_load_commit (OstreeRepo *self,
OstreeRepoCommitState *out_state, OstreeRepoCommitState *out_state,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
if (out_variant) if (out_variant)
{ {
if (!load_metadata_internal (self, OSTREE_OBJECT_TYPE_COMMIT, checksum, TRUE, if (!load_metadata_internal (self, OSTREE_OBJECT_TYPE_COMMIT, checksum, TRUE,
out_variant, NULL, NULL, NULL, error)) out_variant, NULL, NULL, NULL, error))
goto out; return FALSE;
} }
if (out_state) if (out_state)
@ -3622,14 +3525,11 @@ ostree_repo_load_commit (OstreeRepo *self,
} }
else if (errno != ENOENT) else if (errno != ENOENT)
{ {
glnx_set_error_from_errno (error); return glnx_throw_errno (error);
goto out;
} }
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
@ -3655,15 +3555,13 @@ ostree_repo_list_objects (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autoptr(GHashTable) ret_objects = NULL;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_return_val_if_fail (self->inited, FALSE); g_return_val_if_fail (self->inited, FALSE);
ret_objects = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, g_autoptr(GHashTable) ret_objects =
(GDestroyNotify) g_variant_unref, g_hash_table_new_full (ostree_hash_object_name, g_variant_equal,
(GDestroyNotify) g_variant_unref); (GDestroyNotify) g_variant_unref,
(GDestroyNotify) g_variant_unref);
if (flags & OSTREE_REPO_LIST_OBJECTS_ALL) if (flags & OSTREE_REPO_LIST_OBJECTS_ALL)
flags |= (OSTREE_REPO_LIST_OBJECTS_LOOSE | OSTREE_REPO_LIST_OBJECTS_PACKED); flags |= (OSTREE_REPO_LIST_OBJECTS_LOOSE | OSTREE_REPO_LIST_OBJECTS_PACKED);
@ -3671,11 +3569,11 @@ ostree_repo_list_objects (OstreeRepo *self,
if (flags & OSTREE_REPO_LIST_OBJECTS_LOOSE) if (flags & OSTREE_REPO_LIST_OBJECTS_LOOSE)
{ {
if (!list_loose_objects (self, ret_objects, NULL, cancellable, error)) if (!list_loose_objects (self, ret_objects, NULL, cancellable, error))
goto out; return FALSE;
if ((flags & OSTREE_REPO_LIST_OBJECTS_NO_PARENTS) == 0 && self->parent_repo) if ((flags & OSTREE_REPO_LIST_OBJECTS_NO_PARENTS) == 0 && self->parent_repo)
{ {
if (!list_loose_objects (self->parent_repo, ret_objects, NULL, cancellable, error)) if (!list_loose_objects (self->parent_repo, ret_objects, NULL, cancellable, error))
goto out; return FALSE;
} }
} }
@ -3684,10 +3582,8 @@ ostree_repo_list_objects (OstreeRepo *self,
/* Nothing for now... */ /* Nothing for now... */
} }
ret = TRUE;
ot_transfer_out_value (out_objects, &ret_objects); ot_transfer_out_value (out_objects, &ret_objects);
out: return TRUE;
return ret;
} }
/** /**
@ -3757,25 +3653,20 @@ ostree_repo_read_commit (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autoptr(GFile) ret_root = NULL;
g_autofree char *resolved_commit = NULL; g_autofree char *resolved_commit = NULL;
if (!ostree_repo_resolve_rev (self, ref, FALSE, &resolved_commit, error)) if (!ostree_repo_resolve_rev (self, ref, FALSE, &resolved_commit, error))
goto out; return FALSE;
ret_root = (GFile*) _ostree_repo_file_new_for_commit (self, resolved_commit, error); g_autoptr(GFile) ret_root = (GFile*) _ostree_repo_file_new_for_commit (self, resolved_commit, error);
if (!ret_root) if (!ret_root)
goto out; return FALSE;
if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile*)ret_root, error)) if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile*)ret_root, error))
goto out; return FALSE;
ret = TRUE;
ot_transfer_out_value(out_root, &ret_root); ot_transfer_out_value(out_root, &ret_root);
ot_transfer_out_value(out_commit, &resolved_commit); ot_transfer_out_value(out_commit, &resolved_commit);
out: return TRUE;
return ret;
} }
/** /**
@ -4903,7 +4794,6 @@ _ostree_repo_try_lock_tmpdir (int tmpdir_dfd,
gboolean *out_did_lock, gboolean *out_did_lock,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autofree char *lock_name = g_strconcat (tmpdir_name, "-lock", NULL); g_autofree char *lock_name = g_strconcat (tmpdir_name, "-lock", NULL);
gboolean did_lock = FALSE; gboolean did_lock = FALSE;
g_autoptr(GError) local_error = NULL; g_autoptr(GError) local_error = NULL;
@ -4920,7 +4810,7 @@ _ostree_repo_try_lock_tmpdir (int tmpdir_dfd,
else else
{ {
g_propagate_error (error, g_steal_pointer (&local_error)); g_propagate_error (error, g_steal_pointer (&local_error));
goto out; return FALSE;
} }
} }
else else
@ -4928,10 +4818,8 @@ _ostree_repo_try_lock_tmpdir (int tmpdir_dfd,
did_lock = TRUE; did_lock = TRUE;
} }
ret = TRUE;
*out_did_lock = did_lock; *out_did_lock = did_lock;
out: return TRUE;
return ret;
} }
/* This allocates and locks a subdir of the repo tmp dir, using an existing /* This allocates and locks a subdir of the repo tmp dir, using an existing