Fix bugs in bootleg stow, such as not copying symlinks and empty directory removal not working
This commit is contained in:
parent
2c4341e5e8
commit
03293faf89
25
bootleg-stow
25
bootleg-stow
@ -75,14 +75,13 @@ checkconflict() {
|
|||||||
error "Could not read directory: $1" 2
|
error "Could not read directory: $1" 2
|
||||||
fi
|
fi
|
||||||
# Get our list of files
|
# 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 directories="$(find "$1" -type d)"
|
||||||
local -a conflict
|
local -a conflict
|
||||||
# Iterate over them
|
# Iterate over them
|
||||||
for file in $files; do
|
for file in $files; do
|
||||||
# Get the basename of the file
|
# Get the basename of the file
|
||||||
filename="${file#"$1"/}"
|
filename="${file#"$1"/}"
|
||||||
log "$filename" 2
|
|
||||||
if [ -f ../"$filename" ]; then
|
if [ -f ../"$filename" ]; then
|
||||||
if [ -h ../"$filename" ]; then
|
if [ -h ../"$filename" ]; then
|
||||||
continue
|
continue
|
||||||
@ -106,7 +105,7 @@ stow() {
|
|||||||
# Note that you should checkconflict first
|
# Note that you should checkconflict first
|
||||||
[ -z "$1" ] && return 1
|
[ -z "$1" ] && return 1
|
||||||
stowdir="$(basename -- "$PWD")"
|
stowdir="$(basename -- "$PWD")"
|
||||||
log "Stow directory is: $stowdir" 2
|
log "Stowing package: $stowdir" 1
|
||||||
pushd .. > /dev/null 2>&1
|
pushd .. > /dev/null 2>&1
|
||||||
for dir in $_directories; do
|
for dir in $_directories; do
|
||||||
dirname="${dir#"$1"/}"
|
dirname="${dir#"$1"/}"
|
||||||
@ -126,30 +125,42 @@ stow() {
|
|||||||
else
|
else
|
||||||
path="$PWD/$stowdir/$1/$filename"
|
path="$PWD/$stowdir/$1/$filename"
|
||||||
fi
|
fi
|
||||||
log "Linking file: $filename to $path" 2
|
|
||||||
if [ -h "$filename" ]; then
|
if [ -h "$filename" ]; then
|
||||||
rm "$filename"
|
rm "$filename"
|
||||||
fi
|
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
|
done
|
||||||
|
echo "Done stowing package: $1" 1
|
||||||
popd > /dev/null 2>&1
|
popd > /dev/null 2>&1
|
||||||
}
|
}
|
||||||
unstow() {
|
unstow() {
|
||||||
# Unstow all of _files and _directories
|
# Unstow all of _files and _directories
|
||||||
|
# Takes a packagename as $1
|
||||||
|
[ -z "$1" ] && return 1
|
||||||
pushd .. > /dev/null 2>&1
|
pushd .. > /dev/null 2>&1
|
||||||
for file in $_files; do
|
for file in $_files; do
|
||||||
filename="${file#"$1"/}"
|
filename="${file#"$1"/}"
|
||||||
if [ -h "$filename" ]; then
|
if [ -h "$filename" ]; then
|
||||||
rm "$filename"
|
rm "$filename"
|
||||||
|
elif ! [ -e "$filename" ]; then
|
||||||
|
warn "File does not exist, skipping: $filename" 1
|
||||||
else
|
else
|
||||||
warn "File is not a symlink: $filename"
|
warn "File is not a symlink, skipping: $filename"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
_directories="$(echo "$_directories" | tac)"
|
_directories="$(echo "$_directories" | tac)"
|
||||||
|
log "Removing empty directories" 2
|
||||||
for dir in $_directories; do
|
for dir in $_directories; do
|
||||||
|
dirname="${dir#"$1"/}"
|
||||||
# We silently ignore errors here so that rmdiring a directory with stuff in
|
# We silently ignore errors here so that rmdiring a directory with stuff in
|
||||||
# it doesn't break our loop.
|
# it doesn't break our loop.
|
||||||
rmdir -p "$dir" > /dev/null 2>&1 || continue
|
rmdir -p "$dirname" > /dev/null 2>&1 || continue
|
||||||
done
|
done
|
||||||
popd > /dev/null 2>&1
|
popd > /dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user