aboutsummaryrefslogtreecommitdiffstats
path: root/cache/repo_cache.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2023-01-11 14:22:28 +0100
committerMichael Muré <batolettre@gmail.com>2023-01-11 14:22:58 +0100
commitace0f055074a6ecee0f9893d545f0ff6f7fc3c45 (patch)
tree1c6732eb1a87ee9f65da62a6cf156bd441a2f02a /cache/repo_cache.go
parent2664332bfd17094dd8a485ea085099d6eac33068 (diff)
downloadgit-bug-ace0f055074a6ecee0f9893d545f0ff6f7fc3c45.tar.gz
properly close files in edge cases in various places
Diffstat (limited to 'cache/repo_cache.go')
-rw-r--r--cache/repo_cache.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index 130500cb..99e9abbd 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -3,7 +3,6 @@ package cache
import (
"fmt"
"io"
- "io/ioutil"
"os"
"strconv"
"sync"
@@ -181,6 +180,7 @@ func (c *RepoCache) lock(events chan BuildEvent) error {
pid := fmt.Sprintf("%d", os.Getpid())
_, err = f.Write([]byte(pid))
if err != nil {
+ _ = f.Close()
return err
}
@@ -279,11 +279,18 @@ func repoIsAvailable(repo repository.RepoStorage, events chan BuildEvent) error
if err == nil {
// lock file already exist
- buf, err := ioutil.ReadAll(io.LimitReader(f, 10))
+ buf, err := io.ReadAll(io.LimitReader(f, 10))
if err != nil {
+ _ = f.Close()
return err
}
- if len(buf) == 10 {
+
+ err = f.Close()
+ if err != nil {
+ return err
+ }
+
+ if len(buf) >= 10 {
return fmt.Errorf("the lock file should be < 10 bytes")
}
@@ -299,10 +306,6 @@ func repoIsAvailable(repo repository.RepoStorage, events chan BuildEvent) error
// The lock file is just laying there after a crash, clean it
events <- BuildEvent{Event: BuildEventRemoveLock}
- err = f.Close()
- if err != nil {
- return err
- }
err = repo.LocalStorage().Remove(lockfile)
if err != nil {