summaryrefslogtreecommitdiff
path: root/src/ostree/ot-builtin-init.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2011-11-14 15:39:38 -0500
committerColin Walters <walters@verbum.org>2011-11-14 15:39:38 -0500
commit18f0b537a45f12852e4ec6b174440cbfe7702e4d (patch)
treee8535cb5fe66add1c8725db4a50953aebd8159e9 /src/ostree/ot-builtin-init.c
parent9dc6ddce0848cf04b76fc1c673c8fc1a0f6f425a (diff)
downloadostree-18f0b537a45f12852e4ec6b174440cbfe7702e4d.tar.gz
build: Move sources into src/ again
This is necessary if we want to build when srcdir == builddir, otherwise we blow up because "ostree" is a source directory and a binary.
Diffstat (limited to 'src/ostree/ot-builtin-init.c')
-rw-r--r--src/ostree/ot-builtin-init.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/ostree/ot-builtin-init.c b/src/ostree/ot-builtin-init.c
new file mode 100644
index 00000000..c58d6396
--- /dev/null
+++ b/src/ostree/ot-builtin-init.c
@@ -0,0 +1,112 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters@verbum.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Colin Walters <walters@verbum.org>
+ */
+
+#include "config.h"
+
+#include "ot-builtins.h"
+#include "ostree.h"
+
+#include <glib/gi18n.h>
+
+static gboolean archive;
+
+static GOptionEntry options[] = {
+ { "archive", 0, 0, G_OPTION_ARG_NONE, &archive, "Initialize repository as archive", NULL },
+ { NULL }
+};
+
+#define DEFAULT_CONFIG_CONTENTS ("[core]\n" \
+ "repo_version=0\n")
+
+
+gboolean
+ostree_builtin_init (int argc, char **argv, const char *repo_path, GError **error)
+{
+ GOptionContext *context = NULL;
+ gboolean ret = FALSE;
+ GFile *repodir = NULL;
+ GFile *child = NULL;
+ GFile *grandchild = NULL;
+ GString *config_data = NULL;
+
+ context = g_option_context_new ("- Initialize a new empty repository");
+ g_option_context_add_main_entries (context, options, NULL);
+
+ if (!g_option_context_parse (context, &argc, &argv, error))
+ goto out;
+
+ repodir = ot_util_new_file_for_path (repo_path);
+
+ 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 (!g_file_replace_contents (child,
+ config_data->str,
+ config_data->len,
+ NULL, FALSE, 0, NULL,
+ NULL, error))
+ goto out;
+ g_clear_object (&child);
+
+ child = g_file_get_child (repodir, "objects");
+ if (!g_file_make_directory (child, NULL, error))
+ goto out;
+ g_clear_object (&child);
+
+ child = g_file_get_child (repodir, "tmp");
+ if (!g_file_make_directory (child, NULL, error))
+ goto out;
+ g_clear_object (&child);
+
+ child = g_file_get_child (repodir, "refs");
+ if (!g_file_make_directory (child, NULL, error))
+ goto out;
+
+ grandchild = g_file_get_child (child, "heads");
+ if (!g_file_make_directory (grandchild, NULL, error))
+ goto out;
+ g_clear_object (&grandchild);
+
+ grandchild = g_file_get_child (child, "remotes");
+ if (!g_file_make_directory (grandchild, NULL, error))
+ goto out;
+ g_clear_object (&grandchild);
+
+ g_clear_object (&child);
+
+ child = g_file_get_child (repodir, "tags");
+ if (!g_file_make_directory (child, NULL, error))
+ goto out;
+ g_clear_object (&child);
+
+ ret = TRUE;
+ out:
+ if (context)
+ g_option_context_free (context);
+ if (config_data)
+ g_string_free (config_data, TRUE);
+ g_clear_object (&repodir);
+ g_clear_object (&child);
+ g_clear_object (&grandchild);
+ return ret;
+}