getLock returns or creates the mutex for a normalized file path.
(path string)
| 21 | |
| 22 | // getLock returns or creates the mutex for a normalized file path. |
| 23 | func (m *FileLockManager) getLock(path string) *sync.Mutex { |
| 24 | abs, err := filepath.Abs(path) |
| 25 | if err != nil { |
| 26 | abs = path |
| 27 | } |
| 28 | |
| 29 | m.mu.Lock() |
| 30 | defer m.mu.Unlock() |
| 31 | |
| 32 | lock, ok := m.locks[abs] |
| 33 | if !ok { |
| 34 | lock = &sync.Mutex{} |
| 35 | m.locks[abs] = lock |
| 36 | } |
| 37 | return lock |
| 38 | } |
| 39 | |
| 40 | // Lock acquires the mutex for a given file path. |
| 41 | func (m *FileLockManager) Lock(path string) { |