From 03293faf899b0833ace448c042a22d5782189554 Mon Sep 17 00:00:00 2001 From: Salt Date: Thu, 28 Jan 2021 23:45:17 -0600 Subject: [PATCH] Fix bugs in bootleg stow, such as not copying symlinks and empty directory removal not working --- bootleg-stow | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/bootleg-stow b/bootleg-stow index 081517dc..87341913 100755 --- a/bootleg-stow +++ b/bootleg-stow @@ -75,14 +75,13 @@ checkconflict() { error "Could not read directory: $1" 2 fi # Get our list of files - local files="$(find "$1" -type f)" + local files="$(find "$1" -type f -o -type l)" local directories="$(find "$1" -type d)" local -a conflict # Iterate over them for file in $files; do # Get the basename of the file filename="${file#"$1"/}" - log "$filename" 2 if [ -f ../"$filename" ]; then if [ -h ../"$filename" ]; then continue @@ -106,7 +105,7 @@ stow() { # Note that you should checkconflict first [ -z "$1" ] && return 1 stowdir="$(basename -- "$PWD")" - log "Stow directory is: $stowdir" 2 + log "Stowing package: $stowdir" 1 pushd .. > /dev/null 2>&1 for dir in $_directories; do dirname="${dir#"$1"/}" @@ -126,30 +125,42 @@ stow() { else path="$PWD/$stowdir/$1/$filename" fi - log "Linking file: $filename to $path" 2 if [ -h "$filename" ]; then rm "$filename" fi - ln -s "$path" "$filename" + if [ -h "$PWD/$stowdir/$1/$filename" ]; then + log "Copying symlink: $filename" 2 + cp -d "$PWD/$stowdir/$1/$filename" "$filename" + else + log "Linking file: $filename to $path" 2 + ln -s "$path" "$filename" + fi done + echo "Done stowing package: $1" 1 popd > /dev/null 2>&1 } unstow() { # Unstow all of _files and _directories + # Takes a packagename as $1 + [ -z "$1" ] && return 1 pushd .. > /dev/null 2>&1 for file in $_files; do filename="${file#"$1"/}" if [ -h "$filename" ]; then rm "$filename" + elif ! [ -e "$filename" ]; then + warn "File does not exist, skipping: $filename" 1 else - warn "File is not a symlink: $filename" + warn "File is not a symlink, skipping: $filename" fi done _directories="$(echo "$_directories" | tac)" + log "Removing empty directories" 2 for dir in $_directories; do + dirname="${dir#"$1"/}" # We silently ignore errors here so that rmdiring a directory with stuff in # it doesn't break our loop. - rmdir -p "$dir" > /dev/null 2>&1 || continue + rmdir -p "$dirname" > /dev/null 2>&1 || continue done popd > /dev/null 2>&1 }