Skip to content

Commit

Permalink
@mafredri's flock solution
Browse files Browse the repository at this point in the history
  • Loading branch information
agkozak committed Dec 13, 2018
1 parent 4f1dfba commit 30bded5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions zsh-z.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,21 @@ zshz() {
esac
done

# zsystem flock-based solution by @mafredri

# A temporary file that gets copied over the datafile if all goes well
local tempfile="$(mktemp "${datafile}.XXXXXXXX")"

# Make sure tht the datafile exists for locking
[[ -f $datafile ]] || touch "$datafile"
local lockfd
if (( $ZSHZ_USE_ZSYSTEM_FLOCK )); then

# Make sure tht the datafile exists for locking
[[ -f $datafile ]] || touch "$datafile"
local lockfd

# Grab exclusive lock (released when function exits)
zsystem flock -f lockfd "$datafile" || return
# Grab exclusive lock (released when function exits)
zsystem flock -f lockfd "$datafile" || return

fi

_zshz_maintain_datafile "$*" >| "$tempfile"

Expand Down

0 comments on commit 30bded5

Please sign in to comment.