summaryrefslogtreecommitdiff
path: root/src/abslibre-tools
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-05-03 01:00:40 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-05-03 01:39:15 -0400
commitf719b2ecae8183eabcc5fc3580c32af565ea778d (patch)
treec34c2264ba7610123eb02bf26f666b022657675d /src/abslibre-tools
parent569276ca95b637fc455da4d3051ea000d54d6492 (diff)
libredbdiff: improve tmpfile management
Diffstat (limited to 'src/abslibre-tools')
-rwxr-xr-xsrc/abslibre-tools/libredbdiff21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/abslibre-tools/libredbdiff b/src/abslibre-tools/libredbdiff
index 8bcc6d9..24a716d 100755
--- a/src/abslibre-tools/libredbdiff
+++ b/src/abslibre-tools/libredbdiff
@@ -37,9 +37,6 @@ field_pkgname_arch=30
cmd="${0##*/}"
-arch_packages_tmp="/tmp/$cmd.arch-packages"
-prbl_packages_tmp="/tmp/$cmd.parabola-packages"
-
field_pkgname_total="$((field_pkgname_prbl + field_pkgname_arch))"
printf_format="%s %-${field_pkgname_prbl}s%-${field_pkgname_arch}s %s | %s\n"
printf_format_noarch="%s %-${field_pkgname_total}s %s\n"
@@ -150,6 +147,11 @@ initialize() {
fi
}
+# Globals:
+# - pkgname : the Parabola pkgname
+# - ver_prbl : a map of pkgname->arch_pkgver
+# - ver_arch : a map of pkgname->prbl_pkgver
+# - provides : a map of pkgname->provides
compare_pkgs() {
local cmp
if [[ -n "${ver_arch[$pkgname]}" ]] ; then
@@ -186,6 +188,11 @@ compare_pkgs() {
fi
}
+# Globals:
+# - prbl_packages_tmp
+# - ver_prbl
+# - ver_arch (transitively through compare_pkgs)
+# - provides
print_cmp() {
local repo="$1"
awk -F/ -v repo="$repo" \
@@ -342,6 +349,12 @@ main_compare() {
filenotfound "$conffile_prbl"
filenotfound "$conffile_arch"
+ local tmpdir
+ tmpdir="$(mktemp --tmpdir -d "$cmd.XXXXXXXXXX")" || die "Could not create temporary working directory"
+ trap "rm -rf -- $(printf %q "$tmpdir")" RETURN
+ local arch_packages_tmp="$tmpdir/arch-packages"
+ local prbl_packages_tmp="$tmpdir/parabola-packages"
+
unset provides ver_prbl ver_arch
declare -gA provides ver_prbl ver_arch
@@ -350,7 +363,6 @@ main_compare() {
awk -F/ '{print $2}' \
> "$arch_packages_tmp" || \
die "pacman command to get Arch package data has failed. Exiting."
- chmod 777 "$arch_packages_tmp"
while read -a line; do
ver_arch["${line[0]}"]="${line[1]}"
@@ -359,7 +371,6 @@ main_compare() {
expac --config "$conffile_prbl" -S '%r/%n %v %S' \
> "$prbl_packages_tmp" || \
die "expac command to get Parabola package data has failed. Exiting."
- chmod 777 "$prbl_packages_tmp"
if [[ $# == 1 ]]; then
print_cmp "$1"