cleanups
This commit is contained in:
1 parent
60ec470f9f
commit
fe2ad1590d
9 files changed
+186
-19
No files matched your search
+51
-1
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
PACKAGING_REVISION=2
|
||||
PACKAGING_REVISION=3
|
||||
DATA_DIR=${DATA_DIR:-/var/lib/rustbox-package-builder}
|
||||
|
||||
log() { printf '%s %s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ')" "$*"; }
|
||||
@@ -13,3 +13,53 @@ print(json.dumps(sys.argv[1]))
|
||||
PY
|
||||
}
|
||||
atomic_write() { local path=$1 tmp="${path}.tmp.$$"; cat > "$tmp"; mv -f "$tmp" "$path"; }
|
||||
|
||||
is_true() {
|
||||
case "${1:-}" in
|
||||
1|true|TRUE|yes|YES|on|ON) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
require_positive_integer() {
|
||||
local name=$1 value=$2
|
||||
[[ "$value" =~ ^[1-9][0-9]*$ ]] || fatal "$name must be a positive integer"
|
||||
}
|
||||
|
||||
prune_package_files() {
|
||||
local directory=$1 pattern=$2 keep=$3
|
||||
require_positive_integer PACKAGE_RETENTION "$keep"
|
||||
[[ -d "$directory" ]] || return 0
|
||||
|
||||
mapfile -t stale < <(
|
||||
find "$directory" -maxdepth 1 -type f -name "$pattern" -printf '%T@ %p\n' \
|
||||
| sort -nr \
|
||||
| awk -v keep="$keep" 'NR>keep {$1=""; sub(/^ /,""); print}'
|
||||
)
|
||||
|
||||
local path
|
||||
for path in "${stale[@]}"; do
|
||||
[[ -n "$path" ]] || continue
|
||||
log "package retention: removing $path"
|
||||
rm -f -- "$path"
|
||||
done
|
||||
}
|
||||
|
||||
prune_release_dirs() {
|
||||
local releases_dir=$1 keep=$2 protected=${3:-}
|
||||
require_positive_integer RELEASE_RETENTION "$keep"
|
||||
[[ -d "$releases_dir" ]] || return 0
|
||||
|
||||
mapfile -t stale < <(
|
||||
find "$releases_dir" -mindepth 1 -maxdepth 1 -type d -printf '%T@ %p\n' \
|
||||
| sort -nr \
|
||||
| awk -v keep="$keep" 'NR>keep {$1=""; sub(/^ /,""); print}'
|
||||
)
|
||||
|
||||
local path
|
||||
for path in "${stale[@]}"; do
|
||||
[[ -n "$path" && "$path" != "$protected" ]] || continue
|
||||
log "release retention: removing $path"
|
||||
rm -rf -- "$path"
|
||||
done
|
||||
}
|
||||
Reference in new issue
Block a user