mirror of
https://github.com/ostreedev/ostree.git
synced 2024-12-22 17:35:55 +03:00
contrib: indent golang code using only tabs instead of both tabs and spaces
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Closes: #242 Approved by: cgwalters
This commit is contained in:
parent
7763c452dd
commit
6a091c96ba
@ -47,50 +47,50 @@ func GoBool(b C.gboolean) bool {
|
||||
}
|
||||
|
||||
type GError struct {
|
||||
ptr unsafe.Pointer
|
||||
ptr unsafe.Pointer
|
||||
}
|
||||
|
||||
func NewGError() GError {
|
||||
return GError{nil}
|
||||
return GError{nil}
|
||||
}
|
||||
|
||||
func (e *GError) Native() *C.GError {
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
return (*C.GError)(e.ptr)
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
return (*C.GError)(e.ptr)
|
||||
}
|
||||
|
||||
func ConvertGError(e *C.GError) error {
|
||||
defer C.g_error_free(e)
|
||||
return errors.New(C.GoString((*C.char)(C._g_error_get_message(e))))
|
||||
defer C.g_error_free(e)
|
||||
return errors.New(C.GoString((*C.char)(C._g_error_get_message(e))))
|
||||
}
|
||||
|
||||
type GType uint
|
||||
|
||||
func (t GType) Name() string {
|
||||
return C.GoString((*C.char)(C.g_type_name(C.GType(t))))
|
||||
return C.GoString((*C.char)(C.g_type_name(C.GType(t))))
|
||||
}
|
||||
|
||||
|
||||
type GVariant struct {
|
||||
ptr unsafe.Pointer
|
||||
ptr unsafe.Pointer
|
||||
}
|
||||
|
||||
func GVariantNew(p unsafe.Pointer) *GVariant {
|
||||
o := &GVariant{p}
|
||||
runtime.SetFinalizer(o, (*GVariant).Unref)
|
||||
return o;
|
||||
o := &GVariant{p}
|
||||
runtime.SetFinalizer(o, (*GVariant).Unref)
|
||||
return o;
|
||||
}
|
||||
|
||||
func GVariantNewSink(p unsafe.Pointer) *GVariant {
|
||||
o := &GVariant{p}
|
||||
runtime.SetFinalizer(o, (*GVariant).Unref)
|
||||
o.RefSink()
|
||||
return o;
|
||||
o := &GVariant{p}
|
||||
runtime.SetFinalizer(o, (*GVariant).Unref)
|
||||
o.RefSink()
|
||||
return o;
|
||||
}
|
||||
|
||||
func (v *GVariant) native() *C.GVariant {
|
||||
return (*C.GVariant)(v.ptr);
|
||||
return (*C.GVariant)(v.ptr);
|
||||
}
|
||||
|
||||
func (v *GVariant) Ref() {
|
||||
@ -98,7 +98,7 @@ func (v *GVariant) Ref() {
|
||||
}
|
||||
|
||||
func (v *GVariant) Unref() {
|
||||
C.g_variant_unref(v.native())
|
||||
C.g_variant_unref(v.native())
|
||||
}
|
||||
|
||||
func (v *GVariant) RefSink() {
|
||||
@ -116,14 +116,14 @@ func (v *GVariant) GetChildValue(i int) *GVariant {
|
||||
}
|
||||
|
||||
func (v *GVariant) LookupString(key string) (string, error) {
|
||||
ckey := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(ckey))
|
||||
// TODO: Find a way to have constant C strings in golang
|
||||
cstr := C._g_variant_lookup_string(v.native(), ckey)
|
||||
if cstr == nil {
|
||||
return "", fmt.Errorf("No such key: %s", key)
|
||||
}
|
||||
return C.GoString(cstr), nil
|
||||
ckey := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(ckey))
|
||||
// TODO: Find a way to have constant C strings in golang
|
||||
cstr := C._g_variant_lookup_string(v.native(), ckey)
|
||||
if cstr == nil {
|
||||
return "", fmt.Errorf("No such key: %s", key)
|
||||
}
|
||||
return C.GoString(cstr), nil
|
||||
}
|
||||
|
||||
/*
|
||||
@ -144,9 +144,9 @@ type GObject struct {
|
||||
}
|
||||
|
||||
func GObjectNew(p unsafe.Pointer) *GObject {
|
||||
o := &GObject{p}
|
||||
runtime.SetFinalizer(o, (*GObject).Unref)
|
||||
return o;
|
||||
o := &GObject{p}
|
||||
runtime.SetFinalizer(o, (*GObject).Unref)
|
||||
return o;
|
||||
}
|
||||
|
||||
func (v *GObject) Ptr() unsafe.Pointer {
|
||||
@ -172,7 +172,7 @@ func (v *GObject) Ref() {
|
||||
}
|
||||
|
||||
func (v *GObject) Unref() {
|
||||
C.g_object_unref(C.gpointer(v.ptr))
|
||||
C.g_object_unref(C.gpointer(v.ptr))
|
||||
}
|
||||
|
||||
func (v *GObject) RefSink() {
|
||||
@ -191,7 +191,7 @@ func (v *GObject) ForceFloating() {
|
||||
// GIO types
|
||||
|
||||
type GCancellable struct {
|
||||
*GObject
|
||||
*GObject
|
||||
}
|
||||
|
||||
func (self *GCancellable) native() *C.GCancellable {
|
||||
|
@ -16,11 +16,11 @@ import (
|
||||
import "C"
|
||||
|
||||
type Repo struct {
|
||||
*GObject
|
||||
*GObject
|
||||
}
|
||||
|
||||
func RepoGetType() GType {
|
||||
return GType(C.ostree_repo_get_type())
|
||||
return GType(C.ostree_repo_get_type())
|
||||
}
|
||||
|
||||
func (r *Repo) native() *C.OstreeRepo {
|
||||
@ -28,67 +28,67 @@ func (r *Repo) native() *C.OstreeRepo {
|
||||
}
|
||||
|
||||
func repoFromNative(p *C.OstreeRepo) *Repo {
|
||||
if p == nil {
|
||||
return nil
|
||||
}
|
||||
o := GObjectNew(unsafe.Pointer(p))
|
||||
r := &Repo{o}
|
||||
return r
|
||||
if p == nil {
|
||||
return nil
|
||||
}
|
||||
o := GObjectNew(unsafe.Pointer(p))
|
||||
r := &Repo{o}
|
||||
return r
|
||||
}
|
||||
|
||||
func RepoNewOpen(path string) (*Repo, error) {
|
||||
var cerr *C.GError = nil
|
||||
cpath := C.CString(path)
|
||||
pathc := C.g_file_new_for_path(cpath);
|
||||
defer C.g_object_unref(C.gpointer(pathc))
|
||||
crepo := C.ostree_repo_new(pathc)
|
||||
repo := repoFromNative(crepo);
|
||||
r := GoBool(C.ostree_repo_open(repo.native(), nil, &cerr))
|
||||
if !r {
|
||||
return nil, ConvertGError(cerr)
|
||||
}
|
||||
return repo, nil
|
||||
var cerr *C.GError = nil
|
||||
cpath := C.CString(path)
|
||||
pathc := C.g_file_new_for_path(cpath);
|
||||
defer C.g_object_unref(C.gpointer(pathc))
|
||||
crepo := C.ostree_repo_new(pathc)
|
||||
repo := repoFromNative(crepo);
|
||||
r := GoBool(C.ostree_repo_open(repo.native(), nil, &cerr))
|
||||
if !r {
|
||||
return nil, ConvertGError(cerr)
|
||||
}
|
||||
return repo, nil
|
||||
}
|
||||
|
||||
func (r *Repo) GetParent() *Repo {
|
||||
return repoFromNative(C.ostree_repo_get_parent(r.native()))
|
||||
return repoFromNative(C.ostree_repo_get_parent(r.native()))
|
||||
}
|
||||
|
||||
type ObjectType int
|
||||
|
||||
const (
|
||||
OBJECT_TYPE_FILE ObjectType = C.OSTREE_OBJECT_TYPE_FILE
|
||||
OBJECT_TYPE_DIR_TREE = C.OSTREE_OBJECT_TYPE_DIR_TREE
|
||||
OBJECT_TYPE_DIR_META = C.OSTREE_OBJECT_TYPE_DIR_META
|
||||
OBJECT_TYPE_COMMIT = C.OSTREE_OBJECT_TYPE_COMMIT
|
||||
OBJECT_TYPE_TOMBSTONE_COMMIT = C.OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT
|
||||
OBJECT_TYPE_FILE ObjectType = C.OSTREE_OBJECT_TYPE_FILE
|
||||
OBJECT_TYPE_DIR_TREE = C.OSTREE_OBJECT_TYPE_DIR_TREE
|
||||
OBJECT_TYPE_DIR_META = C.OSTREE_OBJECT_TYPE_DIR_META
|
||||
OBJECT_TYPE_COMMIT = C.OSTREE_OBJECT_TYPE_COMMIT
|
||||
OBJECT_TYPE_TOMBSTONE_COMMIT = C.OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT
|
||||
)
|
||||
|
||||
func (repo *Repo) LoadVariant(t ObjectType, checksum string) (*GVariant, error) {
|
||||
var cerr *C.GError = nil
|
||||
var cvariant *C.GVariant = nil
|
||||
var cerr *C.GError = nil
|
||||
var cvariant *C.GVariant = nil
|
||||
|
||||
r := GoBool(C.ostree_repo_load_variant(repo.native(), C.OstreeObjectType(t), C.CString(checksum), &cvariant, &cerr))
|
||||
if !r {
|
||||
return nil, ConvertGError(cerr)
|
||||
}
|
||||
variant := GVariantNew(unsafe.Pointer(cvariant))
|
||||
return variant, nil
|
||||
r := GoBool(C.ostree_repo_load_variant(repo.native(), C.OstreeObjectType(t), C.CString(checksum), &cvariant, &cerr))
|
||||
if !r {
|
||||
return nil, ConvertGError(cerr)
|
||||
}
|
||||
variant := GVariantNew(unsafe.Pointer(cvariant))
|
||||
return variant, nil
|
||||
}
|
||||
|
||||
func (repo *Repo) ResolveRev(ref string) (string, error) {
|
||||
var cerr *C.GError = nil
|
||||
var crev *C.char = nil
|
||||
var cerr *C.GError = nil
|
||||
var crev *C.char = nil
|
||||
|
||||
r := GoBool(C.ostree_repo_resolve_rev(repo.native(), C.CString(ref), GBool(true), &crev, &cerr))
|
||||
if !r {
|
||||
return "", ConvertGError(cerr)
|
||||
}
|
||||
defer C.free(unsafe.Pointer(crev))
|
||||
return C.GoString(crev), nil
|
||||
r := GoBool(C.ostree_repo_resolve_rev(repo.native(), C.CString(ref), GBool(true), &crev, &cerr))
|
||||
if !r {
|
||||
return "", ConvertGError(cerr)
|
||||
}
|
||||
defer C.free(unsafe.Pointer(crev))
|
||||
return C.GoString(crev), nil
|
||||
}
|
||||
|
||||
func (commit *GVariant) CommitGetMetadataKeyString(key string) (string, error) {
|
||||
cmeta := GVariantNew(unsafe.Pointer(C.g_variant_get_child_value(commit.native(), 0)))
|
||||
return cmeta.LookupString(key)
|
||||
cmeta := GVariantNew(unsafe.Pointer(C.g_variant_get_child_value(commit.native(), 0)))
|
||||
return cmeta.LookupString(key)
|
||||
}
|
||||
|
@ -9,47 +9,47 @@ import (
|
||||
)
|
||||
|
||||
func TestTypeName(t *testing.T) {
|
||||
name := RepoGetType().Name();
|
||||
if name != "OstreeRepo" {
|
||||
t.Errorf("%s != OstreeRepo");
|
||||
}
|
||||
name := RepoGetType().Name();
|
||||
if name != "OstreeRepo" {
|
||||
t.Errorf("%s != OstreeRepo");
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoNew(t *testing.T) {
|
||||
r, err := RepoNewOpen("/ostree/repo")
|
||||
if err != nil {
|
||||
t.Errorf("%s", err);
|
||||
return
|
||||
}
|
||||
parent := r.GetParent()
|
||||
if parent != nil {
|
||||
t.Errorf("Expected no parent")
|
||||
return
|
||||
}
|
||||
r, err := RepoNewOpen("/ostree/repo")
|
||||
if err != nil {
|
||||
t.Errorf("%s", err);
|
||||
return
|
||||
}
|
||||
parent := r.GetParent()
|
||||
if parent != nil {
|
||||
t.Errorf("Expected no parent")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoGetMetadataVersion(t *testing.T) {
|
||||
r, err := RepoNewOpen("/ostree/repo")
|
||||
if err != nil {
|
||||
t.Errorf("%s", err);
|
||||
return
|
||||
}
|
||||
commit,err := r.ResolveRev("rhel-atomic-host/7/x86_64/standard")
|
||||
if err != nil {
|
||||
t.Errorf("%s", err)
|
||||
return
|
||||
}
|
||||
commitv,err := r.LoadVariant(OBJECT_TYPE_COMMIT, commit)
|
||||
if err != nil {
|
||||
t.Errorf("%s", err)
|
||||
return
|
||||
}
|
||||
ver, err := commitv.CommitGetMetadataKeyString("version")
|
||||
if err != nil {
|
||||
t.Errorf("%s", err)
|
||||
return
|
||||
}
|
||||
if ver != "7.1.3" {
|
||||
t.Errorf("expected 7.1.3")
|
||||
}
|
||||
r, err := RepoNewOpen("/ostree/repo")
|
||||
if err != nil {
|
||||
t.Errorf("%s", err);
|
||||
return
|
||||
}
|
||||
commit,err := r.ResolveRev("rhel-atomic-host/7/x86_64/standard")
|
||||
if err != nil {
|
||||
t.Errorf("%s", err)
|
||||
return
|
||||
}
|
||||
commitv,err := r.LoadVariant(OBJECT_TYPE_COMMIT, commit)
|
||||
if err != nil {
|
||||
t.Errorf("%s", err)
|
||||
return
|
||||
}
|
||||
ver, err := commitv.CommitGetMetadataKeyString("version")
|
||||
if err != nil {
|
||||
t.Errorf("%s", err)
|
||||
return
|
||||
}
|
||||
if ver != "7.1.3" {
|
||||
t.Errorf("expected 7.1.3")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user