Lock obtains the lock on the locker directory.
()
| 67 | |
| 68 | // Lock obtains the lock on the locker directory. |
| 69 | func (l *DirLocker) Lock() error { |
| 70 | if l.releaser != nil { |
| 71 | return errors.New("DB lock already obtained") |
| 72 | } |
| 73 | |
| 74 | if _, err := os.Stat(l.path); err == nil { |
| 75 | l.logger.Warn("A lockfile from a previous execution already existed. It was replaced", "file", l.path) |
| 76 | |
| 77 | l.createdCleanly.Set(lockfileReplaced) |
| 78 | } else { |
| 79 | l.createdCleanly.Set(lockfileCreatedCleanly) |
| 80 | } |
| 81 | |
| 82 | lockf, _, err := fileutil.Flock(l.path) |
| 83 | if err != nil { |
| 84 | return fmt.Errorf("lock DB directory: %w", err) |
| 85 | } |
| 86 | l.releaser = lockf |
| 87 | return nil |
| 88 | } |
| 89 | |
| 90 | // Release releases the lock. No-op if the lock is not held. |
| 91 | func (l *DirLocker) Release() error { |