Files
MilkV-Duo/buildroot-2021.05/support/scripts/hardlink-or-copy
sam.xiang e38fbf739c [buildroot] create buildroot-2021.05 from github
repo: https://github.com/buildroot/buildroot/tree/2021.05
	commit: 69f79f2a2ee1417e19c1ead2c9226e11753c06cb

	Update for 2021.05

Change-Id: I77d6d14da04483c97cb172bf6732732012e538d9
2023-03-13 23:30:54 +08:00

36 lines
924 B
Bash
Executable File

#!/usr/bin/env bash
# Try to hardlink a file into a directory, fallback to copy on failure.
#
# Hardlink-or-copy the source file in the first argument into the
# destination directory in the second argument, using the basename in
# the third argument as basename for the destination file. If the third
# argument is missing, use the basename of the source file as basename
# for the destination file.
#
# In either case, remove the destination prior to doing the
# hardlink-or-copy.
#
# Note that this is NOT an atomic operation.
set -e
main() {
local src_file="${1}"
local dst_dir="${2}"
local dst_file="${3}"
if [ -n "${dst_file}" ]; then
dst_file="${dst_dir}/${dst_file}"
else
dst_file="${dst_dir}/${src_file##*/}"
fi
mkdir -p "${dst_dir}"
rm -f "${dst_file}"
ln -f "${src_file}" "${dst_file}" 2>/dev/null \
|| cp -f "${src_file}" "${dst_file}"
}
main "${@}"