fix test for $! under Win32
quote $o in regex
prevent locking more than once

some OSes (Win32) can't lock the same file twice in the same process