Skip to content

Commit 2db6bf4

Browse files
committed
close open files
1 parent 1e3aa21 commit 2db6bf4

5 files changed

Lines changed: 18 additions & 7 deletions

File tree

cmds/identityd/ssh.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ func manageSSHKeys() error {
7575
return fmt.Errorf("failed to fetch user keys: %+w", err)
7676
}
7777

78+
defer func() {
79+
if res != nil && res.Body != nil {
80+
res.Body.Close()
81+
}
82+
}()
83+
7884
if res.StatusCode == http.StatusNotFound {
7985
return backoff.Permanent(fmt.Errorf("failed to get user keys for user (%s): keys not found", user))
8086
}

cmds/modules/vmd/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ var Module cli.Command = cli.Command{
4747
// copy files from src dir to dst dir works at one level only for
4848
// our specific use case
4949
func copyDepth1(src, dst string) error {
50-
5150
return filepath.Walk(src, func(path string, info fs.FileInfo, err error) error {
5251
if err != nil {
5352
return err
@@ -62,11 +61,15 @@ func copyDepth1(src, dst string) error {
6261
if err != nil {
6362
return err
6463
}
64+
defer srcF.Close()
65+
6566
dstPath := filepath.Join(dst, filepath.Base(path))
6667
dstF, err := os.Create(dstPath)
6768
if err != nil {
6869
return err
6970
}
71+
defer dstF.Close()
72+
7073
_, err = io.Copy(dstF, srcF)
7174
return err
7275
})
@@ -92,7 +95,7 @@ func action(cli *cli.Context) error {
9295
return errors.Wrap(err, "fail to connect to message broker server")
9396
}
9497

95-
config, err := cache.VolatileDir(module, 50*1024*1024) //50mb volatile directory
98+
config, err := cache.VolatileDir(module, 50*1024*1024) // 50mb volatile directory
9699
if err != nil && !os.IsExist(err) {
97100
return errors.Wrap(err, "failed to create vmd volatile storage")
98101
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ require (
4242
github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.16.1-0.20241229121208-76ac3fea5e67
4343
github.com/threefoldtech/tfgrid4-sdk-go/node-registrar v0.0.0-20250506110945-e1591751c92f
4444
github.com/threefoldtech/zbus v1.0.1
45-
github.com/threefoldtech/zosbase v0.1.9
45+
github.com/threefoldtech/zosbase v0.1.10
4646
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa
4747
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852
4848
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,8 @@ github.com/threefoldtech/tfgrid4-sdk-go/node-registrar v0.0.0-20250506110945-e15
573573
github.com/threefoldtech/tfgrid4-sdk-go/node-registrar v0.0.0-20250506110945-e1591751c92f/go.mod h1:5p+3dprweeEymBRNCB8b8cdGmP36g9LGtf2wwqyqvFk=
574574
github.com/threefoldtech/zbus v1.0.1 h1:3KaEpyOiDYAw+lrAyoQUGIvY9BcjVRXlQ1beBRqhRNk=
575575
github.com/threefoldtech/zbus v1.0.1/go.mod h1:E/v/xEvG/l6z/Oj0aDkuSUXFm/1RVJkhKBwDTAIdsHo=
576-
github.com/threefoldtech/zosbase v0.1.9 h1:S0rB8sET5Afn/GIilU1DPLPf6uzC5sf0Ogs60FkQixY=
577-
github.com/threefoldtech/zosbase v0.1.9/go.mod h1:PzZ9jW1lYFgA0/F4vStP/6CIhQsCdD7DTrum3AYiAWA=
576+
github.com/threefoldtech/zosbase v0.1.10 h1:wRm0KLIjNUmfp92ZU/0xax/SbcFVtMIbmiHSAqFdX/w=
577+
github.com/threefoldtech/zosbase v0.1.10/go.mod h1:PzZ9jW1lYFgA0/F4vStP/6CIhQsCdD7DTrum3AYiAWA=
578578
github.com/tinylib/msgp v1.1.5 h1:2gXmtWueD2HefZHQe1QOy9HVzmFrLOVvsXwXBQ0ayy0=
579579
github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg=
580580
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=

tools/zos-update-worker/internal/worker_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ func TestWorker(t *testing.T) {
4141
})
4242

4343
t.Run("test_no_src_test", func(t *testing.T) {
44-
_, err := os.Create(src + "/zos:v3.4.0-qa1.flist")
44+
f, err := os.Create(src + "/zos:v3.4.0-qa1.flist")
4545
if err != nil {
4646
t.Error(err)
4747
}
48+
defer f.Close()
4849

4950
err = worker.updateZosVersion("testing", worker.clients["testing"])
5051
if err == nil {
@@ -53,10 +54,11 @@ func TestWorker(t *testing.T) {
5354
})
5455

5556
t.Run("test_no_src_main", func(t *testing.T) {
56-
_, err = os.Create(src + "/zos:v3.1.1-rc2.flist")
57+
f, err := os.Create(src + "/zos:v3.1.1-rc2.flist")
5758
if err != nil {
5859
t.Error(err)
5960
}
61+
defer f.Close()
6062

6163
err = worker.updateZosVersion("production", worker.clients["production"])
6264
if err == nil {

0 commit comments

Comments
 (0)