Skip to content

Commit

Permalink
On cleanup do not complain if file is missing
Browse files Browse the repository at this point in the history
If a formatter fails early there might not be a file to cleanup.
Currently the callback can not distinguish between a failure
that happens before the file was written and a failure that
happens after the file was written.
  • Loading branch information
timj committed Dec 10, 2019
1 parent d165907 commit dd07c55
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion python/lsst/daf/butler/datastores/posixDatastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,20 @@ def put(self, inMemoryDataset, ref):
raise FileExistsError(f"Cannot write file for ref {ref} as "
f"output file {predictedFullPath} already exists")

def _removeFileExists(path):
"""Remove a file and do not complain if it is not there.
This is important since a formatter might fail before the file
is written and we should not confuse people by writing spurious
error messages to the log.
"""
try:
os.remove(path)
except FileNotFoundError:
pass

formatter_exception = None
with self._transaction.undoWith("write", os.remove, predictedFullPath):
with self._transaction.undoWith("write", _removeFileExists, predictedFullPath):
try:
path = formatter.write(inMemoryDataset)
log.debug("Wrote file to %s", path)
Expand Down

0 comments on commit dd07c55

Please sign in to comment.