This file is indexed.

/usr/share/gocode/src/github.com/constabulary/gb/internal/untar/untar_test.go is in golang-github-constabulary-gb-dev 0.4.4-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package untar

import (
	"compress/gzip"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"reflect"
	"testing"
)

func TestUntar(t *testing.T) {
	tests := []struct {
		desc string
		r    func(*testing.T) io.ReadCloser
		dest string
		want []string
	}{{
		desc: "a.tar.gz",
		r:    tgz("_testdata/a.tar.gz"),
		want: []string{
			".",
			"a",
			"a/a",
		},
	}, {
		desc: "errors.tar.gz",
		r:    tgz("_testdata/errors.tar.gz"),
		want: []string{
			".",
			"pkg-errors-805fb19",
			"pkg-errors-805fb19/.gitignore",
			"pkg-errors-805fb19/.travis.yml",
			"pkg-errors-805fb19/LICENSE",
			"pkg-errors-805fb19/README.md",
			"pkg-errors-805fb19/appveyor.yml",
			"pkg-errors-805fb19/errors.go",
			"pkg-errors-805fb19/errors_test.go",
			"pkg-errors-805fb19/example_test.go",
			"pkg-errors-805fb19/format_test.go",
			"pkg-errors-805fb19/stack.go",
			"pkg-errors-805fb19/stack_test.go",
		},
	}, {
		desc: "symlink.tar.gz",
		r:    tgz("_testdata/symlink.tar.gz"),
		want: []string{
			".",
			"symlink",
			"symlink/a",
			// no symlink/b
		},
	}}

	for _, tt := range tests {
		dest := tmpdir(t)
		defer os.RemoveAll(dest)
		r := tt.r(t)
		defer r.Close()
		err := Untar(dest, r)
		if err != nil {
			t.Error(err)
			continue
		}
		got := walkdir(t, dest)
		want := make([]string, len(tt.want))
		for i := range tt.want {
			want[i] = filepath.FromSlash(tt.want[i])
		}
		if !reflect.DeepEqual(got, want) {
			t.Errorf("%s: untar: expected %s, got %s", tt.desc, want, got)
		}
	}
}

func tmpdir(t *testing.T) string {
	dir, err := ioutil.TempDir("", ".test")
	if err != nil {
		t.Fatal(err)
	}
	return filepath.Join(dir, "dest")
}

func tgz(path string) func(t *testing.T) io.ReadCloser {
	return func(t *testing.T) io.ReadCloser {
		f, err := os.Open(path)
		if err != nil {
			t.Fatal(err)
		}
		r, err := gzip.NewReader(f)
		if err != nil {
			t.Fatal(err)
		}
		return r
	}
}

func walkdir(t *testing.T, root string) []string {
	var paths []string
	err := filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		path, err = filepath.Rel(root, path)
		paths = append(paths, path)
		return err
	})
	if err != nil {
		t.Fatal(err)
	}
	return paths
}