Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a wrapper for C.H5Lexists for the CommonFG, returns nil if link e… #57

Merged
merged 6 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions h5g_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package hdf5
import "C"

import (
"errors"
"fmt"
"unsafe"
)
Expand Down Expand Up @@ -162,3 +163,15 @@ func (g *Group) CreateTableFrom(name string, dtype interface{}, chunkSize, compr
func (g *Group) OpenTable(name string) (*Table, error) {
return openTable(g.id, name)
}

// CheckLink checks if a link( can be group or dataset or actual link )exsit or not. This method won't give you annoying hdf5 warnings when called in a goroutine
// CheckLink returns nil when a link exist, return an error when the link doesn't exist or some other error occured
zyc-sudo marked this conversation as resolved.
Show resolved Hide resolved
func (g *CommonFG) CheckLink(name string) error {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
status := C.H5Lexists(g.id, c_name, 0)
if status > 0 {
return nil
}
return errors.New("The link " + name + " does not exist or some other error occured")
}
19 changes: 19 additions & 0 deletions h5g_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ func TestGroup(t *testing.T) {
defer os.Remove(fname)
defer f.Close()

err = f.CheckLink("/foo")
if err == nil {
t.Fatalf("err: %s", "/foo shouldn't exist at this time")
zyc-sudo marked this conversation as resolved.
Show resolved Hide resolved
}

g1, err := f.CreateGroup("foo")
if err != nil {
t.Fatalf("couldn't create group: %s", err)
Expand All @@ -28,6 +33,16 @@ func TestGroup(t *testing.T) {
t.Errorf("wrong Name for group: want %q, got %q", "/foo", g1.Name())
zyc-sudo marked this conversation as resolved.
Show resolved Hide resolved
}

err = f.CheckLink("/foo")
if err != nil {
t.Fatalf("err: %s", err)
zyc-sudo marked this conversation as resolved.
Show resolved Hide resolved
}

err = g1.CheckLink("bar")
if err == nil {
t.Fatalf("err: %s", "/foo shouldn't have bar as a child at this time")
}

g2, err := g1.CreateGroup("bar")
if err != nil {
t.Fatalf("couldn't create group: %s", err)
Expand All @@ -38,6 +53,10 @@ func TestGroup(t *testing.T) {
if g2.Name() != "/foo/bar" {
t.Errorf("wrong Name for group: want %q, got %q", "/foo/bar", g1.Name())
}
err = g1.CheckLink("bar")
if err != nil {
t.Fatalf("err: %s", err)
zyc-sudo marked this conversation as resolved.
Show resolved Hide resolved
}

g3, err := g2.CreateGroup("baz")
if err != nil {
Expand Down