Commit 750f9204 authored by Andrej Shadura's avatar Andrej Shadura

New upstream version 0.0~git20190304.5d29096

parent 22a65f63
......@@ -188,4 +188,12 @@ _ostree_repo_commit_modifier_new_wrapper (OstreeRepoCommitModifierFlags flags,
return ostree_repo_commit_modifier_new(flags, _commit_filter, user_data, destroy_notify);
}
// Wrapper for variadic variables
static gboolean _g_variant_iter_next_twoargs(GVariantIter *iter,
const gchar *format_string,
gchar **key,
GVariant **value)
{
return g_variant_iter_next(iter, format_string, key, value);
}
#endif
......@@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"sort"
"strings"
"time"
"unsafe"
......@@ -47,6 +48,8 @@ type commitOptions struct {
Timestamp time.Time // Override the timestamp of the commit
Orphan bool // Commit does not belong to a branch
Fsync bool // Specify whether fsync should be used or not. Default to true
CollectionID string // Collection ID binding
RefBinding []string // Refs binding,each element is a branch name
}
// Initializes a commitOptions struct and sets default values
......@@ -207,6 +210,8 @@ func (repo *Repo) Commit(commitPath, branch string, opts commitOptions) (string,
goto out
}
metadata = addRefs(metadata, options.CollectionID, options.RefBinding)
if options.NoXattrs {
C._ostree_repo_append_modifier_flags(&flags, C.OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS)
}
......@@ -407,6 +412,60 @@ out:
return "", generateError(cerr)
}
// Return the pointer to metadata
// Metadata is recreated only if need to add Collection ID or refBindings.
func addRefs(metadata *C.GVariant, collectionStr string, refStr []string) *C.GVariant {
builder := C.g_variant_builder_new(C._g_variant_type(C.CString("a{sv}")))
defer C.g_variant_builder_unref(builder)
if strings.Compare(collectionStr, "") == 0 && len(refStr) == 0 {
// Do not need to recreate metadata
goto out
}
// Add Ref bindings
if len(refStr) != 0 {
sort.Strings(refStr)
refs := C.g_ptr_array_new()
defer C.g_ptr_array_unref(refs)
for _, ref := range refStr {
refc := C.CString(ref)
C.g_ptr_array_add(refs, (C.gpointer)(refc))
}
refs_v := C.g_variant_new_strv(
(**C.gchar)(unsafe.Pointer(refs.pdata)),
C.gssize(len(refStr)))
C._g_variant_builder_add_twoargs(builder, C.CString("{s@v}"),
C.CString(C.OSTREE_COMMIT_META_KEY_REF_BINDING),
C.g_variant_new_variant(refs_v))
}
// Add Collection ID binding
if strings.Compare(collectionStr, "") != 0 {
collection_id := C.g_variant_new_string((*C.gchar)(C.CString(collectionStr)))
C._g_variant_builder_add_twoargs(builder, C.CString("{sv}"),
C.CString(C.OSTREE_COMMIT_META_KEY_COLLECTION_BINDING),
collection_id)
}
// Add previous metadata pairs
if unsafe.Pointer(metadata) != nil {
var iter C.GVariantIter
var key *C.gchar
var value *C.GVariant
C.g_variant_iter_init(&iter, metadata)
for C._g_variant_iter_next_twoargs(&iter, (*C.gchar)(C.CString("{sv}")), &key, &value) == C.TRUE {
C._g_variant_builder_add_twoargs(builder,
C.CString("{sv}"), (*C.char)(key), value)
}
C.g_variant_unref(metadata)
}
metadata = C.g_variant_builder_end(builder)
metadata = C.g_variant_ref_sink(metadata)
out:
return metadata
}
// Parse an array of key value pairs of the format KEY=VALUE and add them to a GVariant
func parseKeyValueStrings(pairs []string) (*C.GVariant, error) {
builder := C.g_variant_builder_new(C._g_variant_type(C.CString("a{sv}")))
......
......@@ -28,6 +28,7 @@ type RemoteOptions struct {
TlsCaPath string
UnconfiguredState string
MinFreeSpacePercent string
CollectionId string
}
func toDashString(in string) string {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment