From 0651e4f5e0e71b57d6564f2f2887ab98f13f1995 Mon Sep 17 00:00:00 2001 From: Mike Burns and Eric Collins Date: Fri, 27 Nov 2015 13:07:17 +0100 Subject: Fix relative exclude globs Pass the dotfiles subdir along with the file to `is_excluded` so that we can match against it. Preserve single-file compatibility by looping twice. --- bin/lsrc.in | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'bin/lsrc.in') diff --git a/bin/lsrc.in b/bin/lsrc.in index fcf5fbe..8fb1fcd 100755 --- a/bin/lsrc.in +++ b/bin/lsrc.in @@ -141,9 +141,9 @@ handle_file() { if [ ! -e "$file" ]; then $VERBOSE "skipping non-existent file $file" - elif is_excluded "$file" "$exclude_file_globs" "$include_file_globs"; then + elif is_excluded "$dotfiles_subdir/$file" "$exclude_file_globs" "$include_file_globs"; then $VERBOSE "skipping excluded file $file" - elif [ -d "$file" ] && is_excluded "$file" "$symlink_dirs_file_globs" "$mk_dirs_file_globs"; then + elif [ -d "$file" ] && is_excluded "$dotfiles_subdir/$file" "$symlink_dirs_file_globs" "$mk_dirs_file_globs"; then show_file "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted elif [ -d "$file" ]; then show_dir "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" "$mk_dirs_file_globs" @@ -188,6 +188,7 @@ is_excluded() { local file="$1" local exclude_file_globs="$2" local include_file_globs="$3" + local base_file="$(basename "$file")" $DEBUG "is_excluded $file $exclude_file_globs $include_file_globs" @@ -195,22 +196,42 @@ is_excluded() { $DEBUG "file: $file" $DEBUG "exclude_file_glob: $exclude_file_glob" - case "$file" in - $exclude_file_glob) - for include_file_glob in $include_file_globs; do - case "$file" in - $include_file_glob) return 1;; - esac - done - - return 0 - ;; - esac + is_single_excluded "$file" "$exclude_file_glob" "$include_file_globs" + ret=$? + if [ $ret -eq 0 -o $ret -eq 1 ]; then + return $ret + fi + + is_single_excluded "$base_file" "$exclude_file_glob" "$include_file_globs" + ret=$? + if [ $ret -eq 0 -o $ret -eq 1 ]; then + return $ret + fi done return 1 } +is_single_excluded() { + local file="$1" + local exclude_file_glob="$2" + local include_file_globs="$3" + + case "$file" in + $exclude_file_glob) + for include_file_glob in $include_file_globs; do + case "$file" in + $include_file_glob) return 1;; + esac + done + + return 0 + ;; + esac + + return 2 +} + show_help() { local exit_code=${1:-0} -- cgit v1.2.3