Fix locking to work with flutter and dart running simultaneously (#133350)

This commit is contained in:
Ian Hickson 2023-08-25 14:30:07 -07:00 committed by GitHub
parent 347f7bac94
commit c4e1a1b387
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View file

@ -45,6 +45,7 @@ function follow_links() (
PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")"
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
SHARED_NAME="$BIN_DIR/internal/shared.sh"
OS="$(uname -s)"
# If we're on Windows, invoke the batch script instead to get proper locking.
@ -53,6 +54,6 @@ if [[ $OS =~ MINGW.* || $OS =~ CYGWIN.* || $OS =~ MSYS.* ]]; then
fi
# To define `shared::execute()` function
source "$BIN_DIR/internal/shared.sh"
source "$SHARED_NAME"
shared::execute "$@"

View file

@ -50,6 +50,7 @@ function follow_links() (
PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")"
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
SHARED_NAME="$BIN_DIR/internal/shared.sh"
OS="$(uname -s)"
# If we're on Windows, invoke the batch script instead to get proper locking.
@ -58,6 +59,6 @@ if [[ $OS =~ MINGW.* || $OS =~ CYGWIN.* || $OS =~ MSYS.* ]]; then
fi
# To define `shared::execute()` function
source "$BIN_DIR/internal/shared.sh"
source "$SHARED_NAME"
shared::execute "$@"

View file

@ -229,7 +229,23 @@ function shared::execute() {
exit 1
fi
upgrade_flutter 7< "$PROG_NAME"
# File descriptor 7 is prepared here so that we can use it with
# flock(1) in _lock() (see above).
#
# We use number 7 because it's a luckier number than 3; luck is
# important when making locks work reliably. Also because that way
# if anyone is redirecting other file descriptors there's less
# chance of a conflict.
#
# In any case, the file we redirect into this file descriptor is
# this very source file you are reading right now, because that's
# the only file we can truly guarantee exists, since we're running
# it. We don't use PROG_NAME because otherwise if you run `dart` and
# `flutter` simultaneously they'll end up using different lock files
# and will corrupt each others' downloads.
#
# SHARED_NAME itself is prepared by the caller script.
upgrade_flutter 7< "$SHARED_NAME"
BIN_NAME="$(basename "$PROG_NAME")"
case "$BIN_NAME" in