Skip to content

Commit

Permalink
FIX: Skip version cache on read-only filesystems
Browse files Browse the repository at this point in the history
Fixes #853.

Following nipreps/fmriprep#1830.
  • Loading branch information
effigies committed Dec 15, 2020
1 parent ec32c22 commit a72f03e
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions mriqc/cli/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@ def check_latest():
date = None
outdated = None
cachefile = Path.home() / ".cache" / "mriqc" / "latest"
cachefile.parent.mkdir(parents=True, exist_ok=True)

try:
latest, date = cachefile.read_text().split("|")
except Exception:
pass
else:
cachefile.parent.mkdir(parents=True, exist_ok=True)
except OSError:
cachefile = None

if cachefile and cachefile.exists():
try:
latest = Version(latest)
date = datetime.strptime(date, DATE_FMT)
except (InvalidVersion, ValueError):
latest = None
latest, date = cachefile.read_text().split("|")
except Exception:
pass
else:
if abs((datetime.now() - date).days) > RELEASE_EXPIRY_DAYS:
outdated = True
try:
latest = Version(latest)
date = datetime.strptime(date, DATE_FMT)
except (InvalidVersion, ValueError):
latest = None
else:
if abs((datetime.now() - date).days) > RELEASE_EXPIRY_DAYS:
outdated = True

if latest is None or outdated is True:
try:
Expand All @@ -49,7 +53,7 @@ def check_latest():
else:
latest = None

if latest is not None:
if cachefile is not None and latest is not None:
try:
cachefile.write_text(
"|".join(("%s" % latest, datetime.now().strftime(DATE_FMT)))
Expand Down

0 comments on commit a72f03e

Please sign in to comment.