core: Add a config file with repo version
This should let us expand later.
This commit is contained in:
parent
1aac09fee9
commit
ac99188c23
|
|
@ -58,9 +58,12 @@ struct _OstreeRepoPrivate {
|
||||||
GFile *repo_file;
|
GFile *repo_file;
|
||||||
char *head_ref_path;
|
char *head_ref_path;
|
||||||
char *objects_path;
|
char *objects_path;
|
||||||
|
char *config_path;
|
||||||
|
|
||||||
gboolean inited;
|
gboolean inited;
|
||||||
char *current_head;
|
char *current_head;
|
||||||
|
|
||||||
|
GKeyFile *config;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -73,7 +76,10 @@ ostree_repo_finalize (GObject *object)
|
||||||
g_clear_object (&priv->repo_file);
|
g_clear_object (&priv->repo_file);
|
||||||
g_free (priv->head_ref_path);
|
g_free (priv->head_ref_path);
|
||||||
g_free (priv->objects_path);
|
g_free (priv->objects_path);
|
||||||
|
g_free (priv->config_path);
|
||||||
g_free (priv->current_head);
|
g_free (priv->current_head);
|
||||||
|
if (priv->config)
|
||||||
|
g_key_file_free (priv->config);
|
||||||
|
|
||||||
G_OBJECT_CLASS (ostree_repo_parent_class)->finalize (object);
|
G_OBJECT_CLASS (ostree_repo_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +144,7 @@ ostree_repo_constructor (GType gtype,
|
||||||
|
|
||||||
priv->head_ref_path = g_build_filename (priv->path, "HEAD", NULL);
|
priv->head_ref_path = g_build_filename (priv->path, "HEAD", NULL);
|
||||||
priv->objects_path = g_build_filename (priv->path, "objects", NULL);
|
priv->objects_path = g_build_filename (priv->path, "objects", NULL);
|
||||||
|
priv->config_path = g_build_filename (priv->path, "config", NULL);
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
@ -231,6 +238,8 @@ gboolean
|
||||||
ostree_repo_check (OstreeRepo *self, GError **error)
|
ostree_repo_check (OstreeRepo *self, GError **error)
|
||||||
{
|
{
|
||||||
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
char *version = NULL;;
|
||||||
|
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||||
|
|
||||||
|
|
@ -241,12 +250,36 @@ ostree_repo_check (OstreeRepo *self, GError **error)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
"Couldn't find objects directory '%s'", priv->objects_path);
|
"Couldn't find objects directory '%s'", priv->objects_path);
|
||||||
return FALSE;
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parse_checksum_file (self, priv->head_ref_path, &priv->current_head, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
priv->config = g_key_file_new ();
|
||||||
|
if (!g_key_file_load_from_file (priv->config, priv->config_path, 0, error))
|
||||||
|
{
|
||||||
|
g_prefix_error (error, "Couldn't parse config file: ");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
version = g_key_file_get_value (priv->config, "core", "repo_version", error);
|
||||||
|
if (!version)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (strcmp (version, "0") != 0)
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"Invalid repository version '%s'", version);
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->inited = TRUE;
|
priv->inited = TRUE;
|
||||||
|
|
||||||
return parse_checksum_file (self, priv->head_ref_path, &priv->current_head, error);
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
g_free (version);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,10 @@ static GOptionEntry options[] = {
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define DEFAULT_CONFIG_CONTENTS ("[core]\n" \
|
||||||
|
"repo_version=0\n")
|
||||||
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ostree_builtin_init (int argc, char **argv, const char *prefix, GError **error)
|
ostree_builtin_init (int argc, char **argv, const char *prefix, GError **error)
|
||||||
{
|
{
|
||||||
|
|
@ -39,8 +43,10 @@ ostree_builtin_init (int argc, char **argv, const char *prefix, GError **error)
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
char *otdir_path = NULL;
|
char *otdir_path = NULL;
|
||||||
char *objects_path = NULL;
|
char *objects_path = NULL;
|
||||||
|
char *config_path = NULL;
|
||||||
GFile *otdir = NULL;
|
GFile *otdir = NULL;
|
||||||
GFile *objects_dir = NULL;
|
GFile *objects_dir = NULL;
|
||||||
|
GFile *configf = NULL;
|
||||||
|
|
||||||
context = g_option_context_new ("- Initialize a new empty repository");
|
context = g_option_context_new ("- Initialize a new empty repository");
|
||||||
g_option_context_add_main_entries (context, options, NULL);
|
g_option_context_add_main_entries (context, options, NULL);
|
||||||
|
|
@ -56,11 +62,25 @@ ostree_builtin_init (int argc, char **argv, const char *prefix, GError **error)
|
||||||
if (!g_file_make_directory (objects_dir, NULL, error))
|
if (!g_file_make_directory (objects_dir, NULL, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
config_path = g_build_filename (repo_path, "config", NULL);
|
||||||
|
configf = g_file_new_for_path (config_path);
|
||||||
|
|
||||||
|
if (!g_file_replace_contents (configf,
|
||||||
|
DEFAULT_CONFIG_CONTENTS,
|
||||||
|
strlen (DEFAULT_CONFIG_CONTENTS),
|
||||||
|
NULL, FALSE, 0, NULL,
|
||||||
|
NULL, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
if (context)
|
if (context)
|
||||||
g_option_context_free (context);
|
g_option_context_free (context);
|
||||||
g_free (otdir_path);
|
g_free (otdir_path);
|
||||||
|
g_free (objects_path);
|
||||||
|
g_free (config_path);
|
||||||
g_clear_object (&otdir);
|
g_clear_object (&otdir);
|
||||||
|
g_clear_object (&objects_dir);
|
||||||
|
g_clear_object (&configf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue