scripts: Ignore database locks if the process that locked the database no longer exists in makepkg and pacman-db-upgrade
This commit is contained in:
parent
47d80ded72
commit
52996a3727
4 changed files with 45 additions and 12 deletions
31
scripts/libmakepkg/util/lock.sh.in
Normal file
31
scripts/libmakepkg/util/lock.sh.in
Normal file
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# lock.sh - functions to handle pacman locking
|
||||
#
|
||||
# Copyright (c) 2024 Pacman Development Team <pacman-dev@lists.archlinux.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
is_pacman_locked() {
|
||||
local lockfile="$(pacman-conf DBPath)/db.lck"
|
||||
if [[ -f $lockfile ]]; then
|
||||
local pid=$(<"$lockfile")
|
||||
# Check if the pid is valid and the process is still running
|
||||
if [[ -n $pid && $pid =~ ^[0-9]+$ && -d /proc/$pid ]]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
|
@ -5,6 +5,7 @@ sources = [
|
|||
'config.sh.in',
|
||||
'dirsize.sh.in',
|
||||
'error.sh.in',
|
||||
'lock.sh.in',
|
||||
'message.sh.in',
|
||||
'option.sh.in',
|
||||
'parseopts.sh.in',
|
||||
|
|
|
@ -247,14 +247,11 @@ run_pacman() {
|
|||
else
|
||||
cmd=(su root -c "$cmdescape")
|
||||
fi
|
||||
local lockfile="$(pacman-conf DBPath)/db.lck"
|
||||
while [[ -f $lockfile ]]; do
|
||||
local timer=0
|
||||
local timer=0
|
||||
while is_pacman_locked && (( timer < 10 )); do
|
||||
(( ++timer ))
|
||||
msg "$(gettext "Pacman is currently in use, please wait...")"
|
||||
while [[ -f $lockfile ]] && (( timer < 10 )); do
|
||||
(( ++timer ))
|
||||
sleep 3
|
||||
done
|
||||
sleep 3
|
||||
done
|
||||
fi
|
||||
"${cmd[@]}"
|
||||
|
|
|
@ -30,6 +30,7 @@ declare -r myver='@PACKAGE_VERSION@'
|
|||
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
|
||||
|
||||
# Import libmakepkg
|
||||
source "$MAKEPKG_LIBRARY"/util/lock.sh
|
||||
source "$MAKEPKG_LIBRARY"/util/message.sh
|
||||
source "$MAKEPKG_LIBRARY"/util/parseopts.sh
|
||||
|
||||
|
@ -132,15 +133,18 @@ fi
|
|||
|
||||
# strip any trailing slash from our dbroot
|
||||
dbroot="${dbroot%/}"
|
||||
|
||||
# make sure pacman isn't running
|
||||
if is_pacman_locked; then
|
||||
die "$(gettext "Pacman lock file was found. Cannot run while pacman is running.")"
|
||||
fi
|
||||
|
||||
# form the path to our lockfile location
|
||||
lockfile="${dbroot}/db.lck"
|
||||
|
||||
# make sure pacman isn't running
|
||||
if [[ -f $lockfile ]]; then
|
||||
die "$(gettext "Pacman lock file was found. Cannot run while pacman is running.")"
|
||||
fi
|
||||
# do not let pacman run while we do this
|
||||
touch "$lockfile"
|
||||
# write our pid to the lockfile
|
||||
echo $$ > "$lockfile"
|
||||
|
||||
if [[ -f "${dbroot}"/local/ALPM_DB_VERSION ]]; then
|
||||
db_version=$(cat "${dbroot}"/local/ALPM_DB_VERSION)
|
||||
|
|
Loading…
Add table
Reference in a new issue