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 <anthraxx@archlinux.org>
This commit is contained in:
Levente Polyak 2024-01-05 13:38:19 +01:00
parent 4673ad6c89
commit 0e538cf498
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
1 changed files with 1 additions and 1 deletions

View File

@ -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