forked from spack/spack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
file_cache.py: allow read transaction on uninitialized cache (spack#4…
…7212) 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).
- Loading branch information
Showing
2 changed files
with
58 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters