reenable file locking and fix bug introduced by using libmagic