Skip to content

Commit

Permalink
Merge pull request #319 from glotzerlab/fix-pending-index-entries
Browse files Browse the repository at this point in the history
Maintain all pending index entries.
  • Loading branch information
joaander authored Jan 22, 2024
2 parents 44e5545 + a32874b commit 8eaec02
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Change Log

*Fixed:*

* Write all pending index entries to the file when `gsd_flush()` is called after `gsd_write_chunk()`
and before `gsd_end_frame()` (`#319 <https://github.com/glotzerlab/gsd/pull/319>`__).
* Readthedocs builds with pandas 2.2.0
(`#322 <https://github.com/glotzerlab/gsd/pull/322>`__).

Expand Down
2 changes: 1 addition & 1 deletion gsd/gsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ int gsd_flush(struct gsd_handle* handle)
{
handle->frame_index.data[i]
= handle->frame_index
.data[handle->frame_index.size - handle->pending_index_entries];
.data[handle->frame_index.size - handle->pending_index_entries + i];
}
}

Expand Down
26 changes: 26 additions & 0 deletions gsd/test/test_fl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,3 +1146,29 @@ def test_file_exists_error():
schema_version=[1, 2],
):
pass


def test_pending_index_entries(tmp_path):
"""Ensure that gsd preserves pending index entries."""
with gsd.fl.open(
tmp_path / 'test_pending_index_entries.gsd',
'w',
application='My application',
schema='My Schema',
schema_version=[1, 0],
) as f:
# Frame 0 must be complete to trigger the bug.
f.write_chunk(name='0', data=numpy.array([0]))
f.end_frame()

for i in range(16):
f.write_chunk(name=str(i), data=numpy.array([i]))

# Flush with pending chunks in the frame index.
f.flush()

f.end_frame()

# All test chunks should be present in the file.
for i in range(16):
assert f.chunk_exists(name=str(i), frame=1)

0 comments on commit 8eaec02

Please sign in to comment.