SHA256
1
0
forked from pool/os-prober
os-prober/os-prober-use-tmp-over-var-lib-for-transient-files.patch

128 lines
3.5 KiB
Diff
Raw Normal View History

From 2ed7c3ae98aa671d504eba254fdd89ea26fe15c8 Mon Sep 17 00:00:00 2001
From: Michael Chang <mchang@suse.com>
Date: Thu, 7 Mar 2019 16:31:19 +0800
Subject: [PATCH] Use /tmp over /var/lib for transient files
Create transient mount point in directory /tmp rather than /var/lib
which is not available during transactional update. Also clean up the
count_last_label function for not relying on /var/lib/os-prober/labels
file for the caculation.
https://en.opensuse.org/openSUSE:Packaging_for_transactional-updates
---
common.sh | 37 ++++++++++++++------------------
linux-boot-prober | 2 +-
linux-boot-probes/common/50mounted-tests | 2 +-
os-prober | 3 ---
os-probes/common/50mounted-tests | 2 +-
5 files changed, 19 insertions(+), 27 deletions(-)
diff --git a/common.sh b/common.sh
index 19d2668..d73718c 100644
--- a/common.sh
+++ b/common.sh
@@ -21,31 +21,26 @@ require_tmpdir() {
fi
}
-count_for() {
- _labelprefix="$1"
- _result=$(grep "^${_labelprefix} " /var/lib/os-prober/labels 2>/dev/null || true)
-
- if [ -z "$_result" ]; then
- return
- else
- echo "$_result" | cut -d' ' -f2
- fi
-}
-
+OS_PROBER_LABELS=""
count_next_label() {
- require_tmpdir
-
_labelprefix="$1"
- _cfor="$(count_for "${_labelprefix}")"
-
- if [ -z "$_cfor" ]; then
- echo "${_labelprefix} 1" >> /var/lib/os-prober/labels
+ _count=""
+ _labels=""
+ for i in $OS_PROBER_LABELS; do
+ _label="`echo $i | cut -d: -f1`"
+ if [ x"$_labelprefix" = x"$_label" ]; then
+ _count=`echo $i | cut -d: -f2`
+ _labels="$_labels $_label:`expr $_count + 1`"
+ else
+ _labels="$_labels $i"
+ fi
+ done
+ if [ -z "$_count" ]; then
+ OS_PROBER_LABELS="$OS_PROBER_LABELS $_labelprefix:1"
else
- sed "s/^${_labelprefix} ${_cfor}/${_labelprefix} $(($_cfor + 1))/" /var/lib/os-prober/labels > "$OS_PROBER_TMP/os-prober.tmp"
- mv "$OS_PROBER_TMP/os-prober.tmp" /var/lib/os-prober/labels
+ OS_PROBER_LABELS="$_labels"
fi
-
- echo "${_labelprefix}${_cfor}"
+ echo "${_labelprefix}${_count}"
}
progname=
diff --git a/linux-boot-prober b/linux-boot-prober
index 243fd6c..4d0f5e8 100755
--- a/linux-boot-prober
+++ b/linux-boot-prober
@@ -7,7 +7,7 @@ newns "$@"
require_tmpdir
ERR="n"
-tmpmnt=/var/lib/os-prober/mount
+tmpmnt="$OS_PROBER_TMP/mount"
if [ ! -d "$tmpmnt" ]; then
mkdir "$tmpmnt"
fi
diff --git a/linux-boot-probes/common/50mounted-tests b/linux-boot-probes/common/50mounted-tests
index 84c3ced..7c9c717 100755
--- a/linux-boot-probes/common/50mounted-tests
+++ b/linux-boot-probes/common/50mounted-tests
@@ -42,7 +42,7 @@ elif [ -z "$types" ]; then
types="$(grep -v nodev /proc/filesystems)"
fi
-tmpmnt=/var/lib/os-prober/mount
+tmpmnt="$OS_PROBER_TMP/mount"
if [ ! -d "$tmpmnt" ]; then
mkdir "$tmpmnt"
fi
diff --git a/os-prober b/os-prober
index fb0f93c..903eddb 100755
--- a/os-prober
+++ b/os-prober
@@ -141,9 +141,6 @@ parse_proc_mdstat () {
done
}
-# Needed for idempotency
-rm -f /var/lib/os-prober/labels
-
for prog in /usr/lib/os-probes/init/*; do
if [ -x "$prog" ] && [ -f "$prog" ]; then
"$prog" || true
diff --git a/os-probes/common/50mounted-tests b/os-probes/common/50mounted-tests
index a9c20ef..9555c39 100755
--- a/os-probes/common/50mounted-tests
+++ b/os-probes/common/50mounted-tests
@@ -58,7 +58,7 @@ elif [ -z "$types" ]; then
exit 0
fi
-tmpmnt=/var/lib/os-prober/mount
+tmpmnt="$OS_PROBER_TMP/mount"
if [ ! -d "$tmpmnt" ]; then
mkdir "$tmpmnt"
fi
--
2.16.4