aboutsummaryrefslogtreecommitdiffstats
path: root/commands
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 /commands
parent2664332bfd17094dd8a485ea085099d6eac33068 (diff)
downloadgit-bug-ace0f055074a6ecee0f9893d545f0ff6f7fc3c45.tar.gz
properly close files in edge cases in various places
Diffstat (limited to 'commands')
-rw-r--r--commands/select/select.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/commands/select/select.go b/commands/select/select.go
index 694d636a..cd12250e 100644
--- a/commands/select/select.go
+++ b/commands/select/select.go
@@ -3,7 +3,6 @@ package _select
import (
"fmt"
"io"
- "io/ioutil"
"os"
"path/filepath"
@@ -101,6 +100,7 @@ func Select(repo *cache.RepoCache, namespace string, id entity.Id) error {
_, err = f.Write([]byte(id.String()))
if err != nil {
+ _ = f.Close()
return err
}
@@ -124,11 +124,18 @@ func selected[CacheT cache.CacheEntity](repo *cache.RepoCache, resolver Resolver
}
}
- buf, err := ioutil.ReadAll(io.LimitReader(f, 100))
+ buf, err := io.ReadAll(io.LimitReader(f, 100))
if err != nil {
+ _ = f.Close()
return nil, err
}
- if len(buf) == 100 {
+
+ err = f.Close()
+ if err != nil {
+ return nil, err
+ }
+
+ if len(buf) >= 100 {
return nil, fmt.Errorf("the select file should be < 100 bytes")
}
@@ -147,10 +154,5 @@ func selected[CacheT cache.CacheEntity](repo *cache.RepoCache, resolver Resolver
return nil, err
}
- err = f.Close()
- if err != nil {
- return nil, err
- }
-
return &cached, nil
}