From 51b596422443dd740aa8c7c96036f16e5f2f44fe Mon Sep 17 00:00:00 2001 From: Christian Zangl Date: Wed, 10 Jan 2024 20:28:24 +0100 Subject: [PATCH] misc improvements --- README.md | 6 ++++-- chkbit/context.py | 8 ++++++++ chkbit/index_thread.py | 4 ++++ chkbit_cli/main.py | 7 +++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8e63220..c9c86f6 100644 --- a/README.md +++ b/README.md @@ -91,8 +91,8 @@ options: -l FILE, --log-file FILE write to a logfile if specified --log-verbose verbose logging - --index-name NAME filename where chkbit stores its hashes (default: .chkbit) - --ignore-name NAME filename that chkbit reads its ignore list from (default: .chkbitignore) + --index-name NAME filename where chkbit stores its hashes, needs to start with '.' (default: .chkbit) + --ignore-name NAME filename that chkbit reads its ignore list from, needs to start with '.' (default: .chkbitignore) -w N, --workers N number of workers to use (default: 5) --plain show plain status instead of being fancy -q, --quiet quiet, don't show progress/information @@ -140,6 +140,8 @@ Add a `.chkbitignore` file containing the names of the files/directories you wis - `[!seq]` matches any character not in seq - lines starting with `#` are skipped - lines starting with `/` are only applied to the current directory +- you can use `path/sub/name` to ignore a file/directory in a sub path +- hidden files (starting with a `.`) are ignored by default ## FAQ diff --git a/chkbit/context.py b/chkbit/context.py index 71e8be8..f325b85 100644 --- a/chkbit/context.py +++ b/chkbit/context.py @@ -27,6 +27,11 @@ class Context: self.index_filename = index_filename self.ignore_filename = ignore_filename + if not index_filename.startswith("."): + raise Exception("The index filename must start with a dot!") + if not ignore_filename.startswith("."): + raise Exception("The ignore filename must start with a dot!") + # the input queue is used to distribute the work # to the index threads self.input_queue = queue.Queue() @@ -48,3 +53,6 @@ class Context: def end_input(self): self.input_queue.put(None) + + def is_chkbit_file(self, name): + return name in [self.index_filename, self.ignore_filename] diff --git a/chkbit/index_thread.py b/chkbit/index_thread.py index 684af93..20266ef 100644 --- a/chkbit/index_thread.py +++ b/chkbit/index_thread.py @@ -25,6 +25,10 @@ class IndexThread: for name in os.listdir(path=iitem.path): path = os.path.join(iitem.path, name) if name[0] == ".": + if self.context.show_ignored_only and not self.context.is_chkbit_file( + name + ): + self.context.log(Status.IGNORE, path) continue if os.path.isdir(path): if self.context.skip_symlinks and os.path.islink(path): diff --git a/chkbit_cli/main.py b/chkbit_cli/main.py index 8720e07..ff2fbd3 100644 --- a/chkbit_cli/main.py +++ b/chkbit_cli/main.py @@ -302,14 +302,14 @@ class Main: metavar="NAME", type=str, default=".chkbit", - help="filename where chkbit stores its hashes (default: .chkbit)", + help="filename where chkbit stores its hashes, needs to start with '.' (default: .chkbit)", ) parser.add_argument( "--ignore-name", metavar="NAME", type=str, default=".chkbitignore", - help="filename that chkbit reads its ignore list from (default: .chkbitignore)", + help="filename that chkbit reads its ignore list from, needs to start with '.' (default: .chkbitignore)", ) parser.add_argument( @@ -376,6 +376,9 @@ def main(): except KeyboardInterrupt: print("abort") sys.exit(1) + except Exception as e: + print(e, file=sys.stderr) + sys.exit(1) if __name__ == "__main__":