fix(tools): h5rs diff compares soft links by target, like h5diff

An OBJ that was a soft link was resolved and its target object compared,
so two files whose /g/s both point at /z differed when /z did: exit 1,
where h5diff (without --follow-symlinks) compares the links' target paths
and exits 0.

A soft link is now compared as a link wherever it is, OBJ included.
--follow-symlinks compares the objects soft links lead to instead, walks
into soft-linked groups, resolves relative targets against the link's
group, and treats two dangling links as the same; exit codes equal
h5diff's on 14 cases. External links are never followed (documented).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
osobh
2026-09-26 01:18:13 -05:00
co-authored by Claude Opus 5.5
parent f325d111f3
commit b5e43bacd7
5 changed files with 155 additions and 17 deletions
+17
View File
@@ -132,6 +132,23 @@ for name, d in (("big1.h5", 0), ("big2.h5", 1)):
f["i"] = np.array([2**60 + d, -(2**62) - d], dtype="i8")
f["u"] = np.array([2**64 - 1 - d], dtype="u8")
# Soft links: the same link targets, whose target objects differ.
for name, v in (("soft1.h5", 0), ("soft2.h5", 1)):
with h5py.File(os.path.join(out, name), "w") as f:
f["z"] = np.arange(4) + v
f.create_group("g")["s"] = h5py.SoftLink("/z")
grp = f.create_group("grp")
grp["d"] = np.arange(3) + v
f["lnk"] = h5py.SoftLink("/grp")
f["dang"] = h5py.SoftLink("/nowhere")
# Soft links: different link targets, whose target objects are equal.
for name, t in (("target1.h5", "/a"), ("target2.h5", "/b")):
with h5py.File(os.path.join(out, name), "w") as f:
f["a"] = np.arange(4)
f["b"] = np.arange(4)
f["s"] = h5py.SoftLink(t)
f["rel"] = h5py.SoftLink("a")
with h5py.File(os.path.join(out, "userblock.h5"), "w", userblock_size=1024) as f:
f["d"] = np.arange(10)