bin/rebuild: rework locking so it works on OS X