diff options
author | Harmen Stoppels <me@harmenstoppels.nl> | 2024-10-25 17:10:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-25 17:10:14 +0200 |
commit | e86a3b68f7413f0c4c5ec005e90df66a347c86f8 (patch) | |
tree | 787d6a569f422ac98446a99e6bcbb2544250951d /.github/workflows/coverage.yml | |
parent | 7319408bc7ee1c776d80942186eeb8bdd483b9f6 (diff) | |
download | spack-e86a3b68f7413f0c4c5ec005e90df66a347c86f8.tar.gz spack-e86a3b68f7413f0c4c5ec005e90df66a347c86f8.tar.bz2 spack-e86a3b68f7413f0c4c5ec005e90df66a347c86f8.tar.xz spack-e86a3b68f7413f0c4c5ec005e90df66a347c86f8.zip |
file_cache.py: allow read transaction on uninitialized cache (#47212)
This allows the following
```python
cache.init_entry("my/cache")
with cache.read_transaction("my/cache") as f:
data = f.read() if f is not None else None
```
mirroring `write_transaction`, which returns a tuple `(old, new)` where
`old` is `None` if the cache file did not exist yet.
The alternative that requires less defensive programming on the call
site would be to create the "old" file upon first read, but I did not
want to think about how to safely atomically create the file, and it's
not unthinkable that an empty file is an invalid format (for instance
the call site may expect a json file, which requires at least {} bytes).
Diffstat (limited to '.github/workflows/coverage.yml')
0 files changed, 0 insertions, 0 deletions