From 0d03733b4f042324ca32ef520f039a25bffa59d7 Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Fri, 11 Oct 2024 11:09:32 +0200 Subject: [PATCH] ignoe FileNotFound Error that sometimes happens when getting mtime of directories Fixes: #231 --- CHANGELOG.md | 2 ++ blag/devserver.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45cc279..a2295bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [unreleased] -- +* Ignore FileNotFoundError when trying to get the last modified time of files + in directories. This happens for example with temporary emacs files. * Added changelog to docs * removed ruff's target-version from pyproject.toml, this value defaults to the projects requires-python diff --git a/blag/devserver.py b/blag/devserver.py index 1945740..2dd6481 100644 --- a/blag/devserver.py +++ b/blag/devserver.py @@ -42,7 +42,12 @@ def get_last_modified(dirs: list[str]) -> float: for dir in dirs: for root, dirs, files in os.walk(dir): for f in files: - mtime = os.stat(os.path.join(root, f)).st_mtime + try: + mtime = os.stat(os.path.join(root, f)).st_mtime + except FileNotFoundError: + # ignore files that have been deleted since the os.walk + # call (for example temporary emacs files) + continue if mtime > last_mtime: last_mtime = mtime