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 2 commits
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
7 changes: 7 additions & 0 deletions h5g_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,10 @@ func (g *Group) CreateTableFrom(name string, dtype interface{}, chunkSize, compr
func (g *Group) OpenTable(name string) (*Table, error) {
return openTable(g.id, name)
}

// LinkExists returns whether a link with the specified name exists in the group.
func (g *CommonFG) LinkExists(name string) bool {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
return C.H5Lexists(g.id, c_name, 0) > 0
}
15 changes: 15 additions & 0 deletions h5g_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func TestGroup(t *testing.T) {
defer os.Remove(fname)
defer f.Close()

if f.LinkExists("/foo") {
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 +32,14 @@ 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
}

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

if g1.LinkExists("bar") {
t.Fatalf("err: %s", "/foo shouldn't have bar as a child bar at this time")
zyc-sudo marked this conversation as resolved.
Show resolved Hide resolved
}

g2, err := g1.CreateGroup("bar")
if err != nil {
t.Fatalf("couldn't create group: %s", err)
Expand All @@ -38,6 +50,9 @@ func TestGroup(t *testing.T) {
if g2.Name() != "/foo/bar" {
t.Errorf("wrong Name for group: want %q, got %q", "/foo/bar", g1.Name())
}
if !g1.LinkExists("bar") {
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