From 5d42d92598182347f9e934e72ae51a389b7c8869 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 25 May 2024 00:09:33 +0200 Subject: [PATCH] Tolerate some other file access problems --- kitsune | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/kitsune b/kitsune index 9e1359f..229d316 100755 --- a/kitsune +++ b/kitsune @@ -54,12 +54,18 @@ def watch(args): if st.st_mtime_ns > last_ts: last_ts = st.st_mtime_ns for de in os.scandir(d): - if de.is_file(): - if args.match_filename is None or fnmatch.fnmatch(de.name, args.match_filename): - if de.path not in watched_files: - watched_files[de.path] = WatchedFile(de.path, seek_to_end) - if len(de.path) > filename_length: - filename_length = len(de.path) + try: + if de.is_file(): + if args.match_filename is None or fnmatch.fnmatch(de.name, args.match_filename): + if de.path not in watched_files: + watched_files[de.path] = WatchedFile(de.path, seek_to_end) + if len(de.path) > filename_length: + filename_length = len(de.path) + except (PermissionError, OSError): + # ignore, + # or maybe remove from watched_files? + # or just mark as unavailable? + pass # has any of the files changed for f in watched_files.values(): @@ -71,7 +77,7 @@ def watch(args): if stf.st_ino != st.st_ino: f.reopen() st = os.stat(f.fileno) - except FileNotFoundError: + except (FileNotFoundError, PermissionError): # ignore, # or maybe remove from watched_files? # or just mark as deleted? @@ -94,7 +100,7 @@ def watch(args): stf = os.stat(f.path) if stf.st_ctime_ns != f.st_ctime_ns: f.reopen() - except FileNotFoundError: + except (FileNotFoundError, PermissionError): # ignore, # or maybe remove from watched_files? # or just mark as deleted?