]>
Commit | Line | Data |
---|---|---|
879c383c SW |
1 | import os |
2 | import subprocess | |
3 | import time | |
4 | ||
5 | ||
6 | BLOCK_SIZE = 4096 | |
7 | MIN_AGE = time.time() - 86400 * 7 | |
8 | ||
9 | ||
10 | def removesuffix(s, suf): # Until python 3.9 | |
11 | return s[:len(s) - len(suf)] if s.endswith(suf) else s | |
12 | ||
13 | ||
14 | def truncated(log): | |
15 | return subprocess.run(['bunzip2', '--test', log], stderr=subprocess.DEVNULL).returncode == 2 | |
16 | ||
17 | ||
18 | def main(): | |
19 | for d, _, files in os.walk(os.environ.get('NIX_LOG_DIR', '/nix/var/log/nix')): | |
20 | for f in files: | |
21 | path = os.path.join(d, f) | |
22 | st = os.stat(path) | |
23 | if (st.st_size % BLOCK_SIZE) == 0 and st.st_mtime > MIN_AGE and truncated(path): | |
24 | print(d[-2:] + removesuffix(f, '.bz2')) | |
25 | ||
26 | ||
27 | if __name__ == '__main__': | |
28 | main() |