[ostree/wip/packfile-rebase2] pull succeeds



commit 8cc4469813dfa83c9155e05d0e9dd5f1d1e79902
Author: Colin Walters <walters verbum org>
Date:   Fri Mar 30 16:32:24 2012 -0400

    pull succeeds

 src/libostree/ostree-core.c  |   44 ++++++++++++++++++++++++++++---------
 src/libostree/ostree-core.h  |    5 ++++
 src/libostree/ostree-repo.c  |   20 ++++++++++-------
 src/ostree/ostree-pull.c     |   48 ++++++++++++++++++++++++++---------------
 src/ostree/ot-builtin-init.c |   10 ++++++++
 5 files changed, 90 insertions(+), 37 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 9ca8f83..8da0d8e 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -490,6 +490,34 @@ ostree_set_xattrs (GFile  *f,
 }
 
 gboolean
+ostree_unwrap_metadata (GVariant              *container,
+                        OstreeObjectType       expected_type,
+                        GVariant             **out_variant,
+                        GError               **error)
+{
+  gboolean ret = FALSE;
+  GVariant *ret_variant = NULL;
+  guint32 actual_type;
+
+  g_variant_get (container, "(uv)",
+                 &actual_type, &ret_variant);
+  actual_type = GUINT32_FROM_BE (actual_type);
+  if (actual_type != expected_type)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "Corrupted metadata object; found type %u, expected %u",
+                   actual_type, (guint32)expected_type);
+      goto out;
+    }
+
+  ret = TRUE;
+  ot_transfer_out_value (out_variant, &ret_variant);
+ out:
+  ot_clear_gvariant (&ret_variant);
+  return ret;
+}
+
+gboolean
 ostree_map_metadata_file (GFile                       *file,
                           OstreeObjectType             expected_type,
                           GVariant                   **out_variant,
@@ -498,22 +526,16 @@ ostree_map_metadata_file (GFile                       *file,
   gboolean ret = FALSE;
   GVariant *ret_variant = NULL;
   GVariant *container = NULL;
-  guint32 actual_type;
 
   if (!ot_util_variant_map (file, OSTREE_SERIALIZED_VARIANT_FORMAT,
                             &container, error))
     goto out;
 
-  g_variant_get (container, "(uv)",
-                 &actual_type, &ret_variant);
-  ot_util_variant_take_ref (ret_variant);
-  actual_type = GUINT32_FROM_BE (actual_type);
-  if (actual_type != expected_type)
+  if (!ostree_unwrap_metadata (container, expected_type, &ret_variant,
+                               error))
     {
-      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                   "Corrupted metadata object '%s'; found type %u, expected %u",
-                   ot_gfile_get_path_cached (file), 
-                   actual_type, (guint32)expected_type);
+      g_prefix_error (error, "While parsing '%s': ",
+                      ot_gfile_get_path_cached (file));
       goto out;
     }
 
@@ -1535,7 +1557,7 @@ ostree_validate_structureof_pack_superindex (GVariant      *superindex,
 
   g_variant_get_child (superindex, 0, "&s", &header);
 
-  if (strcmp (header, "OSTv0PACKSUPERINDEX") != 0)
+  if (strcmp (header, "OSTv0SUPERPACKINDEX") != 0)
     {
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "Invalid pack superindex; doesn't match header");
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h
index ad08c50..e733f51 100644
--- a/src/libostree/ostree-core.h
+++ b/src/libostree/ostree-core.h
@@ -183,6 +183,11 @@ GVariant *ostree_get_xattrs_for_file (GFile       *f,
 
 GVariant *ostree_wrap_metadata_variant (OstreeObjectType type, GVariant *metadata);
 
+gboolean ostree_unwrap_metadata (GVariant              *container,
+                                 OstreeObjectType       expected_type,
+                                 GVariant             **out_variant,
+                                 GError               **error);
+
 gboolean ostree_set_xattrs (GFile *f, GVariant *xattrs,
                             GCancellable *cancellable, GError **error);
 
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index b48bd34..914e82b 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -164,7 +164,7 @@ ostree_repo_constructor (GType                  gtype,
   
   priv->objects_dir = g_file_get_child (priv->repodir, "objects");
   priv->pack_dir = g_file_get_child (priv->objects_dir, "pack");
-  priv->remote_cache_dir = g_file_get_child (priv->objects_dir, "remote-cache");
+  priv->remote_cache_dir = g_file_get_child (priv->repodir, "remote-cache");
   priv->config_file = g_file_get_child (priv->repodir, "config");
 
   return object;
@@ -1904,16 +1904,17 @@ ensure_remote_cache_dir (OstreeRepo       *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GFile *path = NULL;
+  GFile *ret_cache_dir = NULL;
 
-  path = g_file_get_child (priv->remote_cache_dir, remote_name);
+  ret_cache_dir = g_file_get_child (priv->remote_cache_dir, remote_name);
   
-  if (!ot_gfile_ensure_directory (path, FALSE, error))
+  if (!ot_gfile_ensure_directory (ret_cache_dir, FALSE, error))
     goto out;
 
   ret = TRUE;
+  ot_transfer_out_value (out_cache_dir, &ret_cache_dir);
  out:
-  g_clear_object (&path);
+  g_clear_object (&ret_cache_dir);
   return ret;
 }
 
@@ -3531,6 +3532,7 @@ ostree_repo_load_variant (OstreeRepo  *self,
 {
   gboolean ret = FALSE;
   GFile *object_path = NULL;
+  GFile *pending_path = NULL;
   GVariant *packed_object = NULL;
   GVariant *ret_variant = NULL;
   char *pack_checksum = NULL;
@@ -3541,15 +3543,16 @@ ostree_repo_load_variant (OstreeRepo  *self,
 
   g_return_val_if_fail (OSTREE_OBJECT_TYPE_IS_META (objtype), FALSE);
 
-  if (!ostree_repo_find_object (self, objtype, sha256, &object_path, NULL,
+  if (!ostree_repo_find_object (self, objtype, sha256, &object_path, &pending_path,
                                 &pack_checksum, &object_offset,
                                 cancellable, error))
     goto out;
 
   /* Prefer loose metadata for now */
-  if (object_path != NULL)
+  if (object_path != NULL || pending_path != NULL)
     {
-      if (!ostree_map_metadata_file (object_path, objtype, &ret_variant, error))
+      if (!ostree_map_metadata_file (object_path ? object_path : pending_path,
+                                     objtype, &ret_variant, error))
         goto out;
     }
   else if (pack_checksum != NULL)
@@ -3583,6 +3586,7 @@ ostree_repo_load_variant (OstreeRepo  *self,
   ot_clear_gvariant (&packed_object);
   return ret;
 }
+
 /**
  * ostree_repo_list_objects:
  * @self:
diff --git a/src/ostree/ostree-pull.c b/src/ostree/ostree-pull.c
index 7c32737..467b980 100644
--- a/src/ostree/ostree-pull.c
+++ b/src/ostree/ostree-pull.c
@@ -83,9 +83,12 @@ suburi_new (SoupURI   *base,
   arg_array = g_ptr_array_new ();
   g_ptr_array_add (arg_array, (char*)soup_uri_get_path (base));
   g_ptr_array_add (arg_array, (char*)first);
+
+  va_start (args, first);
   
   while ((arg = va_arg (args, const char *)) != NULL)
     g_ptr_array_add (arg_array, (char*)arg);
+  g_ptr_array_add (arg_array, NULL);
 
   subpath = g_build_filenamev ((char**)arg_array->pdata);
   g_ptr_array_unref (arg_array);
@@ -94,6 +97,8 @@ suburi_new (SoupURI   *base,
   soup_uri_set_path (ret, subpath);
   g_free (subpath);
   
+  va_end (args);
+  
   return ret;
 }
 
@@ -568,7 +573,7 @@ static gboolean
 fetch_and_store_object (OtPullData       *pull_data,
                         const char       *checksum,
                         OstreeObjectType objtype,
-                        gboolean         *out_is_pending,
+                        gboolean         *out_was_stored,
                         GCancellable     *cancellable,
                         GError          **error)
 {
@@ -579,16 +584,16 @@ fetch_and_store_object (OtPullData       *pull_data,
   GFile *pending_path = NULL;
   char *pack_checksum = NULL;
   gboolean is_stored;
-  gboolean ret_is_pending;
+  gboolean is_pending;
 
   g_assert (objtype != OSTREE_OBJECT_TYPE_RAW_FILE);
 
   if (!fetch_object_if_not_stored (pull_data, checksum, objtype,
-                                   &is_stored, &ret_is_pending, &input,
+                                   &is_stored, &is_pending, &input,
                                    cancellable, error))
     goto out;
 
-  if (ret_is_pending || input)
+  if (is_pending || input)
     {
       if (!ostree_repo_stage_object (pull_data->repo, objtype, checksum, NULL, NULL,
                                      input, cancellable, error))
@@ -598,8 +603,8 @@ fetch_and_store_object (OtPullData       *pull_data,
     }
 
   ret = TRUE;
-  if (out_is_pending)
-    *out_is_pending = ret_is_pending;
+  if (out_was_stored)
+    *out_was_stored = is_stored;
  out:
   g_clear_object (&file_info);
   g_clear_object (&input);
@@ -613,17 +618,17 @@ static gboolean
 fetch_and_store_metadata (OtPullData          *pull_data,
                           const char          *checksum,
                           OstreeObjectType     objtype,
-                          gboolean            *out_is_pending,
+                          gboolean            *out_was_stored,
                           GVariant           **out_variant,
                           GCancellable        *cancellable,
                           GError             **error)
 {
   gboolean ret = FALSE;
-  gboolean ret_is_pending;
+  gboolean ret_was_stored;
   GVariant *ret_variant = NULL;
 
   if (!fetch_and_store_object (pull_data, checksum, objtype,
-                               &ret_is_pending, cancellable, error))
+                               &ret_was_stored, cancellable, error))
     goto out;
 
   if (!ostree_repo_load_variant (pull_data->repo, objtype, checksum,
@@ -632,8 +637,8 @@ fetch_and_store_metadata (OtPullData          *pull_data,
 
   ret = TRUE;
   ot_transfer_out_value (out_variant, &ret_variant);
-  if (out_is_pending)
-    *out_is_pending = ret_is_pending;
+  if (out_was_stored)
+    *out_was_stored = ret_was_stored;
  out:
   ot_clear_gvariant (&ret_variant);
   return ret;
@@ -650,6 +655,7 @@ fetch_and_store_file (OtPullData          *pull_data,
   GFile *stored_path = NULL;
   GFile *pending_path = NULL;
   char *pack_checksum = NULL;
+  GVariant *archive_metadata_container = NULL;
   GVariant *archive_metadata = NULL;
   GFileInfo *archive_file_info = NULL;
   GVariant *archive_xattrs = NULL;
@@ -694,7 +700,11 @@ fetch_and_store_file (OtPullData          *pull_data,
       if (input != NULL)
         {
           if (!ot_util_variant_from_stream (input, OSTREE_SERIALIZED_VARIANT_FORMAT,
-                                            FALSE, &archive_metadata, cancellable, error))
+                                            FALSE, &archive_metadata_container, cancellable, error))
+            goto out;
+
+          if (!ostree_unwrap_metadata (archive_metadata_container, OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META,
+                                       &archive_metadata, error))
             goto out;
   
           if (!ostree_parse_archived_file_meta (archive_metadata, &archive_file_info,
@@ -724,6 +734,8 @@ fetch_and_store_file (OtPullData          *pull_data,
   g_clear_object (&stored_path);
   g_clear_object (&pending_path);
   g_clear_object (&input);
+  ot_clear_gvariant (&archive_metadata_container);
+  ot_clear_gvariant (&archive_metadata);
   ot_clear_gvariant (&archive_xattrs);
   g_clear_object (&archive_file_info);
   return ret;
@@ -739,17 +751,17 @@ fetch_and_store_tree_recurse (OtPullData   *pull_data,
   GVariant *tree = NULL;
   GVariant *files_variant = NULL;
   GVariant *dirs_variant = NULL;
-  gboolean is_pending;
+  gboolean was_stored;
   int i, n;
   GFile *stored_path = NULL;
   GFile *pending_path = NULL;
   char *pack_checksum = NULL;
 
   if (!fetch_and_store_metadata (pull_data, rev, OSTREE_OBJECT_TYPE_DIR_TREE,
-                                 &is_pending, &tree, cancellable, error))
+                                 &was_stored, &tree, cancellable, error))
     goto out;
 
-  if (!is_pending)
+  if (was_stored)
     log_verbose ("Already have tree %s", rev);
   else
     {
@@ -821,13 +833,13 @@ fetch_and_store_commit_recurse (OtPullData   *pull_data,
   GVariant *commit = NULL;
   const char *tree_contents_checksum;
   const char *tree_meta_checksum;
-  gboolean is_pending;
+  gboolean was_stored;
 
   if (!fetch_and_store_metadata (pull_data, rev, OSTREE_OBJECT_TYPE_COMMIT,
-                                 &is_pending, &commit, cancellable, error))
+                                 &was_stored, &commit, cancellable, error))
     goto out;
 
-  if (!is_pending)
+  if (was_stored)
     log_verbose ("Already have commit %s", rev);
   else
     {
diff --git a/src/ostree/ot-builtin-init.c b/src/ostree/ot-builtin-init.c
index b194097..5d648d8 100644
--- a/src/ostree/ot-builtin-init.c
+++ b/src/ostree/ot-builtin-init.c
@@ -45,7 +45,9 @@ ostree_builtin_init (int argc, char **argv, GFile *repo_path, GError **error)
   gboolean ret = FALSE;
   GFile *child = NULL;
   GFile *grandchild = NULL;
+  GCancellable *cancellable = NULL;
   GString *config_data = NULL;
+  OstreeRepo *repo = NULL;
 
   context = g_option_context_new ("- Initialize a new empty repository");
   g_option_context_add_main_entries (context, options, NULL);
@@ -104,6 +106,13 @@ ostree_builtin_init (int argc, char **argv, GFile *repo_path, GError **error)
   if (!g_file_make_directory (child, NULL, error))
     goto out;
 
+  repo = ostree_repo_new (repo_path);
+  if (!ostree_repo_check (repo, error))
+    goto out;
+
+  if (!ostree_repo_regenerate_pack_index (repo, cancellable, error))
+    goto out;
+
   ret = TRUE;
  out:
   if (context)
@@ -112,5 +121,6 @@ ostree_builtin_init (int argc, char **argv, GFile *repo_path, GError **error)
     g_string_free (config_data, TRUE);
   g_clear_object (&child);
   g_clear_object (&grandchild);
+  g_clear_object (&repo);
   return ret;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]