diff options
| author | 2026-03-23 03:25:44 +0000 | |
|---|---|---|
| committer | 2026-03-23 03:27:52 +0000 | |
| commit | 4a796e64ac576d6a3e3f2fe6174c4aa476ea0c5c (patch) | |
| tree | 44d72a20076ceab0981d0b553693d26ca36cc0be /refstore/files/update_cleanup.go | |
| parent | receivepack: Lifecycle/ownership docs (diff) | |
| signature | No signature | |
refstore: Improve interfaces, errors, and make batch work v0.1.92
Diffstat (limited to 'refstore/files/update_cleanup.go')
| -rw-r--r-- | refstore/files/update_cleanup.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/refstore/files/update_cleanup.go b/refstore/files/update_cleanup.go new file mode 100644 index 00000000..5df2d967 --- /dev/null +++ b/refstore/files/update_cleanup.go @@ -0,0 +1,39 @@ +package files + +import ( + "errors" + "os" + "slices" +) + +func (executor *refUpdateExecutor) cleanupPreparedUpdates(prepared []preparedUpdate) error { + var firstErr error + + lockNames := make([]string, 0, len(prepared)+1) + for _, item := range prepared { + lockNames = append(lockNames, updateTargetKey(item.target.loc)) + } + + lockNames = append(lockNames, updateTargetKey(refPath{root: rootCommon, path: "packed-refs"})) + slices.Sort(lockNames) + lockNames = slices.Compact(lockNames) + + for _, lockKey := range lockNames { + lockPath := refPathFromKey(lockKey) + lockName := lockPath.path + ".lock" + root := executor.store.rootFor(lockPath.root) + + err := root.Remove(lockName) + if err == nil || errors.Is(err, os.ErrNotExist) { + executor.tryRemoveEmptyParentPaths(lockPath.root, lockName) + + continue + } + + if firstErr == nil { + firstErr = err + } + } + + return firstErr +} |
