kiss: add support for directories and absolute file paths as sources

This adds support for both absolute and relative directories in
sources files. Relative file sources have always been supported,
this just extends it to directories.

Absolute paths to directories and files in sources is totally new.

Directories will have their /contents/ copied to the initial build
directory. The second field in the sources file can be used to set
destination location.

Checksums will not be validated for directories of any type. Absolute
file paths do have their checksums validated.

Notes:

The package manager will check to see if the source is a directory
or not. There is no need to have a trailing forward slash (though it
might make sense to enforce this anyway, we'll see).
This commit is contained in:
Dylan Araps 2020-08-13 01:07:41 +03:00
parent fecf4995f8
commit 99f61fc340
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

56
kiss
View File

@ -221,9 +221,13 @@ pkg_sources() {
die "$1" "Failed to download $src"
}
# Local source.
elif [ -f "$repo_dir/$src" ]; then
log "$1" "Found local file '$src'"
# Local source (relative).
elif [ -e "$repo_dir/$src" ]; then
log "$1" "Found local relative source '$src'"
# Local source (absolute).
elif [ -e "/$src" ]; then
log "$1" "Found local absolute source '$src'"
else
die "$1" "No local file '$src'"
@ -319,10 +323,22 @@ pkg_extract() {
;;
*)
# Local file.
if [ -f "$repo_dir/$src" ]; then
# Local directory (relative).
if [ -d "$repo_dir/$src" ]; then
cp -Rf "$repo_dir/$src/." .
# Local directory (absolute).
elif [ -d "/$src" ]; then
cp -Rf "/$src/." .
# Local file (relative).
elif [ -f "$repo_dir/$src" ]; then
cp -f "$repo_dir/$src" .
# Local file (absolute).
elif [ -f "/$src" ]; then
cp -f "/$src" .
# Remote file.
elif [ -f "$src_dir/$1/${src##*/}" ]; then
cp -f "$src_dir/$1/${src##*/}" .
@ -699,12 +715,30 @@ pkg_checksums() {
[ -f "$repo_dir/sources" ] || return 0
while read -r src _ || [ "$src" ]; do
case $src in
\#*|"") ;;
git+*) printf '%s\n' "$src" ;;
*://*) sh256 "$src_dir/$1/${src##*/}" ;;
*) sh256 "$repo_dir/$src" ;;
esac
# Skip comments and blank lines.
if [ -z "${src##\#*}" ]; then
:
# Git source.
elif [ -z "${src##git+*}" ]; then
printf '%s\n' "$src" # This should probably be ':'.
# Remote source.
elif [ -z "${src##*://*}" ]; then
sh256 "$src_dir/$1/${src##*/}"
# Skip directories.
elif [ -d "$repo_dir/$src" ] || [ -d "/$src" ]; then
:
# Local file (relative).
elif [ -f "$repo_dir/$src" ]; then
sh256 "$repo_dir/$src"
# Local file (absolute).
elif [ -f "/$src" ]; then
sh256 "/$src"
fi
done < "$repo_dir/sources" || die "$1" "Failed to generate checksums"
}