Skip to content

Commit 7dbce99

Browse files
benallengnothingmuch
authored andcommitted
Add lockfile backup to update-lock-files script
1 parent feb27aa commit 7dbce99

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

contrib/update-lock-files.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44

55
set -euo pipefail
66

7+
LOCKFILE="Cargo.lock"
8+
LOCKDIR=".bak"
9+
LOCKFILE_BAK="${LOCKDIR}/${LOCKFILE}"
10+
11+
cleanup() {
12+
if [ -f "$LOCKFILE_BAK" ]; then
13+
mv "$LOCKFILE_BAK" "$LOCKFILE"
14+
fi
15+
rmdir "$LOCKDIR"
16+
}
17+
18+
if ! mkdir "$LOCKDIR" 2>/dev/null; then
19+
echo "Another instance is running. If you're sure it's not, remove $LOCKDIR and try again." >&2
20+
exit 1
21+
fi
22+
23+
trap cleanup EXIT
24+
25+
if [ -f "$LOCKFILE" ]; then
26+
mv "$LOCKFILE" "$LOCKFILE_BAK"
27+
fi
28+
729
for file in Cargo-minimal.lock Cargo-recent.lock; do
830
cp -f "$file" Cargo.lock
931
cargo check

0 commit comments

Comments
 (0)