[ostree/wip/pull: 5/5] more bits



commit bb7b3f0162f0877349db8f6a212de0c697ec7aa1
Author: Colin Walters <walters verbum org>
Date:   Sat Oct 29 20:14:03 2011 -0400

    more bits

 src/libostree/ostree-core.c |   28 +++++++++++++++++++---------
 src/libostree/ostree-core.h |    1 +
 src/libostree/ostree-repo.c |   10 +++++-----
 src/libostree/ostree-repo.h |    8 ++++----
 src/ot-builtin-fsck.c       |   10 +++++++++-
 src/ot-builtin-pull.c       |    3 ++-
 tests/t0012-pull.sh         |    1 +
 7 files changed, 41 insertions(+), 20 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index c0b8e74..0deb764 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -168,9 +168,10 @@ ostree_get_xattrs_for_path (const char *path,
 
 gboolean
 ostree_stat_and_checksum_file (int dir_fd, const char *path,
-                                 GChecksum **out_checksum,
-                                 struct stat *out_stbuf,
-                                 GError **error)
+                               OstreeObjectType objtype,
+                               GChecksum **out_checksum,
+                               struct stat *out_stbuf,
+                               GError **error)
 {
   GChecksum *content_sha256 = NULL;
   GChecksum *content_and_meta_sha256 = NULL;
@@ -216,10 +217,13 @@ ostree_stat_and_checksum_file (int dir_fd, const char *path,
         }
     }
 
-  stat_string = stat_to_string (&stbuf);
-  xattrs = ostree_get_xattrs_for_path (path, error);
-  if (!xattrs)
-    goto out;
+  if (objtype == OSTREE_OBJECT_TYPE_FILE)
+    {
+      stat_string = stat_to_string (&stbuf);
+      xattrs = ostree_get_xattrs_for_path (path, error);
+      if (!xattrs)
+        goto out;
+    }
 
   content_sha256 = g_checksum_new (G_CHECKSUM_SHA256);
  
@@ -238,6 +242,8 @@ ostree_stat_and_checksum_file (int dir_fd, const char *path,
   else if (S_ISLNK(stbuf.st_mode))
     {
       symlink_target = g_malloc (PATH_MAX);
+
+      g_assert (objtype == OSTREE_OBJECT_TYPE_FILE);
       
       bytes_read = readlinkat (dir_fd, basename, symlink_target, PATH_MAX);
       if (bytes_read < 0)
@@ -249,6 +255,7 @@ ostree_stat_and_checksum_file (int dir_fd, const char *path,
     }
   else if (S_ISCHR(stbuf.st_mode) || S_ISBLK(stbuf.st_mode))
     {
+      g_assert (objtype == OSTREE_OBJECT_TYPE_FILE);
       device_id = g_strdup_printf ("%u", (guint)stbuf.st_rdev);
       g_checksum_update (content_sha256, (guint8*)device_id, strlen (device_id));
     }
@@ -263,8 +270,11 @@ ostree_stat_and_checksum_file (int dir_fd, const char *path,
 
   content_and_meta_sha256 = g_checksum_copy (content_sha256);
 
-  g_checksum_update (content_and_meta_sha256, (guint8*)stat_string, strlen (stat_string));
-  g_checksum_update (content_and_meta_sha256, (guint8*)g_variant_get_data (xattrs), g_variant_get_size (xattrs));
+  if (objtype == OSTREE_OBJECT_TYPE_FILE)
+    {
+      g_checksum_update (content_and_meta_sha256, (guint8*)stat_string, strlen (stat_string));
+      g_checksum_update (content_and_meta_sha256, (guint8*)g_variant_get_data (xattrs), g_variant_get_size (xattrs));
+    }
 
   *out_stbuf = stbuf;
   *out_checksum = content_and_meta_sha256;
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h
index 03d8375..d5b7637 100644
--- a/src/libostree/ostree-core.h
+++ b/src/libostree/ostree-core.h
@@ -99,6 +99,7 @@ gboolean ostree_parse_metadata_file (const char                  *path,
                                      GError                     **error);
 
 gboolean ostree_stat_and_checksum_file (int dirfd, const char *path,
+                                        OstreeObjectType type,
                                         GChecksum **out_checksum,
                                         struct stat *out_stbuf,
                                         GError **error);
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 6ebd67b..c8819f8 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -776,7 +776,7 @@ link_one_file (OstreeRepo *self, const char *path, OstreeObjectType type,
   GChecksum *id = NULL;
   gboolean did_exist;
 
-  if (!ostree_stat_and_checksum_file (-1, path, &id, &stbuf, error))
+  if (!ostree_stat_and_checksum_file (-1, path, type, &id, &stbuf, error))
     goto out;
 
   if (!ostree_repo_store_object_trusted (self, path, g_checksum_get_string (id), type,
@@ -794,10 +794,10 @@ link_one_file (OstreeRepo *self, const char *path, OstreeObjectType type,
 
 gboolean
 ostree_repo_link_file (OstreeRepo *self,
-                         const char   *path,
-                         gboolean      ignore_exists,
-                         gboolean      force,
-                         GError      **error)
+                       const char   *path,
+                       gboolean      ignore_exists,
+                       gboolean      force,
+                       GError      **error)
 {
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
   GChecksum *checksum = NULL;
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 36149ef..4274484 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -64,10 +64,10 @@ gboolean      ostree_repo_write_config (OstreeRepo *self,
                                         GError    **error);
 
 gboolean      ostree_repo_link_file (OstreeRepo *self,
-                                       const char   *path,
-                                       gboolean      ignore_exists,
-                                       gboolean      force,
-                                       GError      **error);
+                                     const char   *path,
+                                     gboolean      ignore_exists,
+                                     gboolean      force,
+                                     GError      **error);
 
 gboolean      ostree_repo_store_object_trusted (OstreeRepo   *self,
                                                 const char   *path,
diff --git a/src/ot-builtin-fsck.c b/src/ot-builtin-fsck.c
index 766d17f..3e20bd6 100644
--- a/src/ot-builtin-fsck.c
+++ b/src/ot-builtin-fsck.c
@@ -53,6 +53,7 @@ object_iter_callback (OstreeRepo  *repo,
   char *checksum_prefix = NULL;
   char *checksum_string = NULL;
   char *filename_checksum = NULL;
+  OstreeObjectType objtype;
   char *dot;
 
   dirname = g_path_get_dirname (path);
@@ -62,7 +63,14 @@ object_iter_callback (OstreeRepo  *repo,
      if (nlinks < 2 && !quiet)
      g_printerr ("note: floating object: %s\n", path); */
 
-  if (!ostree_stat_and_checksum_file (-1, path, &checksum, &stbuf, &error))
+  if (g_str_has_suffix (path, ".meta"))
+    objtype = OSTREE_OBJECT_TYPE_META;
+  else if (g_str_has_suffix (path, ".file"))
+    objtype = OSTREE_OBJECT_TYPE_FILE;
+  else
+    g_assert_not_reached ();
+
+  if (!ostree_stat_and_checksum_file (-1, path, objtype, &checksum, &stbuf, &error))
     goto out;
 
   filename_checksum = g_strdup (g_file_info_get_name (file_info));
diff --git a/src/ot-builtin-pull.c b/src/ot-builtin-pull.c
index 07d5513..3c00ad6 100644
--- a/src/ot-builtin-pull.c
+++ b/src/ot-builtin-pull.c
@@ -125,7 +125,7 @@ store_object (OstreeRepo  *repo,
   if (!fetch_uri (repo, soup, obj_uri, &filename, error))
     goto out;
 
-  if (!ostree_stat_and_checksum_file (-1, filename, &checksum,
+  if (!ostree_stat_and_checksum_file (-1, filename, objtype, &checksum,
                                       &stbuf, error))
     goto out;
 
@@ -345,6 +345,7 @@ ostree_builtin_pull (int argc, char **argv, const char *prefix, GError **error)
   rev = ot_util_get_file_contents_utf8 (temppath, error);
   if (!rev)
     goto out;
+  g_strchomp (rev);
 
   if (!ostree_validate_checksum_string (rev, error))
     goto out;
diff --git a/tests/t0012-pull.sh b/tests/t0012-pull.sh
index a98466e..ab3ac91 100755
--- a/tests/t0012-pull.sh
+++ b/tests/t0012-pull.sh
@@ -19,6 +19,7 @@
 # Author: Colin Walters <walters verbum org>
 
 set -e
+set -x
 
 . libtest.sh
 



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