Mark output from deleted files

This commit is contained in:
Peter J. Holzer 2022-03-19 00:22:41 +01:00 committed by Peter J. Holzer
parent 9ab32e5b6b
commit 2cd059908c
1 changed files with 3 additions and 1 deletions

View File

@ -64,6 +64,7 @@ def watch(args):
stf = os.stat(f.path) stf = os.stat(f.path)
if stf.st_ino != st.st_ino: if stf.st_ino != st.st_ino:
f.reopen() f.reopen()
st = os.stat(f.fileno)
except FileNotFoundError: except FileNotFoundError:
# ignore, # ignore,
# or maybe remove from watched_files? # or maybe remove from watched_files?
@ -74,13 +75,14 @@ def watch(args):
# We are beyond the end of the file, so it has probably # We are beyond the end of the file, so it has probably
# been truncated and rewritten - read from beginning # been truncated and rewritten - read from beginning
f.fd.seek(0, 0) f.fd.seek(0, 0)
dead = "✝" if st.st_nlink == 0 else " "
f.last_ts = st.st_mtime_ns f.last_ts = st.st_mtime_ns
new_content = f.fd.read() new_content = f.fd.read()
lines = new_content.split("\n") lines = new_content.split("\n")
if lines[-1] == "": if lines[-1] == "":
lines.pop() lines.pop()
for ln in lines: for ln in lines:
print(f"{f.path:{filename_length}}", format_ts(f.last_ts), ln) print(f"{f.path:{filename_length}}", format_ts(f.last_ts), dead, ln)
time.sleep(0.1) time.sleep(0.1)
seek_to_end = False seek_to_end = False