[ostree/wip/archive-zlib: 2/2] [wip] Add an archive-z repository mode



commit 6a352955374747df4c73cb5953d294793932049c
Author: Colin Walters <walters verbum org>
Date:   Sat Sep 15 12:44:57 2012 -0400

    [wip] Add an archive-z repository mode
    
    This is where loose content objects are stored as one compressed file,
    instead of the two separate ones for regular archive mode.  This mode
    would be suitable for HTTP servers, beause only one HTTP request is
    necessary, and the result would be compressed.

 src/libostree/ostree-core.c                        |    7 +-
 src/libostree/ostree-core.h                        |    3 +-
 src/libostree/ostree-repo.c                        |  192 ++++++++++++++------
 src/libostree/ostree-repo.h                        |    3 +-
 src/ostree/ostree-pull.c                           |   14 +-
 src/ostree/ot-builtin-init.c                       |   18 ++-
 tests/archive-test.sh                              |  105 +++++++++++
 tests/libtest.sh                                   |    4 +-
 tests/t0001-archive.sh                             |   85 +---------
 tests/{t0003-remote-add.sh => t0002-archivez.sh}   |   11 +-
 tests/{t0002-log.sh => t0003-log.sh}               |    0
 tests/{t0003-remote-add.sh => t0004-remote-add.sh} |    0
 12 files changed, 278 insertions(+), 164 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 39a6531..365cb88 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -909,8 +909,9 @@ ostree_checksum_bytes_peek (GVariant *bytes)
 }
 
 char *
-ostree_get_relative_object_path (const char *checksum,
-                                 OstreeObjectType type)
+ostree_get_relative_object_path (const char         *checksum,
+                                 OstreeObjectType    type,
+                                 gboolean            compressed)
 {
   GString *path;
 
@@ -923,6 +924,8 @@ ostree_get_relative_object_path (const char *checksum,
   g_string_append (path, checksum + 2);
   g_string_append_c (path, '.');
   g_string_append (path, ostree_object_type_to_string (type));
+  if (compressed)
+    g_string_append (path, "z");
 
   return g_string_free (path, FALSE);
 }
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h
index 3617b01..41104be 100644
--- a/src/libostree/ostree-core.h
+++ b/src/libostree/ostree-core.h
@@ -169,7 +169,8 @@ void ostree_object_from_string (const char *str,
                                 OstreeObjectType *out_objtype);
 
 char *ostree_get_relative_object_path (const char        *checksum,
-                                       OstreeObjectType   type);
+                                       OstreeObjectType   type,
+                                       gboolean           compressed);
 
 char *ostree_get_relative_archive_content_path (const char        *checksum);
 
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 9bd44f1..0c4e339 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -598,6 +598,8 @@ ostree_repo_mode_from_string (const char      *mode,
     ret_mode = OSTREE_REPO_MODE_BARE;
   else if (strcmp (mode, "archive") == 0)
     ret_mode = OSTREE_REPO_MODE_ARCHIVE;
+  else if (strcmp (mode, "archive-z") == 0)
+    ret_mode = OSTREE_REPO_MODE_ARCHIVE_Z;
   else
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
@@ -859,6 +861,7 @@ stage_object_internal (OstreeRepo         *self,
  gboolean ret = FALSE;
   const char *actual_checksum;
   gboolean do_commit;
+  OstreeRepoMode repo_mode;
   ot_lobj GFileInfo *temp_info = NULL;
   ot_lobj GFile *temp_file = NULL;
   ot_lobj GFile *raw_temp_file = NULL;
@@ -871,6 +874,8 @@ stage_object_internal (OstreeRepo         *self,
   gboolean staged_archive_file = FALSE;
   gboolean temp_file_is_regular;
 
+  repo_mode = ostree_repo_get_mode (self);
+
   if (out_csum)
     {
       checksum = g_checksum_new (G_CHECKSUM_SHA256);
@@ -879,6 +884,30 @@ stage_object_internal (OstreeRepo         *self,
     }
 
   if (objtype == OSTREE_OBJECT_TYPE_FILE
+      && repo_mode == OSTREE_REPO_MODE_ARCHIVE_Z)
+    {
+      ot_lobj GConverter *zlib_compressor = NULL;
+      ot_lobj GOutputStream *raw_out_stream = NULL;
+      ot_lobj GOutputStream *compressed_out_stream = NULL;
+
+      if (!ostree_create_temp_regular_file (self->tmp_dir,
+                                            ostree_object_type_to_string (objtype), NULL,
+                                            &temp_file, &raw_out_stream,
+                                            cancellable, error))
+        goto out;
+
+      zlib_compressor = (GConverter*)g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP, 9);
+      compressed_out_stream = g_converter_output_stream_new (raw_out_stream, zlib_compressor);
+      
+      if (g_output_stream_splice (compressed_out_stream, checksum_input ? (GInputStream*)checksum_input : input,
+                                  G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
+                                  cancellable, error) < 0)
+        goto out;
+
+      staged_raw_file = TRUE;
+      temp_file_is_regular = TRUE;
+    }
+  else if (objtype == OSTREE_OBJECT_TYPE_FILE
       && (flags & OSTREE_REPO_STAGE_FLAGS_LENGTH_VALID) > 0)
     {
       ot_lobj GInputStream *file_input = NULL;
@@ -893,7 +922,7 @@ stage_object_internal (OstreeRepo         *self,
 
       temp_file_is_regular = g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR;
 
-      if (ostree_repo_get_mode (self) == OSTREE_REPO_MODE_BARE)
+      if (repo_mode == OSTREE_REPO_MODE_BARE)
         {
           if (!ostree_create_temp_file_from_input (self->tmp_dir,
                                                    ostree_object_type_to_string (objtype), NULL,
@@ -903,12 +932,12 @@ stage_object_internal (OstreeRepo         *self,
             goto out;
           staged_raw_file = TRUE;
         }
-      else
+      else if (repo_mode == OSTREE_REPO_MODE_ARCHIVE)
         {
           ot_lvariant GVariant *file_meta = NULL;
           ot_lobj GInputStream *file_meta_input = NULL;
           ot_lobj GFileInfo *archive_content_file_info = NULL;
-
+          
           file_meta = ostree_file_header_new (file_info, xattrs);
           file_meta_input = ot_variant_read (file_meta);
 
@@ -956,6 +985,8 @@ stage_object_internal (OstreeRepo         *self,
               staged_archive_file = TRUE;
             }
         }
+      else
+        g_assert_not_reached ();
     }
   else
     {
@@ -1200,6 +1231,7 @@ scan_loose_devino (OstreeRepo                     *self,
   gboolean ret = FALSE;
   GError *temp_error = NULL;
   guint i;
+  OstreeRepoMode repo_mode;
   ot_lptrarray GPtrArray *object_dirs = NULL;
   ot_lobj GFile *objdir = NULL;
 
@@ -1209,6 +1241,10 @@ scan_loose_devino (OstreeRepo                     *self,
         goto out;
     }
 
+  repo_mode = ostree_repo_get_mode (self);
+  if (repo_mode == OSTREE_REPO_MODE_ARCHIVE_Z)
+    return TRUE;
+
   if (!get_loose_object_dirs (self, &object_dirs, cancellable, error))
     goto out;
 
@@ -1227,7 +1263,7 @@ scan_loose_devino (OstreeRepo                     *self,
         goto out;
 
       dirname = ot_gfile_get_basename_cached (objdir);
-  
+
       while ((file_info = g_file_enumerator_next_file (enumerator, cancellable, &temp_error)) != NULL)
         {
           const char *name;
@@ -1245,9 +1281,9 @@ scan_loose_devino (OstreeRepo                     *self,
               continue;
             }
       
-          if (!((ostree_repo_get_mode (self) == OSTREE_REPO_MODE_ARCHIVE
+          if (!((repo_mode == OSTREE_REPO_MODE_ARCHIVE
                  && g_str_has_suffix (name, ".filecontent"))
-                || (ostree_repo_get_mode (self) == OSTREE_REPO_MODE_BARE
+                || (repo_mode == OSTREE_REPO_MODE_BARE
                     && g_str_has_suffix (name, ".file"))))
             {
               g_clear_object (&file_info);
@@ -1407,14 +1443,17 @@ stage_directory_meta (OstreeRepo   *self,
 }
 
 GFile *
-ostree_repo_get_object_path (OstreeRepo  *self,
-                             const char    *checksum,
-                             OstreeObjectType type)
+ostree_repo_get_object_path (OstreeRepo       *self,
+                             const char       *checksum,
+                             OstreeObjectType  type)
 {
   char *relpath;
   GFile *ret;
+  gboolean compressed;
 
-  relpath = ostree_get_relative_object_path (checksum, type);
+  compressed = (type == OSTREE_OBJECT_TYPE_FILE
+                && ostree_repo_get_mode (self) == OSTREE_REPO_MODE_ARCHIVE_Z);
+  relpath = ostree_get_relative_object_path (checksum, type, compressed);
   ret = g_file_resolve_relative_path (self->repodir, relpath);
   g_free (relpath);
  
@@ -1655,7 +1694,8 @@ ostree_repo_write_ref (OstreeRepo  *self,
   if (!write_checksum_file (dir, name, rev, error))
     goto out;
 
-  if (self->mode == OSTREE_REPO_MODE_ARCHIVE)
+  if (self->mode == OSTREE_REPO_MODE_ARCHIVE
+      || self->mode == OSTREE_REPO_MODE_ARCHIVE_Z)
     {
       if (!write_ref_summary (self, NULL, error))
         goto out;
@@ -3489,6 +3529,7 @@ ostree_repo_load_file (OstreeRepo         *self,
   guchar *pack_data;
   guint64 pack_len;
   guint64 pack_offset;
+  OstreeRepoMode repo_mode;
   ot_lvariant GVariant *packed_object = NULL;
   ot_lvariant GVariant *file_data = NULL;
   ot_lobj GFile *loose_path = NULL;
@@ -3504,65 +3545,96 @@ ostree_repo_load_file (OstreeRepo         *self,
                          cancellable, error))
     goto out;
 
+  repo_mode = ostree_repo_get_mode (self);
+
   if (loose_path)
     {
-      if (ostree_repo_get_mode (self) == OSTREE_REPO_MODE_ARCHIVE)
+      switch (repo_mode)
         {
-          ot_lvariant GVariant *archive_meta = NULL;
+        case OSTREE_REPO_MODE_ARCHIVE:
+          {
+            ot_lvariant GVariant *archive_meta = NULL;
 
-          if (!ot_util_variant_map (loose_path, OSTREE_FILE_HEADER_GVARIANT_FORMAT,
-                                    TRUE, &archive_meta, error))
-            goto out;
+            if (!ot_util_variant_map (loose_path, OSTREE_FILE_HEADER_GVARIANT_FORMAT,
+                                      TRUE, &archive_meta, error))
+              goto out;
 
-          if (!ostree_file_header_parse (archive_meta, &ret_file_info, &ret_xattrs,
-                                         error))
-            goto out;
+            if (!ostree_file_header_parse (archive_meta, &ret_file_info, &ret_xattrs,
+                                           error))
+              goto out;
 
-          if (g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_REGULAR)
-            {
-              ot_lobj GFile *archive_content_path = NULL;
-              ot_lobj GFileInfo *content_info = NULL;
-
-              archive_content_path = ostree_repo_get_archive_content_path (self, checksum);
-              content_info = g_file_query_info (archive_content_path, OSTREE_GIO_FAST_QUERYINFO,
-                                                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-                                                cancellable, error);
-              if (!content_info)
-                goto out;
+            if (g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_REGULAR)
+              {
+                ot_lobj GFile *archive_content_path = NULL;
+                ot_lobj GFileInfo *content_info = NULL;
 
-              if (out_input)
-                {
-                  ret_input = (GInputStream*)g_file_read (archive_content_path, cancellable, error);
-                  if (!ret_input)
-                    goto out;
-                }
-              g_file_info_set_size (ret_file_info, g_file_info_get_size (content_info));
-            }
-        }
-      else
-        {
-          ret_file_info = g_file_query_info (loose_path, OSTREE_GIO_FAST_QUERYINFO,
-                                             G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-                                             cancellable, error);
-          if (!ret_file_info)
-            goto out;
+                archive_content_path = ostree_repo_get_archive_content_path (self, checksum);
+                content_info = g_file_query_info (archive_content_path, OSTREE_GIO_FAST_QUERYINFO,
+                                                  G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                                  cancellable, error);
+                if (!content_info)
+                  goto out;
 
-          if (out_xattrs)
-            {
-              if (!ostree_get_xattrs_for_file (loose_path, &ret_xattrs,
-                                               cancellable, error))
-                goto out;
-            }
+                if (out_input)
+                  {
+                    ret_input = (GInputStream*)g_file_read (archive_content_path, cancellable, error);
+                    if (!ret_input)
+                      goto out;
+                  }
+                g_file_info_set_size (ret_file_info, g_file_info_get_size (content_info));
+              }
+          }
+          break;
+        case OSTREE_REPO_MODE_ARCHIVE_Z:
+          {
+            ot_lobj GConverter *zlib_decomp = NULL;
+            ot_lobj GInputStream *file_in = NULL;
+            ot_lobj GInputStream *decomp_converter = NULL;
+            
+            file_in = (GInputStream*)g_file_read (loose_path, cancellable, error);
+            if (!file_in)
+              goto out;
+            
+            zlib_decomp = (GConverter*)g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP);
+            decomp_converter = g_converter_input_stream_new (file_in, zlib_decomp);
+
+            /* XXX must calculate the total size of the remaining
+             * stream; surely the gzip header has this, but
+             * GZlibDecompressor doesn't set it in the file info; kind
+             * of ugly.
+             */
+            g_assert_not_reached ();
+            
+            ret_input = decomp_converter;
+            decomp_converter = NULL; /* Transfer ownership */
+          }
+          break;
+        case OSTREE_REPO_MODE_BARE:
+          {
+            ret_file_info = g_file_query_info (loose_path, OSTREE_GIO_FAST_QUERYINFO,
+                                               G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                               cancellable, error);
+            if (!ret_file_info)
+              goto out;
 
-          if (out_input && g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_REGULAR)
-            {
-              ret_input = (GInputStream*) g_file_read (loose_path, cancellable, error);
-              if (!ret_input)
-                {
-                  g_prefix_error (error, "Error opening loose file object %s: ", ot_gfile_get_path_cached (loose_path));
+            if (out_xattrs)
+              {
+                if (!ostree_get_xattrs_for_file (loose_path, &ret_xattrs,
+                                                 cancellable, error))
                   goto out;
-                }
-            }
+              }
+
+            if (out_input && g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_REGULAR)
+              {
+                ret_input = (GInputStream*) g_file_read (loose_path, cancellable, error);
+                if (!ret_input)
+                  {
+                    g_prefix_error (error, "Error opening loose file object %s: ", ot_gfile_get_path_cached (loose_path));
+                    goto out;
+                  }
+              }
+          }
+          break;
         }
     }
   else if (pack_checksum)
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 5f5e0df..2175467 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -44,7 +44,8 @@ GFile *       ostree_repo_get_path (OstreeRepo  *self);
 
 typedef enum {
   OSTREE_REPO_MODE_BARE,
-  OSTREE_REPO_MODE_ARCHIVE
+  OSTREE_REPO_MODE_ARCHIVE,
+  OSTREE_REPO_MODE_ARCHIVE_Z
 } OstreeRepoMode;
 
 gboolean       ostree_repo_mode_from_string (const char      *mode,
diff --git a/src/ostree/ostree-pull.c b/src/ostree/ostree-pull.c
index f1804da..da86c27 100644
--- a/src/ostree/ostree-pull.c
+++ b/src/ostree/ostree-pull.c
@@ -82,6 +82,7 @@ static GOptionEntry options[] = {
 typedef struct {
   OstreeRepo   *repo;
   char         *remote_name;
+  OstreeRepoMode remote_mode;
   OstreeFetcher *fetcher;
   SoupURI      *base_uri;
 
@@ -566,7 +567,8 @@ fetch_loose_object (OtPullData  *pull_data,
   ot_lobj GFile *ret_temp_path = NULL;
   SoupURI *obj_uri = NULL;
 
-  objpath = ostree_get_relative_object_path (checksum, objtype);
+  objpath = ostree_get_relative_object_path (checksum, OSTREE_OBJECT_TYPE_FILE,
+                                             pull_data->remote_mode == OSTREE_REPO_MODE_ARCHIVE_Z);
   obj_uri = suburi_new (pull_data->base_uri, objpath, NULL);
   
   if (!fetch_uri (pull_data, obj_uri, ostree_object_type_to_string (objtype), &ret_temp_path,
@@ -1203,7 +1205,8 @@ enqueue_loose_meta_requests (OtPullData *pull_data)
       one_item_data->checksum = g_strdup (checksum);
       one_item_data->fetching_content = FALSE;
           
-      objpath = ostree_get_relative_object_path (checksum, OSTREE_OBJECT_TYPE_FILE);
+      objpath = ostree_get_relative_object_path (checksum, OSTREE_OBJECT_TYPE_FILE,
+                                                 pull_data->remote_mode == OSTREE_REPO_MODE_ARCHIVE_Z);
       obj_uri = suburi_new (pull_data->base_uri, objpath, NULL);
 
       ostree_fetcher_request_uri_async (pull_data->fetcher, obj_uri, cancellable,
@@ -1497,9 +1500,9 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
   gpointer key, value;
   int i;
   GCancellable *cancellable = NULL;
-  OstreeRepoMode remote_repo_mode;
   ot_lfree char *remote_key = NULL;
   ot_lobj OstreeRepo *repo = NULL;
+  ot_lfree char *remote_config_content = NULL;
   ot_lfree char *path = NULL;
   ot_lfree char *baseurl = NULL;
   ot_lfree char *summary_data = NULL;
@@ -1565,12 +1568,13 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
                                           &remote_mode_str, error))
     goto out;
 
-  if (!ostree_repo_mode_from_string (remote_mode_str, &remote_repo_mode, error))
+  if (!ostree_repo_mode_from_string (remote_mode_str, &pull_data->remote_mode, error))
     goto out;
 
-  switch (remote_repo_mode)
+  switch (pull_data->remote_mode)
     {
     case OSTREE_REPO_MODE_ARCHIVE:
+    case OSTREE_REPO_MODE_ARCHIVE_Z:
       break;
     default:
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
diff --git a/src/ostree/ot-builtin-init.c b/src/ostree/ot-builtin-init.c
index 6c8c052..c01819e 100644
--- a/src/ostree/ot-builtin-init.c
+++ b/src/ostree/ot-builtin-init.c
@@ -27,10 +27,12 @@
 
 #include <glib/gi18n.h>
 
-static gboolean archive;
+static gboolean opt_archive;
+static char *opt_mode = NULL;
 
 static GOptionEntry options[] = {
-  { "archive", 0, 0, G_OPTION_ARG_NONE, &archive, "Initialize repository as archive", NULL },
+  { "archive", 0, 0, G_OPTION_ARG_NONE, &opt_archive, "Initialize repository as archive", NULL },
+  { "mode", 0, 0, G_OPTION_ARG_STRING, &opt_mode, "Initialize repository in given mode (bare, archive, archive-z)", NULL },
   { NULL }
 };
 
@@ -44,6 +46,7 @@ ostree_builtin_init (int argc, char **argv, GFile *repo_path, GError **error)
   GOptionContext *context = NULL;
   gboolean ret = FALSE;
   GCancellable *cancellable = NULL;
+  const char *mode_str = "bare";
   ot_lobj GFile *child = NULL;
   ot_lobj GFile *grandchild = NULL;
   ot_lobj OstreeRepo *repo = NULL;
@@ -58,7 +61,16 @@ ostree_builtin_init (int argc, char **argv, GFile *repo_path, GError **error)
   child = g_file_get_child (repo_path, "config");
 
   config_data = g_string_new (DEFAULT_CONFIG_CONTENTS);
-  g_string_append_printf (config_data, "mode=%s\n", archive ? "archive" : "bare");
+  if (opt_archive)
+    mode_str = "archive";
+  else if (opt_mode)
+    {
+      OstreeRepoMode mode;
+      if (!ostree_repo_mode_from_string (opt_mode, &mode, error))
+        goto out;
+      mode_str = opt_mode;
+    }
+  g_string_append_printf (config_data, "mode=%s\n", mode_str);
   if (!g_file_replace_contents (child,
                                 config_data->str,
                                 config_data->len,
diff --git a/tests/archive-test.sh b/tests/archive-test.sh
new file mode 100755
index 0000000..d2ddd31
--- /dev/null
+++ b/tests/archive-test.sh
@@ -0,0 +1,105 @@
+#!/bin/bash
+#
+# 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.
+
+set -e
+
+$OSTREE checkout test2 checkout-test2
+echo "ok checkout"
+
+cd checkout-test2
+assert_has_file firstfile
+assert_has_file baz/cow
+assert_file_has_content baz/cow moo
+assert_has_file baz/deeper/ohyeah
+echo "ok content"
+
+cd ${test_tmpdir}
+mkdir repo2
+${CMD_PREFIX} ostree --repo=repo2 init
+${CMD_PREFIX} ostree --repo=repo2 pull-local repo
+echo "ok local clone"
+
+cd ${test_tmpdir}
+${CMD_PREFIX} ostree --repo=repo2 checkout test2 test2-checkout-from-local-clone
+cd test2-checkout-from-local-clone
+assert_file_has_content baz/cow moo
+echo "ok local clone checkout"
+
+$OSTREE checkout -U test2 checkout-user-test2
+echo "ok user checkout"
+
+cd ${test_tmpdir}/checkout-test2
+$OSTREE commit -b test2-uid0 -s 'UID 0 test' --owner-uid=0 --owner-gid=0
+echo "ok uid0 commit"
+
+cd ${test_tmpdir}
+$OSTREE ls test2-uid0 /firstfile > uid0-ls-output.txt
+assert_file_has_content uid0-ls-output.txt "-00664 0 0      6 /firstfile" 
+echo "ok uid0 ls"
+
+$OSTREE checkout -U test2-uid0 checkout-user-test2-uid0
+echo "ok user checkout from uid 0"
+
+cd ${test_tmpdir}
+$OSTREE cat test2 /baz/cow > cow-contents
+assert_file_has_content cow-contents "moo"
+echo "ok cat-file"
+
+cd ${test_tmpdir}
+$OSTREE pack
+echo "ok pack"
+
+cd ${test_tmpdir}
+$OSTREE fsck
+echo "ok fsck"
+
+$OSTREE checkout test2 checkout-test2-from-packed
+echo "ok checkout union 1"
+
+cd ${test_tmpdir}
+$OSTREE fsck
+echo "ok fsck"
+
+$OSTREE pack --analyze-only
+echo "ok pack analyze"
+
+$OSTREE unpack
+echo "ok unpack"
+
+cd ${test_tmpdir}
+$OSTREE fsck
+echo "ok fsck"
+
+cd ${test_tmpdir}
+$OSTREE checkout test2 checkout-test2-from-unpacked
+echo "ok checkout union 2"
+
+$OSTREE pack --metadata-only
+echo "ok pack metadata"
+
+$OSTREE fsck
+echo "ok fsck"
+
+cd ${test_tmpdir}
+rm -rf checkout-test2
+$OSTREE checkout test2 checkout-test2
+echo "ok checkout metadata-packed"
+
+$OSTREE unpack
+echo "ok unpack"
diff --git a/tests/libtest.sh b/tests/libtest.sh
index c09639f..faad91d 100644
--- a/tests/libtest.sh
+++ b/tests/libtest.sh
@@ -75,8 +75,8 @@ setup_test_repository () {
     cd repo
     ot_repo="--repo=`pwd`"
     export OSTREE="${CMD_PREFIX} ostree ${ot_repo}"
-    if test "$mode" = "archive"; then
-	$OSTREE init --archive
+    if test -n "$mode"; then
+	$OSTREE init --mode=${mode}
     else
 	$OSTREE init
     fi
diff --git a/tests/t0001-archive.sh b/tests/t0001-archive.sh
index 3a3e706..ffdc28f 100755
--- a/tests/t0001-archive.sh
+++ b/tests/t0001-archive.sh
@@ -26,87 +26,4 @@ echo '1..22'
 setup_test_repository "archive"
 echo "ok setup"
 
-$OSTREE checkout test2 checkout-test2
-echo "ok checkout"
-
-cd checkout-test2
-assert_has_file firstfile
-assert_has_file baz/cow
-assert_file_has_content baz/cow moo
-assert_has_file baz/deeper/ohyeah
-echo "ok content"
-
-cd ${test_tmpdir}
-mkdir repo2
-${CMD_PREFIX} ostree --repo=repo2 init
-${CMD_PREFIX} ostree --repo=repo2 pull-local repo
-echo "ok local clone"
-
-cd ${test_tmpdir}
-${CMD_PREFIX} ostree --repo=repo2 checkout test2 test2-checkout-from-local-clone
-cd test2-checkout-from-local-clone
-assert_file_has_content baz/cow moo
-echo "ok local clone checkout"
-
-$OSTREE checkout -U test2 checkout-user-test2
-echo "ok user checkout"
-
-cd ${test_tmpdir}/checkout-test2
-$OSTREE commit -b test2-uid0 -s 'UID 0 test' --owner-uid=0 --owner-gid=0
-echo "ok uid0 commit"
-
-cd ${test_tmpdir}
-$OSTREE ls test2-uid0 /firstfile > uid0-ls-output.txt
-assert_file_has_content uid0-ls-output.txt "-00664 0 0      6 /firstfile" 
-echo "ok uid0 ls"
-
-$OSTREE checkout -U test2-uid0 checkout-user-test2-uid0
-echo "ok user checkout from uid 0"
-
-cd ${test_tmpdir}
-$OSTREE cat test2 /baz/cow > cow-contents
-assert_file_has_content cow-contents "moo"
-echo "ok cat-file"
-
-cd ${test_tmpdir}
-$OSTREE pack
-echo "ok pack"
-
-cd ${test_tmpdir}
-$OSTREE fsck
-echo "ok fsck"
-
-$OSTREE checkout test2 checkout-test2-from-packed
-echo "ok checkout union 1"
-
-cd ${test_tmpdir}
-$OSTREE fsck
-echo "ok fsck"
-
-$OSTREE pack --analyze-only
-echo "ok pack analyze"
-
-$OSTREE unpack
-echo "ok unpack"
-
-cd ${test_tmpdir}
-$OSTREE fsck
-echo "ok fsck"
-
-cd ${test_tmpdir}
-$OSTREE checkout test2 checkout-test2-from-unpacked
-echo "ok checkout union 2"
-
-$OSTREE pack --metadata-only
-echo "ok pack metadata"
-
-$OSTREE fsck
-echo "ok fsck"
-
-cd ${test_tmpdir}
-rm -rf checkout-test2
-$OSTREE checkout test2 checkout-test2
-echo "ok checkout metadata-packed"
-
-$OSTREE unpack
-echo "ok unpack"
+. ${SRCDIR}/archive-test.sh
diff --git a/tests/t0003-remote-add.sh b/tests/t0002-archivez.sh
similarity index 80%
copy from tests/t0003-remote-add.sh
copy to tests/t0002-archivez.sh
index 6310b2d..817fcda 100755
--- a/tests/t0003-remote-add.sh
+++ b/tests/t0002-archivez.sh
@@ -21,10 +21,9 @@ set -e
 
 . libtest.sh
 
-echo '1..2'
+echo '1..22'
 
-setup_test_repository "regular"
-$OSTREE remote add origin http://example.com/ostree/gnome
-echo "ok remote add"
-assert_file_has_content $test_tmpdir/repo/config "example.com"
-echo "ok config"
+setup_test_repository "archive-z"
+echo "ok setup"
+
+. ${SRCDIR}/archive-test.sh
diff --git a/tests/t0002-log.sh b/tests/t0003-log.sh
similarity index 100%
rename from tests/t0002-log.sh
rename to tests/t0003-log.sh
diff --git a/tests/t0003-remote-add.sh b/tests/t0004-remote-add.sh
similarity index 100%
rename from tests/t0003-remote-add.sh
rename to tests/t0004-remote-add.sh



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