From 0e538cf4983f27548077c0a2a272ecd8deebacb1 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Fri, 5 Jan 2024 13:38:19 +0100 Subject: fix(util): open lock file in append mode to avoid overwriting files Previously if we opened a lock on an existing file with useful content we overwrote it with an empty file. This is obviously not desired, hence open the file handle in append mode preserving its content. Signed-off-by: Levente Polyak --- src/lib/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/common.sh b/src/lib/common.sh index 82fdd2e..29b0343 100644 --- a/src/lib/common.sh +++ b/src/lib/common.sh @@ -135,7 +135,7 @@ lock() { # Only reopen the FD if it wasn't handed to us if ! [[ "/dev/fd/$1" -ef "$2" ]]; then mkdir -p -- "$(dirname -- "$2")" - eval "exec $1>"'"$2"' + eval "exec $1>>"'"$2"' fi if ! flock -n "$1"; then -- cgit v1.2.3-54-g00ecf