[ostree] core: new function _ostree_parse_delta_name
- From: Giuseppe Scrivano <gscrivano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] core: new function _ostree_parse_delta_name
- Date: Thu, 7 May 2015 20:01:50 +0000 (UTC)
commit ae672c3c9fa0c8ae394566c9265c4227233106c3
Author: Giuseppe Scrivano <gscrivan redhat com>
Date: Tue Apr 28 17:45:37 2015 +0200
core: new function _ostree_parse_delta_name
Signed-off-by: Giuseppe Scrivano <gscrivan redhat com>
Makefile-tests.am | 6 +++-
src/libostree/ostree-core-private.h | 5 +++
src/libostree/ostree-core.c | 19 ++++++++++
tests/test-checksum.c | 63 +++++++++++++++++++++++++++++++++++
4 files changed, 92 insertions(+), 1 deletions(-)
---
diff --git a/Makefile-tests.am b/Makefile-tests.am
index 7350032..6cccb40 100644
--- a/Makefile-tests.am
+++ b/Makefile-tests.am
@@ -112,7 +112,7 @@ noinst_PROGRAMS += tests/test-rollsum
TESTS = tests/test-varint tests/test-ot-unix-utils tests/test-bsdiff tests/test-mutable-tree \
tests/test-keyfile-utils tests/test-ot-opt-utils tests/test-ot-tool-util \
- tests/test-gpg-verify-result
+ tests/test-gpg-verify-result tests/test-checksum
check_PROGRAMS = $(TESTS)
TESTS_ENVIRONMENT = \
@@ -138,6 +138,10 @@ tests_test_varint_LDADD = $(TESTS_LDADD)
tests_test_bsdiff_CFLAGS = $(TESTS_CFLAGS)
tests_test_bsdiff_LDADD = libbsdiff.la $(TESTS_LDADD)
+tests_test_checksum_SOURCES = src/libostree/ostree-core.c tests/test-checksum.c
+tests_test_checksum_CFLAGS = $(TESTS_CFLAGS) $(libglnx_cflags)
+tests_test_checksum_LDADD = $(TESTS_LDADD)
+
tests_test_keyfile_utils_CFLAGS = $(TESTS_CFLAGS)
tests_test_keyfile_utils_LDADD = $(TESTS_LDADD)
diff --git a/src/libostree/ostree-core-private.h b/src/libostree/ostree-core-private.h
index a1584d6..c3c21b2 100644
--- a/src/libostree/ostree-core-private.h
+++ b/src/libostree/ostree-core-private.h
@@ -119,6 +119,11 @@ _ostree_get_commitpartial_path (const char *checksum)
}
void
+_ostree_parse_delta_name (const char *delta_name,
+ char **out_from,
+ char **out_to);
+
+void
_ostree_loose_path (char *buf,
const char *checksum,
OstreeObjectType objtype,
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 3470986..f779f89 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -1496,6 +1496,25 @@ _ostree_get_relative_static_delta_part_path (const char *from,
return _ostree_get_relative_static_delta_path (from, to, partstr);
}
+void
+_ostree_parse_delta_name (const char *delta_name,
+ char **out_from,
+ char **out_to)
+{
+ gs_strfreev char **parts = g_strsplit (delta_name, "-", 2);
+
+ *out_from = *out_to = NULL;
+ if (parts[0] && parts[1])
+ {
+ ot_transfer_out_value (out_from, &parts[0]);
+ ot_transfer_out_value (out_to, &parts[1]);
+ }
+ else
+ {
+ ot_transfer_out_value (out_to, &parts[0]);
+ }
+}
+
/*
* file_header_parse:
* @metadata: A metadata variant of type %OSTREE_FILE_HEADER_GVARIANT_FORMAT
diff --git a/tests/test-checksum.c b/tests/test-checksum.c
new file mode 100644
index 0000000..80b1343
--- /dev/null
+++ b/tests/test-checksum.c
@@ -0,0 +1,63 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * 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.
+ */
+
+#include "config.h"
+
+#include "libgsystem.h"
+#include <glib.h>
+#include <stdlib.h>
+#include <gio/gio.h>
+#include <string.h>
+#include "ostree-core-private.h"
+
+static void
+test_ostree_parse_delta_name (void)
+{
+ {
+ gs_free char *from;
+ gs_free char *to;
+ _ostree_parse_delta_name ("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d", &from,
&to);
+ g_assert_cmpstr (to, ==, "30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d");
+ g_assert_null (from);
+ }
+
+ {
+ gs_free char *from;
+ gs_free char *to;
+ _ostree_parse_delta_name
("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d-5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03",
&from, &to);
+ g_assert_cmpstr (from, ==, "30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d");
+ g_assert_cmpstr (to, ==, "5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03");
+ }
+
+ {
+ gs_free char *from;
+ gs_free char *to;
+ _ostree_parse_delta_name ("", &from, &to);
+ g_assert_null (from);
+ g_assert_null (to);
+ }
+}
+
+int main (int argc, char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/ostree_parse_delta_name", test_ostree_parse_delta_name);
+ return g_test_run();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]