Fix file list gathering

This commit is contained in:
Juno Takano 2024-06-26 10:47:20 -03:00
parent 211df99fc6
commit a08d5765d5
3 changed files with 32 additions and 6 deletions

18
check
View file

@ -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"

7
docs/check.md Normal file
View file

@ -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.

View file

@ -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.