Acquiring a lock should not be in getWorkPath. One function, one responsibility. Define and use functions for locking and unlocking files in the same scope.