[ostree/wip/packfile-rebase2] pull really works
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree/wip/packfile-rebase2] pull really works
- Date: Sat, 31 Mar 2012 14:19:34 +0000 (UTC)
commit b6b5f974a8546c0aa85e0eed49c7bcb8e026ce92
Author: Colin Walters <walters verbum org>
Date: Sat Mar 31 10:18:04 2012 -0400
pull really works
src/libostree/ostree-core.c | 8 ++--
src/ostree/ostree-pull.c | 4 +-
src/ostree/ot-builtin-fsck.c | 92 +++++++++++++++++++++--------------------
tests/t0010-pull.sh | 2 +
4 files changed, 55 insertions(+), 51 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 8da0d8e..1e3a9e1 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -1415,7 +1415,6 @@ ostree_pack_index_search (GVariant *index,
g_variant_get_child (index_contents, imid, "(u ayt)", &cur_objtype,
&cur_csum_bytes, &cur_offset);
cur_objtype = GUINT32_FROM_BE (cur_objtype);
- cur_offset = GUINT64_FROM_BE (cur_offset);
c = ostree_cmp_checksum_bytes (cur_csum_bytes, csum_bytes);
if (c == 0)
@@ -1437,12 +1436,13 @@ ostree_pack_index_search (GVariant *index,
}
else
{
- *out_offset = cur_offset;
- break;
+ if (out_offset)
+ *out_offset = GUINT64_FROM_BE (cur_offset);
+ ret = TRUE;
+ goto out;
}
}
- ret = TRUE;
out:
ot_clear_gvariant (&index_contents);
return ret;
diff --git a/src/ostree/ostree-pull.c b/src/ostree/ostree-pull.c
index 9d092c8..1e54356 100644
--- a/src/ostree/ostree-pull.c
+++ b/src/ostree/ostree-pull.c
@@ -478,9 +478,9 @@ find_object (OtPullData *pull_data,
*out_is_stored = ret_is_stored;
if (out_is_pending)
*out_is_pending = ret_is_pending;
+ ot_transfer_out_value (out_remote_pack_checksum, &ret_remote_pack_checksum);
if (out_offset)
*out_offset = offset;
- ot_transfer_out_value (out_remote_pack_checksum, &ret_remote_pack_checksum);
out:
g_free (local_pack_checksum);
g_free (ret_remote_pack_checksum);
@@ -513,7 +513,7 @@ fetch_object_if_not_stored (OtPullData *pull_data,
GFile *pack_path = NULL;
GMappedFile *pack_map = NULL;
char *remote_pack_checksum = NULL;
- guint64 pack_offset;
+ guint64 pack_offset = 0;
GVariant *pack_entry = NULL;
if (!find_object (pull_data, checksum, objtype, &ret_is_stored,
diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c
index 41876c4..96c4396 100644
--- a/src/ostree/ot-builtin-fsck.c
+++ b/src/ostree/ot-builtin-fsck.c
@@ -39,8 +39,8 @@ static GOptionEntry options[] = {
typedef struct {
OstreeRepo *repo;
- guint n_objects;
- gboolean had_error;
+ guint n_loose_objects;
+ guint n_pack_files;
} OtFsckData;
static gboolean
@@ -124,29 +124,6 @@ checksum_archived_file (OtFsckData *data,
return ret;
}
-static void
-encountered_fsck_error (OtFsckData *data,
- const char *fmt,
- ...) G_GNUC_PRINTF (2, 3);
-
-static void
-encountered_fsck_error (OtFsckData *data,
- const char *fmt,
- ...)
-{
- va_list args;
- char *msg;
-
- va_start (args, fmt);
-
- g_vasprintf (&msg, fmt, args);
- g_printerr ("ERROR: %s\n", msg);
- data->had_error = TRUE;
-
- va_end (args);
-}
-
-
static gboolean
fsck_loose_object (OtFsckData *data,
const char *exp_checksum,
@@ -182,14 +159,14 @@ fsck_loose_object (OtFsckData *data,
if (real_checksum && strcmp (exp_checksum, g_checksum_get_string (real_checksum)) != 0)
{
-
- encountered_fsck_error (data, "corrupted object '%s'; actual checksum: %s",
- ot_gfile_get_path_cached (objf), g_checksum_get_string (real_checksum));
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "corrupted loose object '%s'; actual checksum: %s",
+ ot_gfile_get_path_cached (objf), g_checksum_get_string (real_checksum));
if (delete)
(void) unlink (ot_gfile_get_path_cached (objf));
}
- data->n_objects++;
+ data->n_loose_objects++;
ret = TRUE;
out:
@@ -207,9 +184,14 @@ fsck_pack_files (OtFsckData *data,
GVariant *index_variant = NULL;
GFile *pack_index_path = NULL;
GFile *pack_data_path = NULL;
+ GFileInfo *pack_info = NULL;
GInputStream *input = NULL;
GChecksum *pack_content_checksum = NULL;
+ GVariantIter *index_content_iter = NULL;
guint i;
+ guint32 objtype;
+ guint64 offset;
+ guint64 pack_size;
if (!ostree_repo_list_pack_indexes (data->repo, &pack_indexes, cancellable, error))
goto out;
@@ -228,11 +210,7 @@ fsck_pack_files (OtFsckData *data,
goto out;
if (!ostree_validate_structureof_pack_index (index_variant, error))
- {
- g_prefix_error (error, "Corrupted pack index '%s': ",
- ot_gfile_get_path_cached (pack_index_path));
- goto out;
- }
+ goto out;
g_clear_object (&pack_data_path);
pack_data_path = ostree_repo_get_pack_data_path (data->repo, checksum);
@@ -241,6 +219,13 @@ fsck_pack_files (OtFsckData *data,
input = (GInputStream*)g_file_read (pack_data_path, cancellable, error);
if (!input)
goto out;
+
+ g_clear_object (&pack_info);
+ pack_info = g_file_input_stream_query_info ((GFileInputStream*)input, OSTREE_GIO_FAST_QUERYINFO,
+ cancellable, error);
+ if (!pack_info)
+ goto out;
+ pack_size = g_file_info_get_attribute_uint64 (pack_info, "standard::size");
if (pack_content_checksum)
g_checksum_free (pack_content_checksum);
@@ -249,17 +234,40 @@ fsck_pack_files (OtFsckData *data,
if (strcmp (g_checksum_get_string (pack_content_checksum), checksum) != 0)
{
- encountered_fsck_error (data, "corrupted pack '%s', expected checksum %s",
- checksum, g_checksum_get_string (pack_content_checksum));
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "corrupted pack '%s', expected checksum %s",
+ checksum, g_checksum_get_string (pack_content_checksum));
+ goto out;
+ }
+
+ g_variant_get_child (index_variant, 2, "a(uayt)", &index_content_iter);
+
+ while (g_variant_iter_loop (index_content_iter, "(u ayt)",
+ &objtype, NULL, &offset))
+ {
+ offset = GUINT64_FROM_BE (offset);
+ if (offset > pack_size)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "corrupted pack '%s', offset %" G_GUINT64_FORMAT " larger than file size %" G_GUINT64_FORMAT,
+ checksum,
+ offset, pack_size);
+ goto out;
+ }
}
+
+ data->n_pack_files++;
}
ret = TRUE;
out:
+ if (index_content_iter)
+ g_variant_iter_free (index_content_iter);
if (pack_content_checksum)
g_checksum_free (pack_content_checksum);
if (pack_indexes)
g_ptr_array_unref (pack_indexes);
+ g_clear_object (&pack_info);
g_clear_object (&pack_data_path);
g_clear_object (&input);
return ret;
@@ -288,9 +296,8 @@ ostree_builtin_fsck (int argc, char **argv, GFile *repo_path, GError **error)
if (!ostree_repo_check (repo, error))
goto out;
+ memset (&data, 0, sizeof (data));
data.repo = repo;
- data.n_objects = 0;
- data.had_error = FALSE;
if (!ostree_repo_list_objects (repo, OSTREE_REPO_LIST_OBJECTS_ALL,
&objects, cancellable, error))
@@ -320,14 +327,9 @@ ostree_builtin_fsck (int argc, char **argv, GFile *repo_path, GError **error)
if (!fsck_pack_files (&data, cancellable, error))
goto out;
- if (data.had_error)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Encountered filesystem consistency errors");
- goto out;
- }
if (!quiet)
- g_print ("Total Objects: %u\n", data.n_objects);
+ g_print ("Loose Objects: %u\n", data.n_loose_objects);
+ g_print ("Pack files: %u\n", data.n_pack_files);
ret = TRUE;
out:
diff --git a/tests/t0010-pull.sh b/tests/t0010-pull.sh
index 43e39c1..5f58d11 100755
--- a/tests/t0010-pull.sh
+++ b/tests/t0010-pull.sh
@@ -29,6 +29,7 @@ mkdir repo
ostree --repo=repo init
ostree --repo=repo remote add origin $(cat httpd-address)/ostree/gnomerepo
ostree-pull --repo=repo origin main
+ostree --repo=repo fsck
echo "ok pull"
cd ${test_tmpdir}
@@ -45,6 +46,7 @@ mkdir repo
ostree --repo=repo init
ostree --repo=repo remote add origin $(cat httpd-address)/ostree/gnomerepo
ostree-pull --repo=repo origin main
+ostree --repo=repo fsck
echo "ok pull packed"
cd ${test_tmpdir}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]