FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 06-21-2010, 04:55 PM
Andres P
 
Default pacman-optimize: fix database locking race conditions

Instead of making the lock file with touch, use mkdir since it's the only
portable atomic transaction available to shell scripts.

Signed-off-by: Andres P <aepd87@gmail.com>
---
scripts/pacman-optimize.sh.in | 12 +++++-------
1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/scripts/pacman-optimize.sh.in b/scripts/pacman-optimize.sh.in
index 78b2345..f95f827 100644
--- a/scripts/pacman-optimize.sh.in
+++ b/scripts/pacman-optimize.sh.in
@@ -67,7 +67,7 @@ die() {
}

die_r() {
- rm -f "$lockfile"
+ rm -rf "$lock"
die "$@"
}

@@ -109,15 +109,13 @@ fi

# strip any trailing slash from our dbroot
dbroot="${dbroot%/}"
-# form the path to our lockfile location
-lockfile="${dbroot}/db.lck"
+# form the path to our db lock
+lock="${dbroot}/db.lck"

# make sure pacman isn't running
-if [[ -f $lockfile ]]; then
+if ! mkdir "$lock"; 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"

workdir=$(mktemp -d /tmp/pacman-optimize.XXXXXXXXXX) ||
die_r "$(gettext "ERROR: Can not create temp directory for database building.")
" >&2
@@ -174,7 +172,7 @@ fi
rm -rf "$dbroot.old"

# remove the lock file and our working directory with sums and tarfile
-rm -f "$lockfile"
+rm -rf "$lock"
rm -rf "$workdir"

echo
--
1.7.1
 

Thread Tools




All times are GMT. The time now is 01:31 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org