Skip to content

Commit

Permalink
don't use flock on wsl -- it's broken there
Browse files Browse the repository at this point in the history
    touch /tmp/lock
    zmodload zsh/system
    zsystem flock /tmp/lock
    ( zsystem flock /tmp/lock )  # must hang but on wsl it doesn't

See:

- microsoft/WSL#1927
- microsoft/WSL#1712
  • Loading branch information
romkatv committed Feb 22, 2020
1 parent 9fdf1fa commit 1f0b437
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions gitstatus.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,12 @@ function gitstatus_start() {
fi

if (( ! _GITSTATUS_STATE_$name )); then
print -rn >$file_prefix.lock || return
zsystem flock -f lock_fd $file_prefix.lock || return
if [[ -r /proc/version && "$(</proc/version)" == *Microsoft* ]]; then
lock_fd=-1
else
print -rn >$file_prefix.lock || return
zsystem flock -f lock_fd $file_prefix.lock || return
fi
typeset -gi _GITSTATUS_LOCK_FD_$name=lock_fd

{
Expand Down Expand Up @@ -516,6 +520,8 @@ function gitstatus_start() {
}
} &!
(( lock_fd == -1 )) && return
{
if zsystem flock -- $file_prefix.lock && [[ -e $file_prefix.lock ]]; then
zf_rm -f -- $file_prefix.lock $file_prefix.fifo
Expand Down Expand Up @@ -575,8 +581,10 @@ function gitstatus_start() {
done
[[ $actual == $expected ]] || return

zf_rm -- $file_prefix.lock || return
zsystem flock -u $lock_fd || return
if (( lock_fd != -1 )); then
zf_rm -- $file_prefix.lock || return
zsystem flock -u $lock_fd || return
fi
unset _GITSTATUS_LOCK_FD_$name

typeset -gi _GITSTATUS_STATE_$name=2
Expand Down Expand Up @@ -690,7 +698,7 @@ function gitstatus_stop() {
fi

[[ -n $file_prefix ]] && zf_rm -f -- "$file_prefix.lock" "$file_prefix.fifo"
[[ -n $lock_fd ]] && zsystem flock -u $lock_fd
[[ -n $lock_fd ]] && (( lock_fd != -1 )) && zsystem flock -u $lock_fd
[[ -n $req_fd ]] && exec {req_fd}>&-
[[ -n $resp_fd ]] && exec {resp_fd}>&-

Expand Down

0 comments on commit 1f0b437

Please sign in to comment.