Fallback to using ls
if /bin/ls
does not exist (#22)
This commit is contained in:
parent
ce0acf1505
commit
60eb4c415f
2 changed files with 80 additions and 3 deletions
66
test/003_ls_program.bats
Normal file
66
test/003_ls_program.bats
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
load common
|
||||||
|
load_fixtures
|
||||||
|
|
||||||
|
@test "Default /bin/ls" {
|
||||||
|
echo "
|
||||||
|
By default, the value of LS_PROGRAM should be /bin/ls
|
||||||
|
"
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
YADM_TEST=1 source "$T_YADM"
|
||||||
|
status=0
|
||||||
|
output=$( require_ls; echo "$LS_PROGRAM" ) || {
|
||||||
|
status=$?
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "output=$output"
|
||||||
|
|
||||||
|
[ "$status" == 0 ]
|
||||||
|
[ "$output" = "/bin/ls" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Fallback on 'ls'" {
|
||||||
|
echo "
|
||||||
|
When LS_PROGRAM doesn't exist, use 'ls'
|
||||||
|
"
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
YADM_TEST=1 source "$T_YADM"
|
||||||
|
status=0
|
||||||
|
LS_PROGRAM="/ls/missing"
|
||||||
|
output=$( require_ls; echo "$LS_PROGRAM" ) || {
|
||||||
|
status=$?
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "output=$output"
|
||||||
|
|
||||||
|
[ "$status" == 0 ]
|
||||||
|
[ "$output" = "ls" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Fail if ls isn't in PATH" {
|
||||||
|
echo "
|
||||||
|
When LS_PROGRAM doesn't exist, use 'ls'
|
||||||
|
"
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
YADM_TEST=1 source "$T_YADM"
|
||||||
|
status=0
|
||||||
|
LS_PROGRAM="/ls/missing"
|
||||||
|
savepath="$PATH"
|
||||||
|
# shellcheck disable=SC2123
|
||||||
|
PATH=
|
||||||
|
output=$( require_ls 2>&1; echo "$LS_PROGRAM" ) || {
|
||||||
|
status=$?
|
||||||
|
true
|
||||||
|
}
|
||||||
|
PATH="$savepath"
|
||||||
|
|
||||||
|
echo "output=$output"
|
||||||
|
|
||||||
|
[ "$status" != 0 ]
|
||||||
|
[[ "$output" =~ functionality\ requires\ .ls.\ to\ be\ installed ]]
|
||||||
|
}
|
||||||
|
|
17
yadm
17
yadm
|
@ -30,6 +30,7 @@ YADM_ENCRYPT="encrypt"
|
||||||
YADM_ARCHIVE="files.gpg"
|
YADM_ARCHIVE="files.gpg"
|
||||||
|
|
||||||
GPG_PROGRAM="gpg"
|
GPG_PROGRAM="gpg"
|
||||||
|
LS_PROGRAM="/bin/ls"
|
||||||
|
|
||||||
#; flag when something may have changes (which prompts auto actions to be performed)
|
#; flag when something may have changes (which prompts auto actions to be performed)
|
||||||
CHANGES_POSSIBLE=0
|
CHANGES_POSSIBLE=0
|
||||||
|
@ -231,6 +232,7 @@ function encrypt() {
|
||||||
|
|
||||||
require_gpg
|
require_gpg
|
||||||
require_encrypt
|
require_encrypt
|
||||||
|
require_ls
|
||||||
|
|
||||||
#; process relative to YADM_WORK
|
#; process relative to YADM_WORK
|
||||||
YADM_WORK=$(git config core.worktree)
|
YADM_WORK=$(git config core.worktree)
|
||||||
|
@ -253,13 +255,13 @@ function encrypt() {
|
||||||
GLOBS=()
|
GLOBS=()
|
||||||
while IFS='' read -r glob || [ -n "$glob" ]; do
|
while IFS='' read -r glob || [ -n "$glob" ]; do
|
||||||
if [[ ! $glob =~ ^# ]] ; then
|
if [[ ! $glob =~ ^# ]] ; then
|
||||||
GLOBS=("${GLOBS[@]}" $(eval /bin/ls "$glob" 2>/dev/null))
|
GLOBS=("${GLOBS[@]}" $(eval "$LS_PROGRAM" "$glob" 2>/dev/null))
|
||||||
fi
|
fi
|
||||||
done < "$YADM_ENCRYPT"
|
done < "$YADM_ENCRYPT"
|
||||||
|
|
||||||
#; report which files will be encrypted
|
#; report which files will be encrypted
|
||||||
echo "Encrypting the following files:"
|
echo "Encrypting the following files:"
|
||||||
ls -1 "${GLOBS[@]}"
|
"$LS_PROGRAM" -1 "${GLOBS[@]}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
#; encrypt all files which match the globs
|
#; encrypt all files which match the globs
|
||||||
|
@ -378,6 +380,8 @@ function list() {
|
||||||
|
|
||||||
function perms() {
|
function perms() {
|
||||||
|
|
||||||
|
require_ls
|
||||||
|
|
||||||
#; TODO: prevent repeats in the files changed
|
#; TODO: prevent repeats in the files changed
|
||||||
|
|
||||||
#; process relative to YADM_WORK
|
#; process relative to YADM_WORK
|
||||||
|
@ -406,7 +410,7 @@ function perms() {
|
||||||
if [ -f "$YADM_ENCRYPT" ] ; then
|
if [ -f "$YADM_ENCRYPT" ] ; then
|
||||||
while IFS='' read -r glob || [ -n "$glob" ]; do
|
while IFS='' read -r glob || [ -n "$glob" ]; do
|
||||||
if [[ ! $glob =~ ^# ]] ; then
|
if [[ ! $glob =~ ^# ]] ; then
|
||||||
GLOBS=("${GLOBS[@]}" $(eval /bin/ls "$glob" 2>/dev/null))
|
GLOBS=("${GLOBS[@]}" $(eval "$LS_PROGRAM" "$glob" 2>/dev/null))
|
||||||
fi
|
fi
|
||||||
done < "$YADM_ENCRYPT"
|
done < "$YADM_ENCRYPT"
|
||||||
fi
|
fi
|
||||||
|
@ -592,6 +596,13 @@ function require_gpg() {
|
||||||
function require_repo() {
|
function require_repo() {
|
||||||
[ -d "$YADM_REPO" ] || error_out "Git repo does not exist. did you forget to run 'init' or 'clone'?"
|
[ -d "$YADM_REPO" ] || error_out "Git repo does not exist. did you forget to run 'init' or 'clone'?"
|
||||||
}
|
}
|
||||||
|
function require_ls() {
|
||||||
|
if [ ! -f "$LS_PROGRAM" ] ; then
|
||||||
|
command -v ls >/dev/null 2>&1 || \
|
||||||
|
error_out "This functionality requires 'ls' to be installed at '$LS_PROGRAM' or listed in your \$PATH"
|
||||||
|
LS_PROGRAM=ls
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
#; ****** Main processing (when not unit testing) ******
|
#; ****** Main processing (when not unit testing) ******
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue