ismrmrd / ismrmrd-python

Python API for the ISMRMRD file format
Other
51 stars 27 forks source link

Opening and closing MRD file via File interface updates file modified time #78

Open gabuzi opened 3 months ago

gabuzi commented 3 months ago

Hi,

I noticed some strange behavior:

Just opening and closing again an MRD file via ismrmrd.File() as below updates the file modified timestamp.

import ismrmrd

with ismrmrd.File("mymrd.h5"):
    pass

After this, the mymrd.h5 file shows the current time as the time modified, which is surprising. The sha256 checksum indicates no change in the file.

Opening and closing with ismrmrd.File(..., "r") does not show this behavior, which is reassuring.

I would expect the file modification timestamp to remain unchanged if the file is not modified.

Currently, this throws some of our tools off that take action based on updated files that it determines from modification timestamps. It's not a critical issue as there is the workaround with the "r" flag, however it may be a cause for concern if readonly operations start changing file modification timestamps, especially on raw data that one would like to keep for archival purposes.

I spotted this behavior on Windows with python 3.10 and ismrmrd 1.14.1 installed via pip. Due to a peculiarity in our setup, python will run as admin, which may or may not be relevant to this issue.

gabuzi commented 3 months ago

Additional context: Python's builtin file access behavior (e.g. with open("somefile"): ... does not touch files at all and defaults to the "r" mode, and I think it would make sense to match this behavior.