file

package
v5.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSameFile

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

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

func ReadOpen

func ReadOpen(path string) (*os.File, error)

ReadOpen opens a file for reading only

func SafeFileRotate

func SafeFileRotate(path, tempfile string) error

SafeFileRotate safely rotates an existing file under path and replaces it with the tempfile

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 {
	Source      string      `json:"source"`
	Offset      int64       `json:"offset"`
	Finished    bool        `json:"-"` // harvester state
	Fileinfo    os.FileInfo `json:"-"` // the file info
	FileStateOS StateOS
	Timestamp   time.Time     `json:"timestamp"`
	TTL         time.Duration `json:"ttl"`
}

State is used to communicate the reading state of a file

func NewState

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

NewState creates a new file state

func (*State) IsEmpty

func (s *State) IsEmpty() bool

IsEmpty returns true if the state is empty

type StateOS

type StateOS struct {
	Inode  uint64 `json:"inode,"`
	Device uint64 `json:"device,"`
}

func GetOSState

func GetOSState(info os.FileInfo) StateOS

GetOSState returns the FileStateOS for non windows systems

func (StateOS) IsSame

func (fs StateOS) IsSame(state StateOS) bool

IsSame file checks if the files are identical

type States

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

States handles list of FileState

func NewStates

func NewStates() *States

func (*States) Cleanup

func (s *States) Cleanup() int

Cleanup cleans up the state array. All states which are older then `older` are removed The number of states that were cleaned up 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

func (*States) GetStates

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

Returns a 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

Jump to

Keyboard shortcuts

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