Skip to content

Commit

Permalink
Get stat from file descriptor if possible, in case the file has been …
Browse files Browse the repository at this point in the history
…replaced
  • Loading branch information
takluyver committed Oct 18, 2019
1 parent 89020d8 commit acc4a26
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion karabo_data/run_files_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,19 @@ def save(self, files):
log.debug("Will save cached data for %s", fname)
need_save = True

st = os.stat(file_access.filename)
# It's possible that the file we opened has been replaced by a
# new one before this runs. If possible, get the stat from the
# file descriptor, which will always be accurate. Stat-ing the
# filename will almost always work as a fallback.
try:
fd = file_access.file.id.get_vfd_handle()
except Exception:
log.warning("Can't get fd for %r, will stat name instead",
fname, exc_info=True)
st = os.stat(file_access.filename)
else:
st = os.stat(fd)

self.files_data[fname] = {
'filename': fname,
'mtime': st.st_mtime,
Expand Down

0 comments on commit acc4a26

Please sign in to comment.