core: new function _ostree_parse_delta_name

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2015-04-28 17:45:37 +02:00
parent e0da4db77c
commit ae672c3c9f
4 changed files with 92 additions and 1 deletions

View File

@ -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)

View File

@ -118,6 +118,11 @@ _ostree_get_commitpartial_path (const char *checksum)
return g_strconcat ("state/", checksum, ".commitpartial", NULL);
}
void
_ostree_parse_delta_name (const char *delta_name,
char **out_from,
char **out_to);
void
_ostree_loose_path (char *buf,
const char *checksum,

View File

@ -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

63
tests/test-checksum.c Normal file
View File

@ -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();
}