[ostree] core: Switch is_archive to an enumeration
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] core: Switch is_archive to an enumeration
- Date: Thu, 8 Dec 2011 22:32:58 +0000 (UTC)
commit 30c53a967c96d50d4fcf3be8ddb2a7d3552f91bb
Author: Colin Walters <walters verbum org>
Date: Thu Dec 8 17:05:16 2011 -0500
core: Switch is_archive to an enumeration
This is in preparation for adding a third mode.
src/libostree/ostree-repo-file.c | 6 +-
src/libostree/ostree-repo.c | 118 ++++++++++++++++++++++++++++------
src/libostree/ostree-repo.h | 7 ++-
src/ostree/ot-builtin-fsck.c | 2 +-
src/ostree/ot-builtin-init.c | 3 +-
src/ostree/ot-builtin-local-clone.c | 2 +-
6 files changed, 110 insertions(+), 28 deletions(-)
---
diff --git a/src/libostree/ostree-repo-file.c b/src/libostree/ostree-repo-file.c
index b08601b..137469b 100644
--- a/src/libostree/ostree-repo-file.c
+++ b/src/libostree/ostree-repo-file.c
@@ -314,7 +314,7 @@ _ostree_repo_file_get_xattrs (OstreeRepoFile *self,
if (self->tree_metadata)
ret_xattrs = g_variant_get_child_value (self->tree_metadata, 4);
- else if (ostree_repo_is_archive (self->repo))
+ else if (ostree_repo_get_mode (self->repo) == OSTREE_REPO_MODE_ARCHIVE)
{
local_file = _ostree_repo_file_nontree_get_local (self);
if (!ostree_parse_packed_file (local_file, NULL, &ret_xattrs, NULL, cancellable, error))
@@ -1035,7 +1035,7 @@ _ostree_repo_file_tree_query_child (OstreeRepoFile *self,
local_child = get_child_local_file (self->repo, checksum);
- if (ostree_repo_is_archive (self->repo))
+ if (ostree_repo_get_mode (self->repo) == OSTREE_REPO_MODE_ARCHIVE)
{
if (!ostree_parse_packed_file (local_child, &ret_info, NULL, NULL, cancellable, error))
goto out;
@@ -1167,7 +1167,7 @@ ostree_repo_file_read (GFile *file,
goto out;
}
- if (ostree_repo_is_archive (self->repo))
+ if (ostree_repo_get_mode (self->repo) == OSTREE_REPO_MODE_ARCHIVE)
{
g_set_error_literal (error, G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED,
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index dc5ea30..745d7a4 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -62,7 +62,7 @@ struct _OstreeRepoPrivate {
gboolean inited;
GKeyFile *config;
- gboolean archive;
+ OstreeRepoMode mode;
};
static void
@@ -479,13 +479,81 @@ ostree_repo_write_config (OstreeRepo *self,
return ret;
}
+static gboolean
+keyfile_get_boolean_with_default (GKeyFile *keyfile,
+ const char *section,
+ const char *value,
+ gboolean default_value,
+ gboolean *out_bool,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ GError *temp_error = NULL;
+ gboolean ret_bool;
+
+ ret_bool = g_key_file_get_boolean (keyfile, section, value, &temp_error);
+ if (temp_error)
+ {
+ if (g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
+ {
+ g_clear_error (&temp_error);
+ ret_bool = default_value;
+ }
+ else
+ {
+ g_propagate_error (error, temp_error);
+ goto out;
+ }
+ }
+
+ ret = TRUE;
+ *out_bool = ret_bool;
+ out:
+ return ret;
+}
+
+static gboolean
+keyfile_get_value_with_default (GKeyFile *keyfile,
+ const char *section,
+ const char *value,
+ const char *default_value,
+ char **out_value,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ GError *temp_error = NULL;
+ char *ret_value;
+
+ ret_value = g_key_file_get_value (keyfile, section, value, &temp_error);
+ if (temp_error)
+ {
+ if (g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
+ {
+ g_clear_error (&temp_error);
+ ret_value = g_strdup (default_value);
+ }
+ else
+ {
+ g_propagate_error (error, temp_error);
+ goto out;
+ }
+ }
+
+ ret = TRUE;
+ ot_transfer_out_value(out_value, ret_value);
+ out:
+ g_free (ret_value);
+ return ret;
+}
+
gboolean
ostree_repo_check (OstreeRepo *self, GError **error)
{
OstreeRepoPrivate *priv = GET_PRIVATE (self);
gboolean ret = FALSE;
char *version = NULL;;
- GError *temp_error = NULL;
+ char *mode = NULL;;
+ gboolean is_archive;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -506,12 +574,9 @@ ostree_repo_check (OstreeRepo *self, GError **error)
goto out;
}
- version = g_key_file_get_value (priv->config, "core", "repo_version", &temp_error);
- if (temp_error)
- {
- g_propagate_error (error, temp_error);
- goto out;
- }
+ version = g_key_file_get_value (priv->config, "core", "repo_version", error);
+ if (!version)
+ goto out;
if (strcmp (version, "0") != 0)
{
@@ -520,16 +585,26 @@ ostree_repo_check (OstreeRepo *self, GError **error)
goto out;
}
- priv->archive = g_key_file_get_boolean (priv->config, "core", "archive", &temp_error);
- if (temp_error)
+ if (!keyfile_get_boolean_with_default (priv->config, "core", "archive",
+ FALSE, &is_archive, error))
+ goto out;
+
+ if (is_archive)
+ priv->mode = OSTREE_REPO_MODE_ARCHIVE;
+ else
{
- if (g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND))
- {
- g_clear_error (&temp_error);
- }
+ if (!keyfile_get_value_with_default (priv->config, "core", "mode",
+ "bare", &mode, error))
+ goto out;
+
+ if (strcmp (mode, "bare") == 0)
+ priv->mode = OSTREE_REPO_MODE_BARE;
+ else if (strcmp (mode, "archive") == 0)
+ priv->mode = OSTREE_REPO_MODE_ARCHIVE;
else
{
- g_propagate_error (error, temp_error);
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Invalid mode '%s' in repository configuration", mode);
goto out;
}
}
@@ -538,6 +613,7 @@ ostree_repo_check (OstreeRepo *self, GError **error)
ret = TRUE;
out:
+ g_free (mode);
g_free (version);
return ret;
}
@@ -556,14 +632,14 @@ ostree_repo_get_tmpdir (OstreeRepo *self)
return priv->tmp_dir;
}
-gboolean
-ostree_repo_is_archive (OstreeRepo *self)
+OstreeRepoMode
+ostree_repo_get_mode (OstreeRepo *self)
{
OstreeRepoPrivate *priv = GET_PRIVATE (self);
g_return_val_if_fail (priv->inited, FALSE);
- return priv->archive;
+ return priv->mode;
}
static gboolean
@@ -587,7 +663,7 @@ ostree_repo_stage_object (OstreeRepo *self,
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return FALSE;
- if (objtype == OSTREE_OBJECT_TYPE_FILE && priv->archive)
+ if (objtype == OSTREE_OBJECT_TYPE_FILE && priv->mode == OSTREE_REPO_MODE_ARCHIVE)
{
if (!ostree_create_temp_regular_file (priv->tmp_dir,
"archive-tmp-", NULL,
@@ -868,7 +944,7 @@ ostree_repo_get_object_path (OstreeRepo *self,
char *relpath;
GFile *ret;
- relpath = ostree_get_relative_object_path (checksum, type, priv->archive);
+ relpath = ostree_get_relative_object_path (checksum, type, priv->mode == OSTREE_REPO_MODE_ARCHIVE);
path = g_build_filename (priv->path, relpath, NULL);
g_free (relpath);
ret = ot_gfile_new_for_path (path);
@@ -2063,7 +2139,7 @@ checkout_tree (OstreeRepo *self,
object_path = ostree_repo_get_object_path (self, checksum, OSTREE_OBJECT_TYPE_FILE);
- if (priv->archive)
+ if (priv->mode == OSTREE_REPO_MODE_ARCHIVE)
{
if (!ostree_parse_packed_file (object_path, NULL, &xattrs, &packed_input,
cancellable, error))
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 4a29b68..4a2d140 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -55,7 +55,12 @@ gboolean ostree_repo_check (OstreeRepo *self, GError **error);
const char * ostree_repo_get_path (OstreeRepo *self);
-gboolean ostree_repo_is_archive (OstreeRepo *self);
+typedef enum {
+ OSTREE_REPO_MODE_BARE,
+ OSTREE_REPO_MODE_ARCHIVE
+} OstreeRepoMode;
+
+OstreeRepoMode ostree_repo_get_mode (OstreeRepo *self);
GFile * ostree_repo_get_tmpdir (OstreeRepo *self);
diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c
index f193644..8f65db6 100644
--- a/src/ostree/ot-builtin-fsck.c
+++ b/src/ostree/ot-builtin-fsck.c
@@ -126,7 +126,7 @@ object_iter_callback (OstreeRepo *repo,
if (nlinks < 2 && !quiet)
g_printerr ("note: floating object: %s\n", path); */
- if (ostree_repo_is_archive (repo)
+ if (ostree_repo_get_mode (repo) == OSTREE_REPO_MODE_ARCHIVE
&& objtype == OSTREE_OBJECT_TYPE_FILE)
{
if (!g_str_has_suffix (path, ".packfile"))
diff --git a/src/ostree/ot-builtin-init.c b/src/ostree/ot-builtin-init.c
index 4749437..7c9fd95 100644
--- a/src/ostree/ot-builtin-init.c
+++ b/src/ostree/ot-builtin-init.c
@@ -59,7 +59,8 @@ ostree_builtin_init (int argc, char **argv, const char *repo_path, GError **erro
child = g_file_get_child (repodir, "config");
config_data = g_string_new (DEFAULT_CONFIG_CONTENTS);
- g_string_append_printf (config_data, "archive=%s\n", archive ? "true" : "false");
+ if (archive)
+ g_string_append_printf (config_data, "mode=%s\n", archive ? "archive" : "bare");
if (!g_file_replace_contents (child,
config_data->str,
config_data->len,
diff --git a/src/ostree/ot-builtin-local-clone.c b/src/ostree/ot-builtin-local-clone.c
index 618e289..5df7b21 100644
--- a/src/ostree/ot-builtin-local-clone.c
+++ b/src/ostree/ot-builtin-local-clone.c
@@ -97,7 +97,7 @@ object_iter_callback (OstreeRepo *repo,
GError *error = NULL;
gboolean did_exist;
- if (ostree_repo_is_archive (data->src_repo))
+ if (ostree_repo_get_mode (data->src_repo) == OSTREE_REPO_MODE_ARCHIVE)
{
if (!ostree_repo_store_packfile (data->dest_repo, checksum,
ot_gfile_get_path_cached (objfile),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]