aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xconfigure2
-rw-r--r--spec/01_lib_spec.sh2
-rw-r--r--spec/02_src_spec.sh2
-rw-r--r--src/cpt-lib.in105
-rw-r--r--www/index.md2
5 files changed, 73 insertions, 40 deletions
diff --git a/configure b/configure
index 2411f90..e338b8f 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#!/bin/sh -e
-version=6.2.0
+version=Fossil
die() {
printf '%s: %s\n' "${0##*/}" "$*" >&2
diff --git a/spec/01_lib_spec.sh b/spec/01_lib_spec.sh
index b56ac32..29bd05a 100644
--- a/spec/01_lib_spec.sh
+++ b/spec/01_lib_spec.sh
@@ -162,7 +162,7 @@ Describe 'CPT Library'
End
It "doesn't log 'running hook' if no package is given"
When call run_hook 2 '' destination
- The stderr should eq "-> Running 2 hook "
+ The stderr should eq "-> Running 2 hook"
The output should eq "$CPT_HOOK 2 null destination"
End
It "uses the /etc/cpt-hook file of the root when called with a fourth arg"
diff --git a/spec/02_src_spec.sh b/spec/02_src_spec.sh
index be81775..5286ab9 100644
--- a/spec/02_src_spec.sh
+++ b/spec/02_src_spec.sh
@@ -20,7 +20,7 @@ Describe 'Main toolchain'
Describe '--help'
It 'outputs usage information'
When run script src/cpt --help
- The line 1 of stderr should eq "-> Carbs Packaging Tool "
+ The line 1 of stderr should eq "-> Carbs Packaging Tool"
End
End
diff --git a/src/cpt-lib.in b/src/cpt-lib.in
index 58c9a0f..09b78e1 100644
--- a/src/cpt-lib.in
+++ b/src/cpt-lib.in
@@ -25,11 +25,12 @@ log() {
#
# All messages are printed to stderr to allow the user to hide build
# output which is the only thing printed to stdout.
- #
- # '${3:-->}': If the 3rd argument is missing, set prefix to '->'.
- # '${2:+colorb}': If the 2nd argument exists, set text style of '$1'.
- printf '%b%s %b%b%s%b %s\n' \
- "$colory" "${3:-->}" "$colre" "${2:+$colorb}" "$1" "$colre" "$2" >&2
+ case $# in
+ 1) printf '%b->%b %s\n' "$colory" "$colre" "$1" ;;
+ 2) printf '%b->%b %b%s%b %s\n' "$colory" "$colre" "$colorb" "$1" "$colre" "$2" ;;
+ 3) printf '%b%s%b %b%s%b %s\n' "$colory" "${3:-->}" "$colre" "$colorb" "$1" "$colre" "$2" ;;
+ *) return 1
+ esac >&2
}
warn() {
@@ -945,11 +946,10 @@ pkg_fix_deps() {
# simplify path building.
cd "$pkg_dir/$1/$pkg_db/$1"
- # Make a copy of the depends file if it exists to have a
- # reference to 'diff' against.
+ # Make a copy of the depends file if it exists to have a reference to 'diff'
+ # against.
if [ -f depends ]; then
- cp -f depends "$mak_dir/d"
- dep_file=$mak_dir/d
+ dep_file=$(_tmp_cp depends)
else
dep_file=/dev/null
fi
@@ -1484,13 +1484,13 @@ pkg_etc() {
mkdir -p "$CPT_ROOT/$dir"
done
- digest=$(_get_digest "$mak_dir/c") || digest=b3sum
+ digest=$(_get_digest "$_etcsums") || digest=b3sum
# Handle files in /etc/ based on a 3-way checksum check.
find etc ! -type d | while read -r file; do
{ sum_new=$("$digest" "$file")
sum_sys=$(cd "$CPT_ROOT/"; "$digest" "$file")
- sum_old=$("$grep" "$file$" "$mak_dir/c"); } 2>/dev/null ||:
+ sum_old=$("$grep" "$file$" "$_etcsums"); } 2>/dev/null ||:
logv "$pkg_name" "Doing 3-way handshake for $file"
outv "Previous: ${sum_old:-null}"
@@ -1555,8 +1555,9 @@ pkg_remove() {
# remove anything from packages that create empty directories for a
# purpose (such as baselayout).
manifest_list="$(set +f; pop "$sys_db/$1/manifest" from "$sys_db/"*/manifest)"
+ dirs="$(_tmp_name "directories")"
# shellcheck disable=2086
- [ "$manifest_list" ] && grep -h '/$' $manifest_list | sort -ur > "$mak_dir/dirs"
+ [ "$manifest_list" ] && grep -h '/$' $manifest_list | sort -ur > "$dirs"
run_hook pre-remove "$1" "$sys_db/$1" root
@@ -1566,7 +1567,7 @@ pkg_remove() {
[ "${file##/etc/*}" ] || continue
if [ -d "$CPT_ROOT/$file" ]; then
- "$grep" -Fxq "$file" "$mak_dir/dirs" 2>/dev/null && continue
+ "$grep" -Fxq "$file" "$dirs" 2>/dev/null && continue
rmdir "$CPT_ROOT/$file" 2>/dev/null || continue
else
rm -f "$CPT_ROOT/$file"
@@ -1652,8 +1653,8 @@ pkg_install() {
# If the package is already installed (and this is an upgrade) make a
# backup of the manifest and etcsums files.
- cp -f "$sys_db/$pkg_name/manifest" "$mak_dir/m" 2>/dev/null ||:
- cp -f "$sys_db/$pkg_name/etcsums" "$mak_dir/c" 2>/dev/null ||:
+ _manifest=$(_tmp_cp "$sys_db/$pkg_name/manifest" 2>/dev/null) ||:
+ _etcsums=$(_tmp_cp "$sys_db/$pkg_name/etcsums" 2>/dev/null) ||:
# This is repeated multiple times. Better to make it a function.
pkg_rsync() {
@@ -1668,7 +1669,7 @@ pkg_install() {
pkg_etc
# Remove any leftover files if this is an upgrade.
- "$grep" -vFxf "$sys_db/$pkg_name/manifest" "$mak_dir/m" 2>/dev/null |
+ "$grep" -vFxf "$sys_db/$pkg_name/manifest" "$_manifest" 2>/dev/null |
while read -r file; do
file=$CPT_ROOT/$file
@@ -2109,12 +2110,35 @@ pkg_clean() {
rm -rf -- "${CPT_TMPDIR:=$cac_dir/proc}/$pid"
}
+_tmp_name() {
+ # Name a temporary file/directory
+ out "$tmp_dir/$1"
+}
+
+_tmp_cp() {
+ # Copy given file to the temporary directory and return its name. If a
+ # second argument is not given, use the basename of the copied file.
+ _ret=${2:-${1##*/}}
+ _ret=$(_tmp_name "$_ret")
+ cp "$1" "$_ret"
+ out "$_ret"
+}
+
+_tmp_create() {
+ # Create given file to the temporary directory and return its name
+ _ret=$(_tmp_name "$1")
+ # False positive, we are not reading from the file.
+ # shellcheck disable=2094
+ out "$_ret" 3>> "$_ret"
+}
+
create_tmp() {
# Create the required temporary directories and set the variables which
# point to them.
- mkdir -p "${mak_dir:=$tmp_dir/build}" \
- "${pkg_dir:=$tmp_dir/pkg}" \
- "${tar_dir:=$tmp_dir/export}"
+ mak_dir=$tmp_dir/build
+ pkg_dir=$tmp_dir/pkg
+ tar_dir=$tmp_dir/export
+ mkdir -p "$mak_dir" "$pkg_dir" "$tar_dir"
}
create_cache() {
@@ -2142,25 +2166,34 @@ create_cache() {
# that it doesn't change beneath us.
pid=${CPT_PID:-$$}
- # Create the cache directories for CPT and set the variables which point
- # to them. This is seperate from temporary directories created in
- # create_cache(). That's because we need these variables set on most
- # occasions.
- #
# A temporary directory can be specified apart from the cache directory in
# order to build in a user specified directory. /tmp could be used in order
- # to build on ram, useful on SSDs. The user can specify CPT_TMPDIR for this.
- # We create the temporary directory here to avoid permission issues that can
- # arise from functions that call as_root().
- mkdir -p "${cac_dir:=${CPT_CACHE:=${XDG_CACHE_HOME:-$HOME/.cache}/cpt}}" \
- "${CPT_TMPDIR:=$cac_dir/proc}" \
- "${src_dir:=$cac_dir/sources}" \
- "${log_dir:=$cac_dir/logs}" \
- "${bin_dir:=$cac_dir/bin}"
-
- # We don't create the temporary $pid directory until `create_tmp()` is
- # called, but we still declare its variable here.
- : "${tmp_dir:=${CPT_TMPDIR:=$cac_dir/proc}/$pid}"
+ # to build on ram, useful on SSDs. The user can specify $CPT_TMPDIR for
+ # this. We now also support the usage of $XDG_RUNTIME_DIR, so the directory
+ # naming can be confusing to some. Here are possible $tdir names (by order
+ # of preference):
+ #
+ # 1. $CPT_TMPDIR
+ # 2. $XDG_RUNTIME_DIR/cpt
+ # 3. $XDG_CACHE_DIR/cpt/proc
+ # 4. $HOME/.cache/cpt/proc
+ #
+ # We create the main temporary directory here to avoid permission issues
+ # that can arise from functions that call as_root(). However, the
+ # $pid directories are special for each process and aren't created unless
+ # `create_tmp()` is used.
+ #
+ # We used to assign and create the directories at the same time using a
+ # shell hack, but it made the variables editable outside of the package
+ # manager, but we don't actually want that. Variables that are lower case
+ # aren't meant to be interacted or set by the user.
+ cac_dir=${CPT_CACHE:=${XDG_CACHE_HOME:-${HOME:?}/.cache}}/cpt
+ src_dir=$cac_dir/sources
+ log_dir=$cac_dir/logs
+ bin_dir=$cac_dir/bin
+ tdir=${CPT_TMPDIR:=${XDG_RUNTIME_DIR:-$cac_dir/proc}${XDG_RUNTIME_DIR:+/cpt}}
+ tmp_dir=$tdir/$pid
+ mkdir -p "$cac_dir" "$src_dir" "$log_dir" "$bin_dir" "$tdir"
# Set the location to the repository and package database.
pkg_db=var/db/cpt/installed
diff --git a/www/index.md b/www/index.md
index 2dc1fc5..4985b67 100644
--- a/www/index.md
+++ b/www/index.md
@@ -32,7 +32,7 @@ complements the tools that come with it. It has the following features:
<hr>
-### Latest Release: 6.1.1 ([2021-08-04](/timeline?c=6.1.1))
+### Latest Release: 6.2.0 ([2021-08-14](/timeline?c=6.2.0))
- [Download](/uvlist?byage=1)
- [Changelog](/doc/trunk/CHANGELOG.md)