mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
0d215b5548
realpath(1) is specific to coreutils and its behavior can be had with readlink -f Create the Toolchain Build directory if it doesn't exist before calling readlink, since realpath(3) on at least OpenBSD will error on a non-existent path
29 lines
494 B
Bash
Executable File
29 lines
494 B
Bash
Executable File
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
if [ "$#" -lt "2" ]; then
|
|
echo "USAGE: $0 <file> <cmd...>"
|
|
exit 1
|
|
fi
|
|
|
|
DST_FILE="$1"
|
|
shift
|
|
|
|
# Just in case:
|
|
mkdir -p -- "$(dirname -- "${DST_FILE}")"
|
|
|
|
cleanup()
|
|
{
|
|
rm -f -- "${DST_FILE}.tmp"
|
|
}
|
|
trap cleanup 0 1 2 3 6
|
|
|
|
"$@" > "${DST_FILE}.tmp"
|
|
# If we get here, the command was successful, and we can overwrite the destination.
|
|
|
|
if ! cmp -s -- "${DST_FILE}.tmp" "${DST_FILE}"; then
|
|
# File changed, need to overwrite:
|
|
mv -f -- "${DST_FILE}.tmp" "${DST_FILE}"
|
|
fi
|