util

package
v0.0.0-...-bf9e2ec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Copyright © 2018 Mephis Pheies <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2018 Mephis Pheies <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2018 Mephis Pheies <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2018 Mephis Pheies <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	PERM_OF_AUTO_CREATE_DIR os.FileMode = 0755
)

Variables

View Source
var (
	Debug   = Logger.Debug
	Debugf  = Logger.Debugf
	Debugln = Logger.Debugln

	Info   = Logger.Info
	Infof  = Logger.Infof
	Infoln = Logger.Infoln

	Warn   = Logger.Warn
	Warnf  = Logger.Warnf
	Warnln = Logger.Warnln

	Error   = Logger.Error
	Errorf  = Logger.Errorf
	Errorln = Logger.Errorln

	Fatal   = Logger.Fatal
	Fatalf  = Logger.Fatalf
	Fatalln = Logger.Fatalln

	Panic   = Logger.Panic
	Panicf  = Logger.Panicf
	Panicln = Logger.Panicln
)
View Source
var Logger = log.New()

Functions

func Check

func Check(checker IgnoreSupport, path string, info os.FileInfo) bool

Check calls each IsIgnore method of each IgnoreSupport in chain of repositories.

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies a file from src to dst. If src and dst files exist, and are the same, then return success. Otherise, copy the file contents from src to dst.

func HomeDir

func HomeDir() string

func IsDir

func IsDir(path string) bool

func IsNotExist

func IsNotExist(path string) bool

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile just keep the same style as WriteFile

func WriteFile

func WriteFile(path string, data []byte) error

WriteFile write data to file, and create its directories if necessary

Types

type BaseSupport

type BaseSupport struct {
	// contains filtered or unexported fields
}

BaseSupport implements almost methods of IgnoreSupport interface except `IsIgnore`. It should be embeded into a concrete IgnoreSupport.

func (*BaseSupport) Done

func (bs *BaseSupport) Done(path string, info os.FileInfo)

Done does nothing but implement IgnoreSupport interface

func (*BaseSupport) Fail

func (bs *BaseSupport) Fail(path string, info os.FileInfo)

Fail does nothing but implement IgnoreSupport interface

func (*BaseSupport) Next

func (bs *BaseSupport) Next() IgnoreSupport

Next return next.

func (*BaseSupport) SetName

func (bs *BaseSupport) SetName(n string)

SetName set n to name This method should only be used when concrete IgnoreSupport inits, so it is not a part of IgnoreSupport interface.

func (*BaseSupport) SetNext

func (bs *BaseSupport) SetNext(n IgnoreSupport) IgnoreSupport

SetNext assign another IgnoreSupport to inner next field. It is used to construct a chain of IgnoreSupports.

func (*BaseSupport) SetNexts

func (bs *BaseSupport) SetNexts(ns []IgnoreSupport) IgnoreSupport

SetNexts assign a IgnoreSupport link list to inner next field.

func (*BaseSupport) String

func (bs *BaseSupport) String() string

String describe the chain of IgnoreSupport

type GitIgnoreSupport

type GitIgnoreSupport struct {
	BaseSupport
	// contains filtered or unexported fields
}

func (*GitIgnoreSupport) IsIgnore

func (gis *GitIgnoreSupport) IsIgnore(path string, info os.FileInfo) (bool, error)

IsIgnore ...

type IgnoreDotSupport

type IgnoreDotSupport struct {
	BaseSupport
}

IgnoreDotSupport ignore all dot fies.

func (*IgnoreDotSupport) IsIgnore

func (ids *IgnoreDotSupport) IsIgnore(path string, info os.FileInfo) (bool, error)

IsIgnore ...

type IgnoreRegexpMatchSupport

type IgnoreRegexpMatchSupport struct {
	BaseSupport
	// contains filtered or unexported fields
}

func (*IgnoreRegexpMatchSupport) IsIgnore

func (irms *IgnoreRegexpMatchSupport) IsIgnore(path string, info os.FileInfo) (bool, error)

IsIgnore ...

type IgnoreSpecialMadeSupport

type IgnoreSpecialMadeSupport struct {
	BaseSupport
	// contains filtered or unexported fields
}

IgnoreSpecialMadeSupport ignore special type fies.

func (*IgnoreSpecialMadeSupport) IsIgnore

func (isms *IgnoreSpecialMadeSupport) IsIgnore(path string, info os.FileInfo) (bool, error)

IsIgnore ...

type IgnoreSupport

type IgnoreSupport interface {
	SetNext(IgnoreSupport) IgnoreSupport
	SetNexts([]IgnoreSupport) IgnoreSupport
	Next() IgnoreSupport
	String() string

	IsIgnore(path string, info os.FileInfo) (bool, error)
	Done(path string, info os.FileInfo)
	Fail(path string, info os.FileInfo)
}

IgnoreSupport is a part of abstract Support.

func NewGitIgnoreSupport

func NewGitIgnoreSupport(path string) (IgnoreSupport, error)

func NewIgnoreDotSupport

func NewIgnoreDotSupport() (IgnoreSupport, error)

func NewIgnoreRegexpMatchSupport

func NewIgnoreRegexpMatchSupport(expr string) (IgnoreSupport, error)

func NewIgnoreUnregularSupport

func NewIgnoreUnregularSupport() (IgnoreSupport, error)

func NewMultiIgnoreRegexpMatchSupports

func NewMultiIgnoreRegexpMatchSupports(exprs []string) ([]IgnoreSupport, error)

type Item

type Item struct {
	Err error

	Path string
}

Item is the subject passed in pipe by channel

type Walker

type Walker struct {
	// contains filtered or unexported fields
}

Walker walk the directory 'dir' to check each pathes of file undet it, then put path of valid file into pipe channel.

func NewWalker

func NewWalker(dir string, checker IgnoreSupport, cap int) *Walker

NewWalker read and collect files recursively under the dir Directory

func (Walker) Dir

func (w Walker) Dir() string

Dir return dir

func (Walker) Pipe

func (w Walker) Pipe() <-chan *Item

Pipe return single direction channel 'pipe'

func (*Walker) Walk

func (w *Walker) Walk() (err error)

Walk read and collect files recursively under the dir Directory

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL