diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2019-05-17 06:54:42 +0200 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2019-05-17 06:54:48 +0200 |
commit | 2f3ab69844bf3d62a31704b6b5efba7576b52781 (patch) | |
tree | a5686560278d1d96ce58c7844e6d69848f37eb3f /scripts | |
parent | 0d4009fa7c3f43321ae5768b06e8c113b8e8eeec (diff) | |
download | ptxdist-2f3ab69844bf3d62a31704b6b5efba7576b52781.tar.gz ptxdist-2f3ab69844bf3d62a31704b6b5efba7576b52781.tar.xz |
introduce ptxd_replace_copy_from_path()
New helper to find a file with ptxd_in_path() and then atomically replace
the target file.
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/libptxdist.sh | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/scripts/libptxdist.sh b/scripts/libptxdist.sh index 17441e9db..1d21a0adb 100644 --- a/scripts/libptxdist.sh +++ b/scripts/libptxdist.sh @@ -320,6 +320,30 @@ ptxd_replace_link() { } export -f ptxd_replace_link +# +# ptxd_replace_copy_from_path +# +# atomically replace a file and use ptxd_in_path to find the source +# +# $1 variable name with paths separated by ":" +# $2 filename to find within these paths +# $$ the target file name +# +ptxd_replace_copy_from_path() { + if [ -d "${3}" ]; then + ptxd_bailout "ptxd_replace_copy_from_path: '${3}' must not be a directory" + fi + if ! ptxd_in_path "${1}" "${2}"; then + ptxd_bailout "ptxd_replace_copy_from_path: could not find ${2} in ${1}" + fi + if [ -d "${ptxd_reply}" ]; then + ptxd_bailout "ptxd_replace_copy_from_path: '${ptxd_reply}' must not be a directory" + fi + cp -a "${ptxd_reply}" "${3}.tmp" && + mv "${3}.tmp" "${3}" +} +export -f ptxd_replace_copy_from_path + ptxd_get_alternative_list() { local prefix="${1%/}" local file="${2#/}" |