WithReadLock runs the given function while holding a read lock on the directory `dir`
It returns a bool indicating whether the lock was acquired and any error that occurred acquiring the lock or running the function
WithWriteLock runs the given function while holding a write lock on the directory `dir`
It returns a bool indicating whether the lock was acquired and any error that occurred acquiring the lock or running the function