1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-28 22:23:41 +00:00

vendor: switch to using go1.11 modules

This commit is contained in:
Nick Craig-Wood
2018-08-28 15:27:07 +01:00
parent 5c75453aba
commit da1682a30e
6142 changed files with 390 additions and 5155875 deletions

View File

@@ -1,197 +0,0 @@
package main
import (
"errors"
"flag"
"fmt"
"os"
"github.com/a8m/tree"
)
var (
// List
a = flag.Bool("a", false, "")
d = flag.Bool("d", false, "")
f = flag.Bool("f", false, "")
ignorecase = flag.Bool("ignore-case", false, "")
noreport = flag.Bool("noreport", false, "")
l = flag.Bool("l", false, "")
L = flag.Int("L", 3, "")
P = flag.String("P", "", "")
I = flag.String("I", "", "")
o = flag.String("o", "", "")
// Files
s = flag.Bool("s", false, "")
h = flag.Bool("h", false, "")
p = flag.Bool("p", false, "")
u = flag.Bool("u", false, "")
g = flag.Bool("g", false, "")
Q = flag.Bool("Q", false, "")
D = flag.Bool("D", false, "")
inodes = flag.Bool("inodes", false, "")
device = flag.Bool("device", false, "")
// Sort
U = flag.Bool("U", false, "")
v = flag.Bool("v", false, "")
t = flag.Bool("t", false, "")
c = flag.Bool("c", false, "")
r = flag.Bool("r", false, "")
dirsfirst = flag.Bool("dirsfirst", false, "")
sort = flag.String("sort", "", "")
// Graphics
i = flag.Bool("i", false, "")
C = flag.Bool("C", false, "")
)
var usage = `Usage: tree [options...] [paths...]
Options:
------- Listing options -------
-a All files are listed.
-d List directories only.
-l Follow symbolic links like directories.
-f Print the full path prefix for each file.
-L Descend only level directories deep.
-P List only those files that match the pattern given.
-I Do not list files that match the given pattern.
--ignore-case Ignore case when pattern matching.
--noreport Turn off file/directory count at end of tree listing.
-o filename Output to file instead of stdout.
-------- File options ---------
-Q Quote filenames with double quotes.
-p Print the protections for each file.
-u Displays file owner or UID number.
-g Displays file group owner or GID number.
-s Print the size in bytes of each file.
-h Print the size in a more human readable way.
-D Print the date of last modification or (-c) status change.
--inodes Print inode number of each file.
--device Print device ID number to which each file belongs.
------- Sorting options -------
-v Sort files alphanumerically by version.
-t Sort files by last modification time.
-c Sort files by last status change time.
-U Leave files unsorted.
-r Reverse the order of the sort.
--dirsfirst List directories before files (-U disables).
--sort X Select sort: name,version,size,mtime,ctime.
------- Graphics options ------
-i Don't print indentation lines.
-C Turn colorization on always.
`
type fs struct{}
func (f *fs) Stat(path string) (os.FileInfo, error) {
return os.Lstat(path)
}
func (f *fs) ReadDir(path string) ([]string, error) {
dir, err := os.Open(path)
if err != nil {
return nil, err
}
names, err := dir.Readdirnames(-1)
dir.Close()
if err != nil {
return nil, err
}
return names, nil
}
func main() {
flag.Usage = func() { fmt.Fprint(os.Stderr, usage) }
var nd, nf int
var dirs = []string{"."}
flag.Parse()
// Make it work with leading dirs
if args := flag.Args(); len(args) > 0 {
dirs = args
}
// Output file
var outFile = os.Stdout
var err error
if *o != "" {
outFile, err = os.Create(*o)
if err != nil {
errAndExit(err)
}
}
defer outFile.Close()
// Check sort-type
if *sort != "" {
switch *sort {
case "version", "mtime", "ctime", "name", "size":
default:
msg := fmt.Sprintf("sort type '%s' not valid, should be one of: "+
"name,version,size,mtime,ctime", *sort)
errAndExit(errors.New(msg))
}
}
// Set options
opts := &tree.Options{
// Required
Fs: new(fs),
OutFile: outFile,
// List
All: *a,
DirsOnly: *d,
FullPath: *f,
DeepLevel: *L,
FollowLink: *l,
Pattern: *P,
IPattern: *I,
IgnoreCase: *ignorecase,
// Files
ByteSize: *s,
UnitSize: *h,
FileMode: *p,
ShowUid: *u,
ShowGid: *g,
LastMod: *D,
Quotes: *Q,
Inodes: *inodes,
Device: *device,
// Sort
NoSort: *U,
ReverSort: *r,
DirSort: *dirsfirst,
VerSort: *v || *sort == "version",
ModSort: *t || *sort == "mtime",
CTimeSort: *c || *sort == "ctime",
NameSort: *sort == "name",
SizeSort: *sort == "size",
// Graphics
NoIndent: *i,
Colorize: *C,
}
for _, dir := range dirs {
inf := tree.New(dir)
d, f := inf.Visit(opts)
nd, nf = nd+d, nf+f
inf.Print(opts)
}
// Print footer report
if !*noreport {
footer := fmt.Sprintf("\n%d directories", nd)
if !opts.DirsOnly {
footer += fmt.Sprintf(", %d files", nf)
}
fmt.Fprintln(outFile, footer)
}
}
func usageAndExit(msg string) {
if msg != "" {
fmt.Fprintf(os.Stderr, msg)
fmt.Fprintf(os.Stderr, "\n\n")
}
flag.Usage()
fmt.Fprintf(os.Stderr, "\n")
os.Exit(1)
}
func errAndExit(err error) {
fmt.Fprintf(os.Stderr, "tree: \"%s\"\n", err)
os.Exit(1)
}

View File

@@ -1,53 +0,0 @@
package tree
import (
"os"
"syscall"
"testing"
)
var extsTests = []struct {
name string
expected string
}{
{"foo.jpg", "\x1b[1;35mfoo.jpg\x1b[0m"},
{"bar.tar", "\x1b[1;31mbar.tar\x1b[0m"},
{"baz.exe", "\x1b[1;32mbaz.exe\x1b[0m"},
}
func TestExtension(t *testing.T) {
for _, test := range extsTests {
fi := &file{name: test.name}
no := &Node{FileInfo: fi}
if actual := ANSIColor(no, fi.name); actual != test.expected {
t.Errorf("\ngot:\n%+v\nexpected:\n%+v", actual, test.expected)
}
}
}
var modeTests = []struct {
path string
name string
expected string
mode os.FileMode
}{
{"", "simple", "simple", os.FileMode(0)},
{"", "dir", "\x1b[1;34mdir\x1b[0m", os.ModeDir},
{"", "socket", "\x1b[40;1;35msocket\x1b[0m", os.ModeSocket},
{"", "fifo", "\x1b[40;33mfifo\x1b[0m", os.ModeNamedPipe},
{"", "block", "\x1b[40;1;33mblock\x1b[0m", os.ModeDevice},
{"", "char", "\x1b[40;1;33mchar\x1b[0m", os.ModeCharDevice},
{"", "exist-symlink", "\x1b[1;36mexist-symlink\x1b[0m", os.ModeSymlink},
{"fake-path-a8m", "fake-path", "\x1b[40;1;31mfake-path\x1b[0m", os.ModeSymlink},
{"", "exec", "\x1b[1;32mexec\x1b[0m", os.FileMode(syscall.S_IXUSR)},
}
func TestFileMode(t *testing.T) {
for _, test := range modeTests {
fi := &file{name: test.name, mode: test.mode}
no := &Node{FileInfo: fi, path: test.path}
if actual := ANSIColor(no, fi.name); actual != test.expected {
t.Errorf("\ngot:\n%+v\nexpected:\n%+v", actual, test.expected)
}
}
}

0
vendor/github.com/a8m/tree/compileall.sh generated vendored Executable file → Normal file
View File

View File

@@ -1,398 +0,0 @@
package tree
import (
"os"
"syscall"
"testing"
"time"
)
// Mock file/FileInfo
type file struct {
name string
size int64
files []*file
lastMod time.Time
stat interface{}
mode os.FileMode
}
func (f file) Name() string { return f.name }
func (f file) Size() int64 { return f.size }
func (f file) Mode() (o os.FileMode) {
if f.mode != o {
return f.mode
}
if f.stat != nil {
stat := (f.stat).(*syscall.Stat_t)
o = os.FileMode(stat.Mode)
}
return
}
func (f file) ModTime() time.Time { return f.lastMod }
func (f file) IsDir() bool { return nil != f.files }
func (f file) Sys() interface{} {
if f.stat == nil {
return new(syscall.Stat_t)
}
return f.stat
}
// Mock filesystem
type MockFs struct {
files map[string]*file
}
func NewFs() *MockFs {
return &MockFs{make(map[string]*file)}
}
func (fs *MockFs) clean() *MockFs {
fs.files = make(map[string]*file)
return fs
}
func (fs *MockFs) addFile(path string, file *file) *MockFs {
fs.files[path] = file
if file.IsDir() {
for _, f := range file.files {
fs.addFile(path+"/"+f.name, f)
}
}
return fs
}
func (fs *MockFs) Stat(path string) (os.FileInfo, error) {
return fs.files[path], nil
}
func (fs *MockFs) ReadDir(path string) ([]string, error) {
var names []string
for _, file := range fs.files[path].files {
names = append(names, file.Name())
}
return names, nil
}
// Mock output file
type Out struct {
str string
}
func (o *Out) equal(s string) bool {
return o.str == s
}
func (o *Out) Write(p []byte) (int, error) {
o.str += string(p)
return len(p), nil
}
func (o *Out) clear() {
o.str = ""
}
// FileSystem and Stdout mocks
var (
fs = NewFs()
out = new(Out)
)
type treeTest struct {
name string
opts *Options // test params.
expected string // expected output.
dirs int // expected dir count.
files int // expected file count.
}
var listTests = []treeTest{
{"basic", &Options{Fs: fs, OutFile: out}, `root
├── a
├── b
└── c
├── d
└── e
`, 1, 4},
{"all", &Options{Fs: fs, OutFile: out, All: true, NoSort: true}, `root
├── a
├── b
└── c
├── d
├── e
└── .f
`, 1, 5},
{"dirs", &Options{Fs: fs, OutFile: out, DirsOnly: true}, `root
└── c
`, 1, 0},
{"fullPath", &Options{Fs: fs, OutFile: out, FullPath: true}, `root
├── root/a
├── root/b
└── root/c
├── root/c/d
└── root/c/e
`, 1, 4},
{"deepLevel", &Options{Fs: fs, OutFile: out, DeepLevel: 1}, `root
├── a
├── b
└── c
`, 1, 2},
{"pattern", &Options{Fs: fs, OutFile: out, Pattern: "(a|e)"}, `root
├── a
└── c
└── e
`, 1, 2},
{"ipattern", &Options{Fs: fs, OutFile: out, IPattern: "(a|e)"}, `root
├── b
└── c
└── d
`, 1, 2},
{"ignore-case", &Options{Fs: fs, OutFile: out, Pattern: "(A)", IgnoreCase: true}, `root
├── a
└── c
`, 1, 1}}
func TestSimple(t *testing.T) {
root := &file{
name: "root",
size: 200,
files: []*file{
{name: "a", size: 50},
{name: "b", size: 50},
{
name: "c",
size: 100,
files: []*file{
{name: "d", size: 50},
{name: "e", size: 50},
{name: ".f", size: 0},
},
},
},
}
fs.clean().addFile(root.name, root)
for _, test := range listTests {
inf := New(root.name)
d, f := inf.Visit(test.opts)
if d != test.dirs {
t.Errorf("wrong dir count for test %q:\ngot:\n%d\nexpected:\n%d", test.name, d, test.dirs)
}
if f != test.files {
t.Errorf("wrong dir count for test %q:\ngot:\n%d\nexpected:\n%d", test.name, d, test.files)
}
inf.Print(test.opts)
if !out.equal(test.expected) {
t.Errorf("%s:\ngot:\n%+v\nexpected:\n%+v", test.name, out.str, test.expected)
}
out.clear()
}
}
var sortTests = []treeTest{
{"name-sort", &Options{Fs: fs, OutFile: out, NameSort: true}, `root
├── a
├── b
└── c
└── d
`, 1, 3},
{"dirs-first sort", &Options{Fs: fs, OutFile: out, DirSort: true}, `root
├── c
│ └── d
├── b
└── a
`, 1, 3},
{"reverse sort", &Options{Fs: fs, OutFile: out, ReverSort: true, DirSort: true}, `root
├── b
├── a
└── c
└── d
`, 1, 3},
{"no-sort", &Options{Fs: fs, OutFile: out, NoSort: true, DirSort: true}, `root
├── b
├── c
│ └── d
└── a
`, 1, 3},
{"size-sort", &Options{Fs: fs, OutFile: out, SizeSort: true}, `root
├── a
├── c
│ └── d
└── b
`, 1, 3},
{"last-mod-sort", &Options{Fs: fs, OutFile: out, ModSort: true}, `root
├── a
├── b
└── c
└── d
`, 1, 3},
{"c-time-sort", &Options{Fs: fs, OutFile: out, CTimeSort: true}, `root
├── b
├── c
│ └── d
└── a
`, 1, 3}}
func TestSort(t *testing.T) {
tFmt := "2006-Jan-02"
aTime, _ := time.Parse(tFmt, "2015-Aug-01")
bTime, _ := time.Parse(tFmt, "2015-Sep-01")
cTime, _ := time.Parse(tFmt, "2015-Oct-01")
root := &file{
name: "root",
size: 200,
files: []*file{
{name: "b", size: 11, lastMod: bTime},
{name: "c", size: 10, files: []*file{{name: "d", size: 10, lastMod: cTime}}, lastMod: cTime},
{name: "a", size: 9, lastMod: aTime},
},
}
fs.clean().addFile(root.name, root)
for _, test := range sortTests {
inf := New(root.name)
inf.Visit(test.opts)
inf.Print(test.opts)
if !out.equal(test.expected) {
t.Errorf("%s:\ngot:\n%+v\nexpected:\n%+v", test.name, out.str, test.expected)
}
out.clear()
}
}
var graphicTests = []treeTest{
{"no-indent", &Options{Fs: fs, OutFile: out, NoIndent: true}, `root
a
b
c
`, 0, 3},
{"quotes", &Options{Fs: fs, OutFile: out, Quotes: true}, `"root"
├── "a"
├── "b"
└── "c"
`, 0, 3},
{"byte-size", &Options{Fs: fs, OutFile: out, ByteSize: true}, `[ 12499] root
├── [ 1500] a
├── [ 9999] b
└── [ 1000] c
`, 0, 3},
{"unit-size", &Options{Fs: fs, OutFile: out, UnitSize: true}, `[ 12K] root
├── [1.5K] a
├── [9.8K] b
└── [1000] c
`, 0, 3},
{"show-gid", &Options{Fs: fs, OutFile: out, ShowGid: true}, `root
├── [1 ] a
├── [2 ] b
└── [1 ] c
`, 0, 3},
{"mode", &Options{Fs: fs, OutFile: out, FileMode: true}, `root
├── [-rw-r--r--] a
├── [-rwxr-xr-x] b
└── [-rw-rw-rw-] c
`, 0, 3},
{"lastMod", &Options{Fs: fs, OutFile: out, LastMod: true}, `root
├── [Feb 11 00:00] a
├── [Jan 28 00:00] b
└── [Jul 12 00:00] c
`, 0, 3}}
func TestGraphics(t *testing.T) {
tFmt := "2006-Jan-02"
aTime, _ := time.Parse(tFmt, "2015-Feb-11")
bTime, _ := time.Parse(tFmt, "2006-Jan-28")
cTime, _ := time.Parse(tFmt, "2015-Jul-12")
root := &file{
name: "root",
size: 11499,
files: []*file{
{name: "a", size: 1500, lastMod: aTime, stat: &syscall.Stat_t{Gid: 1, Mode: 0644}},
{name: "b", size: 9999, lastMod: bTime, stat: &syscall.Stat_t{Gid: 2, Mode: 0755}},
{name: "c", size: 1000, lastMod: cTime, stat: &syscall.Stat_t{Gid: 1, Mode: 0666}},
},
stat: &syscall.Stat_t{Gid: 1},
}
fs.clean().addFile(root.name, root)
for _, test := range graphicTests {
inf := New(root.name)
inf.Visit(test.opts)
inf.Print(test.opts)
if !out.equal(test.expected) {
t.Errorf("%s:\ngot:\n%+v\nexpected:\n%+v", test.name, out.str, test.expected)
}
out.clear()
}
}
var symlinkTests = []treeTest{
{"symlink", &Options{Fs: fs, OutFile: out}, `root
└── symlink -> root/symlink
`, 0, 1},
{"symlink-rec", &Options{Fs: fs, OutFile: out, FollowLink: true}, `root
└── symlink -> root/symlink [recursive, not followed]
`, 0, 1}}
func TestSymlink(t *testing.T) {
root := &file{
name: "root",
files: []*file{
&file{name: "symlink", mode: os.ModeSymlink, files: make([]*file, 0)},
},
}
fs.clean().addFile(root.name, root)
for _, test := range symlinkTests {
inf := New(root.name)
inf.Visit(test.opts)
inf.Print(test.opts)
if !out.equal(test.expected) {
t.Errorf("%s:\ngot:\n%+v\nexpected:\n%+v", test.name, out.str, test.expected)
}
out.clear()
}
}
func TestCount(t *testing.T) {
defer out.clear()
root := &file{
name: "root",
files: []*file{
&file{
name: "a",
files: []*file{
{
name: "b",
files: []*file{{name: "c"}},
},
{
name: "d",
files: []*file{
{
name: "e",
files: []*file{{name: "f"}, {name: "g"}},
},
},
},
{
name: "h",
files: []*file{
{
name: "i",
files: []*file{{name: "j"}},
},
{
name: "k",
files: []*file{{name: "l"}, {name: "m"}},
},
{name: "n"},
{name: "o"},
},
},
},
}},
}
fs.clean().addFile(root.name, root)
opt := &Options{Fs: fs, OutFile: out}
inf := New(root.name)
d, f := inf.Visit(opt)
if d != 7 || f != 8 {
inf.Print(opt)
t.Errorf("TestCount - expect (dir, file) count to be equal to (7, 8)\n%s", out.str)
}
}