mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-24 00:55:41 +00:00
Merge pull request #196 from vbatts/golangci-lint
*.go: update to golangci-lint, and fix everything
This commit is contained in:
commit
732bc463ba
19 changed files with 101 additions and 78 deletions
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
|
@ -22,9 +22,9 @@ jobs:
|
||||||
go-version: ${{ matrix.go }}
|
go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: make
|
run: make build
|
||||||
|
|
||||||
- name: Test
|
- name: Validation
|
||||||
run: make validation
|
run: make validation
|
||||||
|
|
||||||
- name: Build.Arches
|
- name: Build.Arches
|
||||||
|
|
28
.github/workflows/validation.yml
vendored
Normal file
28
.github/workflows/validation.yml
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
name: lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go: ['1.21']
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
|
- name: Install tools
|
||||||
|
run: make install.tools
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: make lint
|
18
Makefile
18
Makefile
|
@ -11,7 +11,7 @@ GO_VER := go1.14
|
||||||
default: build validation
|
default: build validation
|
||||||
|
|
||||||
.PHONY: validation
|
.PHONY: validation
|
||||||
validation: .test .lint .vet .cli.test
|
validation: .test .vet .cli.test
|
||||||
|
|
||||||
.PHONY: validation.tags
|
.PHONY: validation.tags
|
||||||
validation.tags: .test.tags .vet.tags .cli.test .staticcheck
|
validation.tags: .test.tags .vet.tags .cli.test .staticcheck
|
||||||
|
@ -50,11 +50,7 @@ lint: .lint
|
||||||
CLEAN_FILES += .lint
|
CLEAN_FILES += .lint
|
||||||
|
|
||||||
.lint: $(SOURCE_FILES)
|
.lint: $(SOURCE_FILES)
|
||||||
@if [ "$(findstring $(GO_VER),$(shell go version))" != "" ] ; then \
|
set -e ; golangci-lint run && touch $@
|
||||||
set -e ; for dir in $(NO_VENDOR_DIR) ; do golint -set_exit_status $$dir ; done && touch $@ \
|
|
||||||
else \
|
|
||||||
touch $@ ; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
.PHONY: vet
|
.PHONY: vet
|
||||||
vet: .vet .vet.tags
|
vet: .vet .vet.tags
|
||||||
|
@ -85,12 +81,10 @@ $(BUILD): $(SOURCE_FILES)
|
||||||
go build -ldflags="-X 'main.Version=$(shell git describe --always --dirty)'" -mod=vendor -o $(BUILD) $(BUILDPATH)
|
go build -ldflags="-X 'main.Version=$(shell git describe --always --dirty)'" -mod=vendor -o $(BUILD) $(BUILDPATH)
|
||||||
|
|
||||||
install.tools:
|
install.tools:
|
||||||
@go install -u github.com/fatih/color@latest ; \
|
@go install github.com/fatih/color@latest ; \
|
||||||
go install -u github.com/fzipp/gocyclo/cmd/gocyclo@latest ; \
|
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest ; \
|
||||||
go install -u honnef.co/go/tools/cmd/staticcheck@latest ; \
|
go install honnef.co/go/tools/cmd/staticcheck@latest ; \
|
||||||
if [ "$(findstring $(GO_VER),$(shell go version))" != "" ] ; then \
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||||
go get -u golang.org/x/lint/golint ;\
|
|
||||||
fi
|
|
||||||
|
|
||||||
./bin:
|
./bin:
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
|
@ -2,7 +2,6 @@ package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -31,14 +30,14 @@ func TestCheck(t *testing.T) {
|
||||||
// only check again for size and sha1, and ignore time, and ensure it passes
|
// only check again for size and sha1, and ignore time, and ensure it passes
|
||||||
func TestCheckKeywords(t *testing.T) {
|
func TestCheckKeywords(t *testing.T) {
|
||||||
content := []byte("I know half of you half as well as I ought to")
|
content := []byte("I know half of you half as well as I ought to")
|
||||||
dir, err := ioutil.TempDir("", "test-check-keywords")
|
dir, err := os.MkdirTemp("", "test-check-keywords")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir) // clean up
|
defer os.RemoveAll(dir) // clean up
|
||||||
|
|
||||||
tmpfn := filepath.Join(dir, "tmpfile")
|
tmpfn := filepath.Join(dir, "tmpfile")
|
||||||
if err := ioutil.WriteFile(tmpfn, content, 0666); err != nil {
|
if err := os.WriteFile(tmpfn, content, 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +119,7 @@ func TestDefaultBrokenLink(t *testing.T) {
|
||||||
|
|
||||||
// https://github.com/vbatts/go-mtree/issues/8
|
// https://github.com/vbatts/go-mtree/issues/8
|
||||||
func TestTimeComparison(t *testing.T) {
|
func TestTimeComparison(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-time.")
|
dir, err := os.MkdirTemp("", "test-time.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -165,7 +164,7 @@ func TestTimeComparison(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTarTime(t *testing.T) {
|
func TestTarTime(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-tar-time.")
|
dir, err := os.MkdirTemp("", "test-tar-time.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -219,7 +218,7 @@ func TestTarTime(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIgnoreComments(t *testing.T) {
|
func TestIgnoreComments(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-comments.")
|
dir, err := os.MkdirTemp("", "test-comments.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -288,7 +287,7 @@ func TestIgnoreComments(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckNeedsEncoding(t *testing.T) {
|
func TestCheckNeedsEncoding(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-needs-encoding")
|
dir, err := os.MkdirTemp("", "test-needs-encoding")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -266,7 +265,7 @@ func validateAction(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
ts := mtree.NewTarStreamer(input, excludes, currentKeywords)
|
ts := mtree.NewTarStreamer(input, excludes, currentKeywords)
|
||||||
|
|
||||||
if _, err := io.Copy(ioutil.Discard, ts); err != nil && err != io.EOF {
|
if _, err := io.Copy(io.Discard, ts); err != nil && err != io.EOF {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := ts.Close(); err != nil {
|
if err := ts.Close(); err != nil {
|
||||||
|
@ -344,8 +343,8 @@ func validateAction(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// output stateDh
|
// output stateDh
|
||||||
stateDh.WriteTo(fh)
|
_, err = stateDh.WriteTo(fh)
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// no spec manifest has been provided yet, so look for it on stdin
|
// no spec manifest has been provided yet, so look for it on stdin
|
||||||
|
@ -358,7 +357,8 @@ func validateAction(c *cli.Context) error {
|
||||||
|
|
||||||
// We can't check against more fields than in the specKeywords list, so
|
// We can't check against more fields than in the specKeywords list, so
|
||||||
// currentKeywords can only have a subset of specKeywords.
|
// currentKeywords can only have a subset of specKeywords.
|
||||||
specKeywords = specDh.UsedKeywords()
|
// TODO this specKeywords is not even used
|
||||||
|
_ = specDh.UsedKeywords()
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a validation.
|
// This is a validation.
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -37,7 +36,7 @@ func TestCompare(t *testing.T) {
|
||||||
|
|
||||||
//gocyclo:ignore
|
//gocyclo:ignore
|
||||||
func TestCompareModified(t *testing.T) {
|
func TestCompareModified(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-compare-modified")
|
dir, err := os.MkdirTemp("", "test-compare-modified")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -45,7 +44,7 @@ func TestCompareModified(t *testing.T) {
|
||||||
|
|
||||||
// Create a bunch of objects.
|
// Create a bunch of objects.
|
||||||
tmpfile := filepath.Join(dir, "tmpfile")
|
tmpfile := filepath.Join(dir, "tmpfile")
|
||||||
if err := ioutil.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
|
if err := os.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +54,7 @@ func TestCompareModified(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
|
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
|
||||||
if err := ioutil.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
|
if err := os.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +65,7 @@ func TestCompareModified(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwrite the content in one of the files.
|
// Overwrite the content in one of the files.
|
||||||
if err := ioutil.WriteFile(tmpsubfile, []byte("modified content"), 0666); err != nil {
|
if err := os.WriteFile(tmpsubfile, []byte("modified content"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +116,7 @@ func TestCompareModified(t *testing.T) {
|
||||||
|
|
||||||
//gocyclo:ignore
|
//gocyclo:ignore
|
||||||
func TestCompareMissing(t *testing.T) {
|
func TestCompareMissing(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-compare-missing")
|
dir, err := os.MkdirTemp("", "test-compare-missing")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -125,7 +124,7 @@ func TestCompareMissing(t *testing.T) {
|
||||||
|
|
||||||
// Create a bunch of objects.
|
// Create a bunch of objects.
|
||||||
tmpfile := filepath.Join(dir, "tmpfile")
|
tmpfile := filepath.Join(dir, "tmpfile")
|
||||||
if err := ioutil.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
|
if err := os.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +134,7 @@ func TestCompareMissing(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
|
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
|
||||||
if err := ioutil.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
|
if err := os.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +208,7 @@ func TestCompareMissing(t *testing.T) {
|
||||||
|
|
||||||
//gocyclo:ignore
|
//gocyclo:ignore
|
||||||
func TestCompareExtra(t *testing.T) {
|
func TestCompareExtra(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-compare-extra")
|
dir, err := os.MkdirTemp("", "test-compare-extra")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -223,7 +222,7 @@ func TestCompareExtra(t *testing.T) {
|
||||||
|
|
||||||
// Create a bunch of objects.
|
// Create a bunch of objects.
|
||||||
tmpfile := filepath.Join(dir, "tmpfile")
|
tmpfile := filepath.Join(dir, "tmpfile")
|
||||||
if err := ioutil.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
|
if err := os.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +232,7 @@ func TestCompareExtra(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
|
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
|
||||||
if err := ioutil.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
|
if err := os.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +286,7 @@ func TestCompareExtra(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompareKeys(t *testing.T) {
|
func TestCompareKeys(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-compare-keys")
|
dir, err := os.MkdirTemp("", "test-compare-keys")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -295,7 +294,7 @@ func TestCompareKeys(t *testing.T) {
|
||||||
|
|
||||||
// Create a bunch of objects.
|
// Create a bunch of objects.
|
||||||
tmpfile := filepath.Join(dir, "tmpfile")
|
tmpfile := filepath.Join(dir, "tmpfile")
|
||||||
if err := ioutil.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
|
if err := os.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +304,7 @@ func TestCompareKeys(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
|
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
|
||||||
if err := ioutil.WriteFile(tmpsubfile, []byte("aaa"), 0666); err != nil {
|
if err := os.WriteFile(tmpsubfile, []byte("aaa"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +315,7 @@ func TestCompareKeys(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwrite the content in one of the files, but without changing the size.
|
// Overwrite the content in one of the files, but without changing the size.
|
||||||
if err := ioutil.WriteFile(tmpsubfile, []byte("bbb"), 0666); err != nil {
|
if err := os.WriteFile(tmpsubfile, []byte("bbb"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +342,7 @@ func TestCompareKeys(t *testing.T) {
|
||||||
|
|
||||||
//gocyclo:ignore
|
//gocyclo:ignore
|
||||||
func TestTarCompare(t *testing.T) {
|
func TestTarCompare(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-compare-tar")
|
dir, err := os.MkdirTemp("", "test-compare-tar")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -351,7 +350,7 @@ func TestTarCompare(t *testing.T) {
|
||||||
|
|
||||||
// Create a bunch of objects.
|
// Create a bunch of objects.
|
||||||
tmpfile := filepath.Join(dir, "tmpfile")
|
tmpfile := filepath.Join(dir, "tmpfile")
|
||||||
if err := ioutil.WriteFile(tmpfile, []byte("some content"), 0644); err != nil {
|
if err := os.WriteFile(tmpfile, []byte("some content"), 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +360,7 @@ func TestTarCompare(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
|
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
|
||||||
if err := ioutil.WriteFile(tmpsubfile, []byte("aaa"), 0644); err != nil {
|
if err := os.WriteFile(tmpsubfile, []byte("aaa"), 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +394,7 @@ func TestTarCompare(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
str := NewTarStreamer(bytes.NewBuffer(ts), nil, append(DefaultTarKeywords, "sha1"))
|
str := NewTarStreamer(bytes.NewBuffer(ts), nil, append(DefaultTarKeywords, "sha1"))
|
||||||
if _, err = io.Copy(ioutil.Discard, str); err != nil && err != io.EOF {
|
if _, err = io.Copy(io.Discard, str); err != nil && err != io.EOF {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err = str.Close(); err != nil {
|
if err = str.Close(); err != nil {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -73,7 +72,7 @@ func (fs *MockFsEval) KeywordFunc(fn KeywordFunc) KeywordFunc {
|
||||||
|
|
||||||
//gocyclo:ignore
|
//gocyclo:ignore
|
||||||
func TestCheckFsEval(t *testing.T) {
|
func TestCheckFsEval(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-check-fs-eval")
|
dir, err := os.MkdirTemp("", "test-check-fs-eval")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -81,7 +80,7 @@ func TestCheckFsEval(t *testing.T) {
|
||||||
|
|
||||||
content := []byte("If you hide your ignorance, no one will hit you and you'll never learn.")
|
content := []byte("If you hide your ignorance, no one will hit you and you'll never learn.")
|
||||||
tmpfn := filepath.Join(dir, "tmpfile")
|
tmpfn := filepath.Join(dir, "tmpfile")
|
||||||
if err := ioutil.WriteFile(tmpfn, content, 0451); err != nil {
|
if err := os.WriteFile(tmpfn, content, 0451); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
"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
|
//nolint:staticcheck // SA1019 yes ripemd160 is deprecated, but this is for mtree compatibility
|
||||||
"golang.org/x/crypto/ripemd160"
|
"golang.org/x/crypto/ripemd160"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package mtree
|
package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -21,7 +20,7 @@ func TestXattr(t *testing.T) {
|
||||||
// xattrs
|
// xattrs
|
||||||
testDir = "."
|
testDir = "."
|
||||||
}
|
}
|
||||||
dir, err := ioutil.TempDir(testDir, "test.xattrs.")
|
dir, err := os.MkdirTemp(testDir, "test.xattrs.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -30,8 +29,14 @@ func TestXattr(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
fh.WriteString("howdy")
|
_, err = fh.WriteString("howdy")
|
||||||
fh.Sync()
|
if err != nil {
|
||||||
|
t.Errorf("failed to write string: %s", err)
|
||||||
|
}
|
||||||
|
err = fh.Sync()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to sync file: %s", err)
|
||||||
|
}
|
||||||
if _, err := fh.Seek(0, 0); err != nil {
|
if _, err := fh.Seek(0, 0); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package mtree
|
package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ func TestParser(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i, err := dh.WriteTo(ioutil.Discard)
|
i, err := dh.WriteTo(io.Discard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
3
tar.go
3
tar.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -111,7 +110,7 @@ hdrloop:
|
||||||
// Because the content of the file may need to be read by several
|
// Because the content of the file may need to be read by several
|
||||||
// KeywordFuncs, it needs to be an io.Seeker as well. So, just reading from
|
// KeywordFuncs, it needs to be an io.Seeker as well. So, just reading from
|
||||||
// ts.tarReader is not enough.
|
// ts.tarReader is not enough.
|
||||||
tmpFile, err := ioutil.TempFile("", "ts.payload.")
|
tmpFile, err := os.CreateTemp("", "ts.payload.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ts.pipeReader.CloseWithError(err)
|
ts.pipeReader.CloseWithError(err)
|
||||||
return
|
return
|
||||||
|
|
13
tar_test.go
13
tar_test.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -62,7 +61,7 @@ func TestTar(t *testing.T) {
|
||||||
}
|
}
|
||||||
str := NewTarStreamer(fh, nil, append(DefaultKeywords, "sha1"))
|
str := NewTarStreamer(fh, nil, append(DefaultKeywords, "sha1"))
|
||||||
|
|
||||||
if _, err := io.Copy(ioutil.Discard, str); err != nil && err != io.EOF {
|
if _, err := io.Copy(io.Discard, str); err != nil && err != io.EOF {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := str.Close(); err != nil {
|
if err := str.Close(); err != nil {
|
||||||
|
@ -137,7 +136,7 @@ func TestArchiveCreation(t *testing.T) {
|
||||||
}
|
}
|
||||||
str := NewTarStreamer(fh, nil, []Keyword{"sha1"})
|
str := NewTarStreamer(fh, nil, []Keyword{"sha1"})
|
||||||
|
|
||||||
if _, err := io.Copy(ioutil.Discard, str); err != nil && err != io.EOF {
|
if _, err := io.Copy(io.Discard, str); err != nil && err != io.EOF {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := str.Close(); err != nil {
|
if err := str.Close(); err != nil {
|
||||||
|
@ -206,7 +205,7 @@ func TestTreeTraversal(t *testing.T) {
|
||||||
}
|
}
|
||||||
str := NewTarStreamer(fh, nil, DefaultTarKeywords)
|
str := NewTarStreamer(fh, nil, DefaultTarKeywords)
|
||||||
|
|
||||||
if _, err = io.Copy(ioutil.Discard, str); err != nil && err != io.EOF {
|
if _, err = io.Copy(io.Discard, str); err != nil && err != io.EOF {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err = str.Close(); err != nil {
|
if err = str.Close(); err != nil {
|
||||||
|
@ -258,7 +257,7 @@ func TestTreeTraversal(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
str = NewTarStreamer(fh, nil, DefaultTarKeywords)
|
str = NewTarStreamer(fh, nil, DefaultTarKeywords)
|
||||||
if _, err = io.Copy(ioutil.Discard, str); err != nil && err != io.EOF {
|
if _, err = io.Copy(io.Discard, str); err != nil && err != io.EOF {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err = str.Close(); err != nil {
|
if err = str.Close(); err != nil {
|
||||||
|
@ -297,7 +296,7 @@ func TestHardlinks(t *testing.T) {
|
||||||
}
|
}
|
||||||
str := NewTarStreamer(fh, nil, append(DefaultTarKeywords, "nlink"))
|
str := NewTarStreamer(fh, nil, append(DefaultTarKeywords, "nlink"))
|
||||||
|
|
||||||
if _, err = io.Copy(ioutil.Discard, str); err != nil && err != io.EOF {
|
if _, err = io.Copy(io.Discard, str); err != nil && err != io.EOF {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err = str.Close(); err != nil {
|
if err = str.Close(); err != nil {
|
||||||
|
@ -379,7 +378,7 @@ func TestArchiveExcludeNonDirectory(t *testing.T) {
|
||||||
}
|
}
|
||||||
str := NewTarStreamer(fh, []ExcludeFunc{ExcludeNonDirectories}, []Keyword{"type"})
|
str := NewTarStreamer(fh, []ExcludeFunc{ExcludeNonDirectories}, []Keyword{"type"})
|
||||||
|
|
||||||
if _, err := io.Copy(ioutil.Discard, str); err != nil && err != io.EOF {
|
if _, err := io.Copy(io.Discard, str); err != nil && err != io.EOF {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := str.Close(); err != nil {
|
if err := str.Close(); err != nil {
|
||||||
|
|
|
@ -32,5 +32,5 @@ func main() {
|
||||||
fmt.Fprintf(os.Stderr, red("%d FAILED tests\n"), failed)
|
fmt.Fprintf(os.Stderr, red("%d FAILED tests\n"), failed)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(os.Stdout, green("SUCCESS: no cli tests failed\n"))
|
fmt.Fprint(os.Stdout, green("SUCCESS: no cli tests failed\n"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/heap"
|
"container/heap"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
@ -23,7 +24,12 @@ func Update(root string, dh *DirectoryHierarchy, keywords []Keyword, fs FsEval)
|
||||||
creator := dhCreator{DH: dh}
|
creator := dhCreator{DH: dh}
|
||||||
curDir, err := os.Getwd()
|
curDir, err := os.Getwd()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer os.Chdir(curDir)
|
defer func() {
|
||||||
|
err := os.Chdir(curDir)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Warn(fmt.Errorf("failed to change directory to %q: %w", curDir, err))
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Chdir(root); err != nil {
|
if err := os.Chdir(root); err != nil {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -19,14 +18,14 @@ func TestXattrUpdate(t *testing.T) {
|
||||||
content := []byte("I know half of you half as well as I ought to")
|
content := []byte("I know half of you half as well as I ought to")
|
||||||
// a bit dirty to create/destroy a directory in cwd, but often /tmp is
|
// a bit dirty to create/destroy a directory in cwd, but often /tmp is
|
||||||
// mounted tmpfs and doesn't support xattrs
|
// mounted tmpfs and doesn't support xattrs
|
||||||
dir, err := ioutil.TempDir(".", "test.xattr.restore.")
|
dir, err := os.MkdirTemp(".", "test.xattr.restore.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir) // clean up
|
defer os.RemoveAll(dir) // clean up
|
||||||
|
|
||||||
tmpfn := filepath.Join(dir, "tmpfile")
|
tmpfn := filepath.Join(dir, "tmpfile")
|
||||||
if err := ioutil.WriteFile(tmpfn, content, 0666); err != nil {
|
if err := os.WriteFile(tmpfn, content, 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ package mtree
|
||||||
import (
|
import (
|
||||||
"container/heap"
|
"container/heap"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -24,14 +23,14 @@ func init() {
|
||||||
//gocyclo:ignore
|
//gocyclo:ignore
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
content := []byte("I know half of you half as well as I ought to")
|
content := []byte("I know half of you half as well as I ought to")
|
||||||
dir, err := ioutil.TempDir("", "test-check-keywords")
|
dir, err := os.MkdirTemp("", "test-check-keywords")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir) // clean up
|
defer os.RemoveAll(dir) // clean up
|
||||||
|
|
||||||
tmpfn := filepath.Join(dir, "tmpfile")
|
tmpfn := filepath.Join(dir, "tmpfile")
|
||||||
if err := ioutil.WriteFile(tmpfn, content, 0666); err != nil {
|
if err := os.WriteFile(tmpfn, content, 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package mtree
|
package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -13,7 +12,7 @@ func TestWalk(t *testing.T) {
|
||||||
}
|
}
|
||||||
numEntries := countTypes(dh)
|
numEntries := countTypes(dh)
|
||||||
|
|
||||||
fh, err := ioutil.TempFile("", "walk.")
|
fh, err := os.CreateTemp("", "walk.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ package xattr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -15,7 +14,7 @@ func TestXattr(t *testing.T) {
|
||||||
if present == false {
|
if present == false {
|
||||||
testDir = "."
|
testDir = "."
|
||||||
}
|
}
|
||||||
fh, err := ioutil.TempFile(testDir, "xattr.")
|
fh, err := os.CreateTemp(testDir, "xattr.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,12 @@ package xattr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestXattrUnsupported(t *testing.T) {
|
func TestXattrUnsupported(t *testing.T) {
|
||||||
fh, err := ioutil.TempFile(".", "xattr.")
|
fh, err := os.CreateTemp(".", "xattr.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue