helpers: fix non-atomic cache write

This was causing some values to be repeated more than once when using
multiple tmux windows at the same time, for example for the RAM
percentage in ram_percentage.sh.

GitHub: fixes #62
This commit is contained in:
pacien 2023-01-05 21:21:05 +01:00
parent 9eb3dba666
commit f609bed961

View file

@ -130,8 +130,10 @@ put_cache_val() {
val="${*:2}"
tmpdir="$(get_tmp_dir)"
[ ! -d "$tmpdir" ] && mkdir -p "$tmpdir" && chmod 0700 "$tmpdir"
get_time >"$tmpdir/$key"
echo -n "$val" >>"$tmpdir/$key"
(
get_time
echo -n "$val"
) >"$tmpdir/$key"
echo -n "$val"
}