Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Skip version cache on read-only filesystems #862

Merged
merged 1 commit into from
Dec 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions mriqc/cli/version.py
Original file line number Diff line number Diff line change
@@ -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:
@@ -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)))