mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-24 04:50:27 +02:00
27756: add OS file locking to calendar
add errflag test to loop over fcntl()
This commit is contained in:
parent
ecc7dc91f6
commit
07b6256d8e
7 changed files with 57 additions and 9 deletions
|
|
@ -253,13 +253,21 @@ if (( verbose )); then
|
|||
fi
|
||||
fi
|
||||
|
||||
# start of subshell for OS file locking
|
||||
(
|
||||
# start of block for following always to clear up lockfiles.
|
||||
# Not needed but harmless if OS file locking is used.
|
||||
{
|
||||
if [[ -n $donefile ]]; then
|
||||
# Attempt to lock both $donefile and $calendar.
|
||||
# Don't lock $newfile; we've tried our best to make
|
||||
# the name unique.
|
||||
calendar_lockfiles $calendar $donefile || return 1
|
||||
if zmodload -F zsh/system b:zsystem && zsystem supports flock; then
|
||||
zsystem flock $calendar
|
||||
zsystem flock $donefile
|
||||
else
|
||||
calendar_lockfiles $calendar $donefile || exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
calendar_read $calendar
|
||||
|
|
@ -414,4 +422,5 @@ Old calendar left in $calendar.old." >&2
|
|||
(( ${#lockfiles} )) && rm -f $lockfiles
|
||||
}
|
||||
|
||||
return $rstat
|
||||
exit $rstat
|
||||
)
|
||||
|
|
|
|||
|
|
@ -68,9 +68,18 @@ if [[ $addline = ${~uidpat} ]]; then
|
|||
my_uid=${(U)match[1]}
|
||||
fi
|
||||
|
||||
# start of subshell for OS file locking
|
||||
(
|
||||
# start of block for following always to clear up lockfiles.
|
||||
# Not needed but harmless if OS file locking is used.
|
||||
{
|
||||
(( nolock )) || calendar_lockfiles $calendar || return 1
|
||||
if (( ! nolock )); then
|
||||
if zmodload -F zsh/system b:zsystem && zsystem supports flock; then
|
||||
zsystem flock $calendar
|
||||
else
|
||||
calendar_lockfiles $calendar || exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -f $calendar ]]; then
|
||||
calendar_read $calendar
|
||||
|
|
@ -158,4 +167,5 @@ Old calendar left in $calendar.old." >&2
|
|||
(( ${#lockfiles} )) && rm -f $lockfiles
|
||||
}
|
||||
|
||||
return $rstat
|
||||
exit $rstat
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,12 +10,21 @@ done
|
|||
|
||||
zstyle -s ':datetime:calendar:' calendar-file calendar || calendar=~/calendar
|
||||
|
||||
# start of subshell for OS file locking
|
||||
(
|
||||
# start of block for following always to clear up lockfiles.
|
||||
# Not needed but harmless if OS file locking is used.
|
||||
{
|
||||
calendar_lockfiles $calendar || return 1
|
||||
if zmodload -F zsh/system b:zsystem && zsystem supports flock; then
|
||||
zsystem flock $calendar
|
||||
else
|
||||
calendar_lockfiles $calendar || exit 1
|
||||
fi
|
||||
|
||||
eval $editor \$calendar
|
||||
} always {
|
||||
(( ${#lockfiles} )) && rm -f $lockfiles
|
||||
}
|
||||
)
|
||||
|
||||
(( cal_running )) && calendar -s
|
||||
|
|
|
|||
|
|
@ -11,9 +11,16 @@ integer i
|
|||
# Read the calendar file from the calendar-file style
|
||||
zstyle -s ':datetime:calendar:' calendar-file calendar || calendar=~/calendar
|
||||
|
||||
# Start block for "always" to handle lockfile
|
||||
# start of subshell for OS file locking
|
||||
(
|
||||
# start of block for following always to clear up lockfiles.
|
||||
# Not needed but harmless if OS file locking is used.
|
||||
{
|
||||
calendar_lockfiles $calendar || return 1
|
||||
if zmodload -F zsh/system b:zsystem && zsystem supports flock; then
|
||||
zsystem flock $calendar
|
||||
else
|
||||
calendar_lockfiles $calendar || exit 1
|
||||
fi
|
||||
|
||||
new=$calendar.new.$$
|
||||
calendar_read $calendar
|
||||
|
|
@ -65,3 +72,4 @@ Old calendar left in $calendar.old"
|
|||
} always {
|
||||
(( ${#lockfiles} )) && rm -rf $lockfiles
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue