Skip to content

Commit 1d0db42

Browse files
jayanthvnachevuruFernando Cainellidependabot[bot]
authored
Merge main to Release 1.0 (#74)
* Update mocks * Fix: nil pointer exception on `utils.IsfileExists` (#72) * fix: nil pointer exception * return an error from IsfileExists * fix: use error.Is * Bump golang.org/x/sys from 0.15.0 to 0.16.0 (#73) Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.15.0 to 0.16.0. - [Commits](golang/sys@v0.15.0...v0.16.0) --- updated-dependencies: - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix go mod tidy * fix go mod tidy --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Apurup Chevuru <[email protected]> Co-authored-by: Fernando Cainelli <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 29e0d43 commit 1d0db42

File tree

7 files changed

+33
-24
lines changed

7 files changed

+33
-24
lines changed

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/stretchr/testify v1.8.4
88
github.com/vishvananda/netlink v1.1.0
99
go.uber.org/zap v1.26.0
10-
golang.org/x/sys v0.15.0
10+
golang.org/x/sys v0.16.0
1111
gopkg.in/natefinch/lumberjack.v2 v2.2.1
1212
)
1313

@@ -16,8 +16,5 @@ require (
1616
github.com/pmezard/go-difflib v1.0.0 // indirect
1717
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df // indirect
1818
go.uber.org/multierr v1.10.0 // indirect
19-
golang.org/x/mod v0.4.2 // indirect
20-
golang.org/x/tools v0.1.1 // indirect
21-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
2219
gopkg.in/yaml.v3 v3.0.1 // indirect
2320
)

go.sum

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
44
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
55
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
66
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
87
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
98
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
109
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
@@ -19,7 +18,6 @@ go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
1918
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
2019
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
2120
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
22-
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
2321
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
2422
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
2523
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -32,18 +30,16 @@ golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7w
3230
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3331
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3432
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
35-
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
36-
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
33+
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
34+
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
3735
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
3836
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
3937
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
4038
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
4139
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
42-
golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
4340
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
4441
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
4542
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
46-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
4743
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
4844
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
4945
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

pkg/maps/loader.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,19 @@ func (m *BpfMap) PinMap(pinPath string, pinType uint32) error {
229229
if pinType == constdef.PIN_GLOBAL_NS.Index() {
230230

231231
//If pinPath is already present lets delete and create a new one
232-
if utils.IsfileExists(pinPath) {
232+
found, err := utils.IsfileExists(pinPath)
233+
if err != nil {
234+
return fmt.Errorf("unable to check file: %w", err)
235+
}
236+
if found {
233237
log.Infof("Found file %s so deleting the path", pinPath)
234238
err := utils.UnPinObject(pinPath)
235239
if err != nil {
236240
log.Errorf("failed to UnPinObject %v", err)
237241
return err
238242
}
239243
}
240-
err := os.MkdirAll(filepath.Dir(pinPath), 0755)
244+
err = os.MkdirAll(filepath.Dir(pinPath), 0755)
241245
if err != nil {
242246
log.Errorf("error creating directory %s: %v", filepath.Dir(pinPath), err)
243247
return fmt.Errorf("error creating directory %s: %v", filepath.Dir(pinPath), err)

pkg/progs/loader.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ func MountBpfFS() error {
143143
}
144144

145145
func (m *BpfProgram) PinProg(progFD uint32, pinPath string) error {
146-
147-
var err error
148-
if utils.IsfileExists(pinPath) {
146+
found, err := utils.IsfileExists(pinPath)
147+
if err != nil {
148+
return fmt.Errorf("unable to check file: %w", err)
149+
}
150+
if found {
149151
log.Infof("Found file %s so deleting the path", pinPath)
150152
err = utils.UnPinObject(pinPath)
151153
if err != nil {

pkg/utils/utils.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ package utils
1616

1717
import (
1818
"encoding/binary"
19+
"errors"
1920
"fmt"
21+
"io/fs"
2022
"math"
2123
"os"
2224
"runtime"
@@ -82,22 +84,30 @@ func PinObject(objFD uint32, pinPath string) error {
8284
return nil
8385
}
8486

85-
func IsfileExists(fname string) bool {
87+
func IsfileExists(fname string) (bool, error) {
8688
info, err := os.Stat(fname)
87-
if os.IsNotExist(err) {
88-
return false
89+
switch {
90+
case errors.Is(err, fs.ErrNotExist):
91+
return false, nil
92+
case err != nil:
93+
return false, fmt.Errorf("unexpected error stat %q: %w", fname, err)
94+
default:
95+
return !info.IsDir(), nil
8996
}
90-
return !info.IsDir()
9197
}
9298

9399
func UnPinObject(pinPath string) error {
94100
var log = logger.Get()
95-
if pinPath == "" || !IsfileExists(pinPath) {
101+
found, err := IsfileExists(pinPath)
102+
if err != nil {
103+
return fmt.Errorf("unable to check file: %w", err)
104+
}
105+
if pinPath == "" || !found {
96106
log.Infof("PinPath is empty or file doesn't exist")
97107
return nil
98108
}
99109

100-
err := os.Remove(pinPath)
110+
err = os.Remove(pinPath)
101111
if err != nil {
102112
log.Infof("File remove failed ", pinPath)
103113
return err

test/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/vishvananda/netns v0.0.4 // indirect
1515
go.uber.org/multierr v1.10.0 // indirect
1616
go.uber.org/zap v1.26.0 // indirect
17-
golang.org/x/sys v0.15.0 // indirect
17+
golang.org/x/sys v0.16.0 // indirect
1818
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
1919
)
2020

test/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
2121
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
2222
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2323
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
24-
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
25-
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
24+
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
25+
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
2626
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
2727
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
2828
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 commit comments

Comments
 (0)