mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #49897 from mikedanese/atomic-append
Automatic merge from submit-queue (batch tested with PRs 49898, 49897, 49919, 48860, 49491) gce: make append_or_replace.. atomic Before this change, * the final echo is not atomically written to the target file * two concurrent callers will use the same tempfile Helps with https://github.com/kubernetes/kubernetes/issues/49895 cc @miekg
This commit is contained in:
commit
49955b1594
@ -239,10 +239,13 @@ function append_or_replace_prefixed_line {
|
|||||||
local -r file="${1:-}"
|
local -r file="${1:-}"
|
||||||
local -r prefix="${2:-}"
|
local -r prefix="${2:-}"
|
||||||
local -r suffix="${3:-}"
|
local -r suffix="${3:-}"
|
||||||
|
local -r dirname="$(dirname ${file})"
|
||||||
|
local -r tmpfile="$(mktemp -t filtered.XXXX --tmpdir=${dirname})"
|
||||||
|
|
||||||
touch "${file}"
|
touch "${file}"
|
||||||
awk "substr(\$0,0,length(\"${prefix}\")) != \"${prefix}\" { print }" "${file}" > "${file}.filtered" && mv "${file}.filtered" "${file}"
|
awk "substr(\$0,0,length(\"${prefix}\")) != \"${prefix}\" { print }" "${file}" > "${tmpfile}"
|
||||||
echo "${prefix}${suffix}" >> "${file}"
|
echo "${prefix}${suffix}" >> "${tmpfile}"
|
||||||
|
mv "${tmpfile}" "${file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function create-node-pki {
|
function create-node-pki {
|
||||||
|
Loading…
Reference in New Issue
Block a user