file

package
v6.2.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Glob

func Glob(pattern string, doubleStarPatternDepth uint8) ([]string, error)

Glob expands '**' patterns into multiple patterns to satisfy https://golang.org/pkg/path/filepath/#Match

func GlobPatterns

func GlobPatterns(pattern string, doubleStarPatternDepth uint8) ([]string, error)

GlobPatterns detects the use of "**" and expands it to standard glob patterns up to a max depth

func IsSameFile

func IsSameFile(path string, info os.FileInfo) bool

IsSameFile checks if the given File path corresponds with the FileInfo given

Types

type File

type File struct {
	File     *os.File
	FileInfo os.FileInfo
	Path     string
	State    *State
}

func (*File) IsSameFile

func (f *File) IsSameFile(f2 *File) bool

Checks if the two files are the same.

type State

type State struct {
	Id          string        `json:"-"` // local unique id to make comparison more efficient
	Finished    bool          `json:"-"` // harvester state
	Fileinfo    os.FileInfo   `json:"-"` // the file info
	Source      string        `json:"source"`
	Offset      int64         `json:"offset"`
	Timestamp   time.Time     `json:"timestamp"`
	TTL         time.Duration `json:"ttl"`
	Type        string        `json:"type"`
	FileStateOS file.StateOS
}

State is used to communicate the reading state of a file

func NewState

func NewState(fileInfo os.FileInfo, path string, t string) State

NewState creates a new file state

func (*State) ID

func (s *State) ID() string

ID returns a unique id for the state as a string

func (*State) IsEmpty

func (s *State) IsEmpty() bool

IsEmpty returns true if the state is empty

func (*State) IsEqual

func (s *State) IsEqual(c *State) bool

IsEqual compares the state to an other state supporing stringer based on the unique string

type States

type States struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

States handles list of FileState. One must use NewStates to instantiate a file states regisry. Using the zero-value is not safe.

func NewStates

func NewStates() *States

NewStates generates a new states registry.

func (*States) Cleanup

func (s *States) Cleanup() (int, int)

Cleanup cleans up the state array. All states which are older then `older` are removed The number of states that were cleaned up and number of states that can be cleaned up in the future is returned.

func (*States) Copy

func (s *States) Copy() *States

Copy create a new copy of the states object

func (*States) Count

func (s *States) Count() int

Count returns number of states

func (*States) FindPrevious

func (s *States) FindPrevious(newState State) State

FindPrevious lookups a registered state, that matching the new state. Returns a zero-state if no match is found.

func (*States) GetStates

func (s *States) GetStates() []State

GetStates creates copy of the file states.

func (*States) SetStates

func (s *States) SetStates(states []State)

SetStates overwrites all internal states with the given states array

func (*States) Update

func (s *States) Update(newState State)

Update updates a state. If previous state didn't exist, new one is created

func (*States) UpdateWithTs

func (s *States) UpdateWithTs(newState State, ts time.Time)

UpdateWithTs updates a state, assigning the given timestamp. If previous state didn't exist, new one is created

Jump to

Keyboard shortcuts

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