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 all 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
}
17 changes: 16 additions & 1 deletion 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.Error("unexpected /foo link present")
}

g1, err := f.CreateGroup("foo")
if err != nil {
t.Fatalf("couldn't create group: %s", err)
Expand All @@ -25,7 +29,15 @@ func TestGroup(t *testing.T) {
t.Fatal("wrong file for group")
}
if g1.Name() != "/foo" {
t.Errorf("wrong Name for group: want %q, got %q", "/foo", g1.Name())
t.Errorf(`wrong name for group: want:"/foo", got:%q`, g1.Name())
}

if !f.LinkExists("/foo") {
t.Error(`unexpected "/foo" group link not present`)
}

if g1.LinkExists("bar") {
t.Error(`unexpected "bar" child link for "/foo" group`)
}

g2, err := g1.CreateGroup("bar")
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.Error(`expected "bar" child link for "/foo" group not present`)
}

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