From a08d5765d5446ca59607c3e076c07e4123fd7a2e Mon Sep 17 00:00:00 2001 From: jutty Date: Wed, 26 Jun 2024 10:47:20 -0300 Subject: [PATCH] Fix file list gathering --- check | 18 ++++++++++++------ docs/check.md | 7 +++++++ docs/portability.md | 13 +++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 docs/check.md diff --git a/check b/check index 6320289..fb7a3fe 100755 --- a/check +++ b/check @@ -3,25 +3,31 @@ # user-configured settings TORI_ROOT="$HOME/.config/tori" +# global state +files= + # application logic log() { local level="$1" # unimplemented local message="$2" - echo "$message" + if [ -n "$DEBUG" ] && [ $level = debug ]; then + printf "$(date "+%H:%M:%N") $message\n" + fi } traverse() { local target="$1" - log debug "target: $target" - if [ -f "$target" ]; then - echo "file: $target" - elif [ -d "$target" ]; then - traverse $target/* + log debug "traversing $target" + if [ -d "$target" ]; then + log debug "found dir: $target" + files="$(find "$target" -type f)\n$files" fi + + log debug "collected files:\n$files" } cd "$TORI_ROOT" diff --git a/docs/check.md b/docs/check.md new file mode 100644 index 0000000..793d96f --- /dev/null +++ b/docs/check.md @@ -0,0 +1,7 @@ +The `check` executable traverses the configuration directory to assemble a file list containing full paths for both the `base` and `bkp` directories. + +This is currently accomplished by resorting to `find`. While this allows for cleaner code, it relies on an external program with an interface that may be unpredictable. + +A better option might be using a POSIX-compliant wildcard such as `.[!.]* ..?* *` to match the files directly (e.g., in a for loop). + +Another option that may provide both readability and portability is repeating the match, once for hidden file and once for non-hidden files. diff --git a/docs/portability.md b/docs/portability.md index 28c5549..23c7e2a 100644 --- a/docs/portability.md +++ b/docs/portability.md @@ -1,3 +1,16 @@ tori is designed to be portable so that its features allow transfering your configuration between different versions of an operating system or even between different operating systems depending on the presently supported ones. To aid this portability and ability to run in different systems, it is also designed to have minimal dependencies since it is meant to run on brand new systems where very few packages have been installed. + +Despite this, some assumptions are still made about what your system supports: + +- shell + - `local` keyword + +- executables + - `find` + - `date` with nanoseconds as `%N` + - `env` at `/usr/bin/env` + - While this may be an issue from a portability standpoint, hardcoding the path where `sh` is also poses another portability issue. A more robust way to find it would be desirable. + +tori is implemented as a set of shell scripts. These are currently only tested on the `sh` Almquist shell as shipped by FreeBSD and the `dash` Almquist shell as shipped by Void Linux.