aboutsummaryrefslogtreecommitdiffstats
path: root/commands/select
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2023-01-11 14:30:52 +0100
committerGitHub <noreply@github.com>2023-01-11 14:30:52 +0100
commit9c50a359704f4edd2f33df6d256e032feae3a576 (patch)
tree1c6732eb1a87ee9f65da62a6cf156bd441a2f02a /commands/select
parent76100380978418dbfa6fa880f05d335c9a4aafcd (diff)
parentace0f055074a6ecee0f9893d545f0ff6f7fc3c45 (diff)
downloadgit-bug-9c50a359704f4edd2f33df6d256e032feae3a576.tar.gz
Merge pull request #989 from MichaelMure/fix-tests
repo: check error when closing a repo in tests
Diffstat (limited to 'commands/select')
-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
}