From 9cf92c4916b080dd92a59b19f6cf85784df193a3 Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Wed, 13 Jan 2021 11:45:10 -0600 Subject: [PATCH] Removed some shadowed values (thanks gopls) --- file.go | 13 ++++++++----- go.mod | 3 ++- go.sum | 7 +++++-- reader.go | 12 ++++++++---- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/file.go b/file.go index 04fe3bd..608d80b 100644 --- a/file.go +++ b/file.go @@ -146,8 +146,8 @@ func (f *File) GetChildrenRecursively() (children []*File, err error) { errChan := make(chan error) for _, folds := range childFolders { go func(fil *File) { - childs, err := fil.GetChildrenRecursively() - errChan <- err + childs, childsErr := fil.GetChildrenRecursively() + errChan <- childsErr foldChil <- childs }(folds) } @@ -320,7 +320,8 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin errs = append(errs, err) return } - fil, err := os.Open(path + "/" + f.name) + var fil *os.File + fil, err = os.Open(path + "/" + f.name) if err != nil { if verbose { fmt.Println("Error while opening:", path+"/"+f.name) @@ -347,7 +348,8 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin errs = append(errs, err) } } - children, err := f.GetChildren() + var children []*File + children, err = f.GetChildren() if err != nil { if verbose { fmt.Println("Error getting children for:", f.Path()) @@ -371,7 +373,8 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin } return case f.IsFile(): - fil, err := os.Create(path + "/" + f.name) + var fil *os.File + fil, err = os.Create(path + "/" + f.name) if os.IsExist(err) { err = os.Remove(path + "/" + f.name) if err != nil { diff --git a/go.mod b/go.mod index d16b465..ddef52b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/CalebQ42/squashfs go 1.15 require ( - github.com/CalebQ42/GoAppImage v0.4.0 + github.com/CalebQ42/GoAppImage v0.5.0 github.com/adrg/xdg v0.2.3 // indirect github.com/google/go-cmp v0.5.4 // indirect github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect @@ -11,6 +11,7 @@ require ( github.com/kr/text v0.2.0 // indirect github.com/pierrec/lz4/v4 v4.1.3 github.com/smartystreets/assertions v1.2.0 // indirect + github.com/stretchr/testify v1.7.0 // indirect github.com/ulikunitz/xz v0.5.9 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/go.sum b/go.sum index 4f32dce..3611c48 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/CalebQ42/GoAppImage v0.4.0 h1:aF+Y/vyo/RGhoyZEW1CMY6WyRWrZZO4ydsRFAtIGnaY= -github.com/CalebQ42/GoAppImage v0.4.0/go.mod h1:qHudJKAn/dlkNWNnH4h1YKXp29EZ7Bppsn7sNP2HuvU= +github.com/CalebQ42/GoAppImage v0.5.0 h1:znoKNXtliH754tS9sYwyOIg/0wFDjFN5Twc7PAh1rSM= +github.com/CalebQ42/GoAppImage v0.5.0/go.mod h1:qHudJKAn/dlkNWNnH4h1YKXp29EZ7Bppsn7sNP2HuvU= github.com/adrg/xdg v0.2.2 h1:A7ZHKRz5KGOLJX/bg7IPzStryhvCzAE1wX+KWawPiAo= github.com/adrg/xdg v0.2.2/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ= github.com/adrg/xdg v0.2.3 h1:GxXngdYxNDkoUvZXjNJGwqZxWXi43MKbOOlA/00qZi4= @@ -39,9 +39,12 @@ github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I= github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= go.lsp.dev/uri v0.3.0 h1:KcZJmh6nFIBeJzTugn5JTU6OOyG0lDOo3R9KwTxTYbo= diff --git a/reader.go b/reader.go index 59cbf66..4446353 100644 --- a/reader.go +++ b/reader.go @@ -56,7 +56,8 @@ func NewSquashfsReader(r io.ReaderAt) (*Reader, error) { if rdr.flags.CompressorOptions { switch rdr.super.CompressionType { case GzipCompression: - gzip, err := compression.NewGzipCompressorWithOptions(io.NewSectionReader(rdr.r, int64(binary.Size(rdr.super)), 8)) + var gzip *compression.Gzip + gzip, err = compression.NewGzipCompressorWithOptions(io.NewSectionReader(rdr.r, int64(binary.Size(rdr.super)), 8)) if err != nil { return nil, err } @@ -65,7 +66,8 @@ func NewSquashfsReader(r io.ReaderAt) (*Reader, error) { } rdr.decompressor = gzip case XzCompression: - xz, err := compression.NewXzCompressorWithOptions(io.NewSectionReader(rdr.r, int64(binary.Size(rdr.super)), 8)) + var xz *compression.Xz + xz, err = compression.NewXzCompressorWithOptions(io.NewSectionReader(rdr.r, int64(binary.Size(rdr.super)), 8)) if err != nil { return nil, err } @@ -74,13 +76,15 @@ func NewSquashfsReader(r io.ReaderAt) (*Reader, error) { } rdr.decompressor = xz case Lz4Compression: - lz4, err := compression.NewLz4CompressorWithOptions(io.NewSectionReader(rdr.r, int64(binary.Size(rdr.super)), 8)) + var lz4 *compression.Lz4 + lz4, err = compression.NewLz4CompressorWithOptions(io.NewSectionReader(rdr.r, int64(binary.Size(rdr.super)), 8)) if err != nil { return nil, err } rdr.decompressor = lz4 case ZstdCompression: - zstd, err := compression.NewZstdCompressorWithOptions(io.NewSectionReader(rdr.r, int64(binary.Size(rdr.super)), 4)) + var zstd *compression.Zstd + zstd, err = compression.NewZstdCompressorWithOptions(io.NewSectionReader(rdr.r, int64(binary.Size(rdr.super)), 4)) if err != nil { return nil, err }