mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-21 16:05:40 +00:00
Merge pull request #177 from vbatts/lint
linting and adding check for staticcheck
This commit is contained in:
commit
b9356e6843
10 changed files with 23 additions and 45 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,4 +3,6 @@
|
||||||
.lint
|
.lint
|
||||||
.test
|
.test
|
||||||
.vet
|
.vet
|
||||||
|
.staticcheck
|
||||||
|
.gocyclo
|
||||||
gomtree
|
gomtree
|
||||||
|
|
11
Makefile
11
Makefile
|
@ -14,7 +14,7 @@ default: build validation
|
||||||
validation: .test .lint .vet .cli.test
|
validation: .test .lint .vet .cli.test
|
||||||
|
|
||||||
.PHONY: validation.tags
|
.PHONY: validation.tags
|
||||||
validation.tags: .test.tags .vet.tags .cli.test
|
validation.tags: .test.tags .vet.tags .cli.test .staticcheck
|
||||||
|
|
||||||
.PHONY: gocyclo
|
.PHONY: gocyclo
|
||||||
gocyclo: .gocyclo
|
gocyclo: .gocyclo
|
||||||
|
@ -24,6 +24,14 @@ CLEAN_FILES += .gocyclo
|
||||||
.gocyclo:
|
.gocyclo:
|
||||||
gocyclo -avg -over 15 -ignore 'vendor/*' . && touch $@
|
gocyclo -avg -over 15 -ignore 'vendor/*' . && touch $@
|
||||||
|
|
||||||
|
.PHONY: staticcheck
|
||||||
|
staticcheck: .staticcheck
|
||||||
|
|
||||||
|
CLEAN_FILES += .staticcheck
|
||||||
|
|
||||||
|
.staticcheck:
|
||||||
|
staticcheck . && touch $@
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: .test
|
test: .test
|
||||||
|
|
||||||
|
@ -79,6 +87,7 @@ $(BUILD): $(SOURCE_FILES)
|
||||||
install.tools:
|
install.tools:
|
||||||
@go install -u github.com/fatih/color@latest ; \
|
@go install -u github.com/fatih/color@latest ; \
|
||||||
go install -u github.com/fzipp/gocyclo/cmd/gocyclo@latest ; \
|
go install -u github.com/fzipp/gocyclo/cmd/gocyclo@latest ; \
|
||||||
|
go install -u honnef.co/go/tools/cmd/staticcheck@latest ; \
|
||||||
if [ "$(findstring $(GO_VER),$(shell go version))" != "" ] ; then \
|
if [ "$(findstring $(GO_VER),$(shell go version))" != "" ] ; then \
|
||||||
go get -u golang.org/x/lint/golint ;\
|
go get -u golang.org/x/lint/golint ;\
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -12,6 +12,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/vbatts/go-mtree/pkg/govis"
|
"github.com/vbatts/go-mtree/pkg/govis"
|
||||||
|
|
||||||
|
//lint:ignore SA1019 yes ripemd160 is deprecated, but this is for mtree compatibility
|
||||||
"golang.org/x/crypto/ripemd160"
|
"golang.org/x/crypto/ripemd160"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build linux
|
||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
package mtree
|
package mtree
|
||||||
|
@ -69,11 +70,11 @@ var (
|
||||||
}
|
}
|
||||||
xattrKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
|
xattrKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
|
||||||
if hdr, ok := info.Sys().(*tar.Header); ok {
|
if hdr, ok := info.Sys().(*tar.Header); ok {
|
||||||
if len(hdr.Xattrs) == 0 {
|
if len(hdr.PAXRecords) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
klist := []KeyVal{}
|
klist := []KeyVal{}
|
||||||
for k, v := range hdr.Xattrs {
|
for k, v := range hdr.PAXRecords {
|
||||||
encKey, err := govis.Vis(k, DefaultVisFlags)
|
encKey, err := govis.Vis(k, DefaultVisFlags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
@ -174,9 +174,7 @@ func keyValDifference(this, that []KeyVal) []KeyVal {
|
||||||
}
|
}
|
||||||
func keyValCopy(set []KeyVal) []KeyVal {
|
func keyValCopy(set []KeyVal) []KeyVal {
|
||||||
ret := make([]KeyVal, len(set))
|
ret := make([]KeyVal, len(set))
|
||||||
for i := range set {
|
copy(ret, set)
|
||||||
ret[i] = set[i]
|
|
||||||
}
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package mtree
|
package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -42,7 +41,7 @@ func TestXattr(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := xattr.Set(dir, "user.test", []byte("directory")); err != nil {
|
if err := xattr.Set(dir, "user.test", []byte("directory")); err != nil {
|
||||||
t.Skip(fmt.Sprintf("skipping: %q does not support xattrs", dir))
|
t.Skipf("skipping: %q does not support xattrs", dir)
|
||||||
}
|
}
|
||||||
if err := xattr.Set(filepath.Join(dir, "file"), "user.test", []byte("regular file")); err != nil {
|
if err := xattr.Set(filepath.Join(dir, "file"), "user.test", []byte("regular file")); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
26
tar.go
26
tar.go
|
@ -373,7 +373,6 @@ func flatten(root *Entry, creator *dhCreator, keywords []Keyword) {
|
||||||
}
|
}
|
||||||
creator.DH.Entries = append(creator.DH.Entries, dotEntry)
|
creator.DH.Entries = append(creator.DH.Entries, dotEntry)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveHardlinks goes through an Entry tree, and finds the Entry's associated
|
// resolveHardlinks goes through an Entry tree, and finds the Entry's associated
|
||||||
|
@ -409,31 +408,6 @@ func resolveHardlinks(root *Entry, hardlinks map[string][]string, countlinks boo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter takes in a pointer to an Entry, and returns a slice of Entry's that
|
|
||||||
// satisfy the predicate p
|
|
||||||
func filter(root *Entry, p func(*Entry) bool) []Entry {
|
|
||||||
if root != nil {
|
|
||||||
var validEntrys []Entry
|
|
||||||
if len(root.Children) > 0 || root.Prev != nil {
|
|
||||||
for _, c := range root.Children {
|
|
||||||
// filter the sub-directory
|
|
||||||
if c.Prev != nil {
|
|
||||||
validEntrys = append(validEntrys, filter(c, p)...)
|
|
||||||
}
|
|
||||||
if p(c) {
|
|
||||||
if c.Prev == nil {
|
|
||||||
validEntrys = append([]Entry{*c}, validEntrys...)
|
|
||||||
} else {
|
|
||||||
validEntrys = append(validEntrys, *c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return validEntrys
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ts *tarStream) setErr(err error) {
|
func (ts *tarStream) setErr(err error) {
|
||||||
ts.err = err
|
ts.err = err
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,12 +336,6 @@ type fakeFile struct {
|
||||||
Xattrs map[string]string
|
Xattrs map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// minimal tar archive that mimics what is in ./testdata/test.tar
|
|
||||||
var minimalFiles = []fakeFile{
|
|
||||||
{"x/", "", 0755, '5', 0, 0, nil},
|
|
||||||
{"x/files", "howdy\n", 0644, '0', 0, 0, nil},
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeTarStream(ff []fakeFile) ([]byte, error) {
|
func makeTarStream(ff []fakeFile) ([]byte, error) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -32,7 +31,7 @@ func TestXattrUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := xattr.Set(dir, "user.test", []byte("directory")); err != nil {
|
if err := xattr.Set(dir, "user.test", []byte("directory")); err != nil {
|
||||||
t.Skip(fmt.Sprintf("skipping: %q does not support xattrs", dir))
|
t.Skipf("skipping: %q does not support xattrs", dir)
|
||||||
}
|
}
|
||||||
if err := xattr.Set(tmpfn, "user.test", []byte("regular file")); err != nil {
|
if err := xattr.Set(tmpfn, "user.test", []byte("regular file")); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
6
walk.go
6
walk.go
|
@ -103,7 +103,7 @@ func Walk(root string, excludes []ExcludeFunc, keywords []Keyword, fsEval FsEval
|
||||||
}
|
}
|
||||||
keyFunc, ok := KeywordFuncs[keyword.Prefix()]
|
keyFunc, ok := KeywordFuncs[keyword.Prefix()]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Unknown keyword %q for file %q", keyword.Prefix(), path)
|
return fmt.Errorf("unknown keyword %q for file %q", keyword.Prefix(), path)
|
||||||
}
|
}
|
||||||
kvs, err := creator.fs.KeywordFunc(keyFunc)(path, info, r)
|
kvs, err := creator.fs.KeywordFunc(keyFunc)(path, info, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -138,7 +138,7 @@ func Walk(root string, excludes []ExcludeFunc, keywords []Keyword, fsEval FsEval
|
||||||
}
|
}
|
||||||
keyFunc, ok := KeywordFuncs[keyword.Prefix()]
|
keyFunc, ok := KeywordFuncs[keyword.Prefix()]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Unknown keyword %q for file %q", keyword.Prefix(), path)
|
return fmt.Errorf("unknown keyword %q for file %q", keyword.Prefix(), path)
|
||||||
}
|
}
|
||||||
kvs, err := creator.fs.KeywordFunc(keyFunc)(path, info, r)
|
kvs, err := creator.fs.KeywordFunc(keyFunc)(path, info, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -198,7 +198,7 @@ func Walk(root string, excludes []ExcludeFunc, keywords []Keyword, fsEval FsEval
|
||||||
}
|
}
|
||||||
keyFunc, ok := KeywordFuncs[keyword.Prefix()]
|
keyFunc, ok := KeywordFuncs[keyword.Prefix()]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Unknown keyword %q for file %q", keyword.Prefix(), path)
|
return fmt.Errorf("unknown keyword %q for file %q", keyword.Prefix(), path)
|
||||||
}
|
}
|
||||||
kvs, err := creator.fs.KeywordFunc(keyFunc)(path, info, r)
|
kvs, err := creator.fs.KeywordFunc(keyFunc)(path, info, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue