Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

no_clobber and error conditions



On May 9,  6:04pm, Lloyd Zusman wrote:
} Subject: File locking within zsh?
}
} Do any of you know of any functions, primitives, tricks, hacks, or even
} outright abominations which will allow me to do cooperative file locking
} from within zsh?

I was going to suggest this:

    function lock {
      setopt localoptions noclobber
      while true
      do
	{
	  : > $1
	  return 0
	} always {
	  (( TRY_BLOCK_ERROR=0 ))
	} 2>/dev/null
        sleep 1
      done
      return 1
    }

However, it appears that the error from noclobber does not "throw an
exception," it merely causes the command to have exit status 1.

That's not consistent with csh behavior (tcsh in this sample):

[schaefer@toltec /tmp]$ ( set noclobber; echo > lockfile; echo oops )
lockfile: File exists.
[schaefer@toltec /tmp]$ 
schaefer[537] ( setopt noclobber; echo > lockfile; echo oops )
zsh: file exists: lockfile
oops
schaefer[538]



Messages sorted by: Reverse Date, Date, Thread, Author