filemod

package module
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: MIT Imports: 4 Imported by: 1

README

filemod

GoDoc Build Status Code Coverage Issues

Simple abstraction for comparing file timestamps - useful for tools that make decisions based on comparing modification times.

You can install it with:

go get github.com/rickb777/filemod

Documentation

Overview

package filemod makes it easier to handle file modification times.

It provides tools for comparing the modification timestamps of files and of groups of files.

Lists of files can be sorted by modification time, by file size and by path order.

Lists of files can be partitioned into files, directories, and absent items.

Index

Constants

This section is empty.

Variables

View Source
var Debug = func(message string, args ...interface{}) {}

Debug is a function that prints trace information. By default it does nothing; set it to (e.g.) 'fmt.Printf' to enable messages.

Functions

This section is empty.

Types

type Errors

type Errors []error

Errors holds a slice of errors and is itself an error.

func (Errors) Error

func (ee Errors) Error() string

Error gets the error string, built from each error conjoined with a newline.

type FileMetaInfo

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

FileMetaInfo holds information about one file (which may not exist).

func Lstat added in v0.7.0

func Lstat(path string) FileMetaInfo

Lstat tests a file path using the operating system. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link.

func Stat

func Stat(path string) FileMetaInfo

Stat tests a file path using the operating system.

func (FileMetaInfo) Err

func (file FileMetaInfo) Err() error

Err gets the error, if any, from Stat. If there is an error, it will be of type *os.PathError.

func (FileMetaInfo) Exists

func (file FileMetaInfo) Exists() bool

Tests whether the file exists.

func (FileMetaInfo) IsDir

func (file FileMetaInfo) IsDir() bool

func (FileMetaInfo) ModTime

func (file FileMetaInfo) ModTime() time.Time

func (FileMetaInfo) Mode

func (file FileMetaInfo) Mode() os.FileMode

func (FileMetaInfo) Name

func (file FileMetaInfo) Name() string

func (FileMetaInfo) Newer added in v0.6.0

func (file FileMetaInfo) Newer(other FileMetaInfo) FileMetaInfo

Newer compares the modification timestamps and returns the file that is newer.

func (FileMetaInfo) NewerThan added in v0.6.0

func (file FileMetaInfo) NewerThan(other FileMetaInfo) bool

NewerThan compares the modification timestamps and returns true if this file is newer than the other.

func (FileMetaInfo) Older

func (file FileMetaInfo) Older(other FileMetaInfo) FileMetaInfo

Older compares the modification timestamps and returns the file that is older.

func (FileMetaInfo) OlderThan added in v0.6.0

func (file FileMetaInfo) OlderThan(other FileMetaInfo) bool

OlderThan compares the modification timestamps and returns true if this file is older than the other.

func (FileMetaInfo) Path

func (file FileMetaInfo) Path() string

Gets the file path.

func (FileMetaInfo) Refresh added in v0.7.0

func (file FileMetaInfo) Refresh() FileMetaInfo

Refresh queries the operating system for the status of the file again. A new FileMetaInfo is returned that contains the current status of the file.

func (FileMetaInfo) Size

func (file FileMetaInfo) Size() int64

func (FileMetaInfo) Sys

func (file FileMetaInfo) Sys() interface{}

type Files

type Files []FileMetaInfo

Files holds data on a group of files. Use the builtin 'append' if required; also use slicing as required.

func New

func New(paths ...string) Files

New builds file information for one or more files. If filesystem errors arise, these are held in the files returned and can be inspected later.

func Of added in v0.6.0

func Of(files ...FileMetaInfo) Files

Of simply constructs a list of files. This is a convenience function.

func (Files) AbsentOnly added in v0.8.0

func (files Files) AbsentOnly() Files

AbsentOnly returns only those files/directories that don't exist.

func (Files) AllAreNewerThan added in v0.6.0

func (files Files) AllAreNewerThan(other Files) bool

AllAreNewerThan compares the file modification timestamps of two lists of files, returning true if all of 'files' are newer than all of 'other'.

func (Files) AllAreOlderThan added in v0.6.0

func (files Files) AllAreOlderThan(other Files) bool

AllAreOlderThan compares the file modification timestamps of two lists of files, returning true if all of 'files' are older than all of 'other'.

func (Files) DirectoriesOnly added in v0.8.0

func (files Files) DirectoriesOnly() Files

DirectoriesOnly returns only directories that exist.

func (Files) Errors

func (files Files) Errors() Errors

Errors gets any errors encountered when checking the files.

func (Files) FilesOnly added in v0.8.0

func (files Files) FilesOnly() Files

FilesOnly returns only files that exist (i.e. not directories).

func (Files) Filter added in v0.8.0

func (files Files) Filter(p func(info FileMetaInfo) bool) Files

Filter returns only those items for which a predicate p returns true.

func (Files) First added in v0.9.0

func (files Files) First() *FileMetaInfo

First returns the first file, equivalent to files[0] with a check for an empty slice.

func (Files) Last added in v0.9.0

func (files Files) Last() *FileMetaInfo

Last returns the last file, equivalent to files[n-1] with a check for an empty slice.

func (Files) OverlapsWith added in v0.6.0

func (files Files) OverlapsWith(other Files) bool

OverlapsWith compares the file modification timestamps of two lists of files, returning true if the range of modification times of 'files' overlaps with the range of modification times of the 'other' list.

func (Files) Partition

func (files Files) Partition() (allFiles, allDirs, absent Files)

Partition separates files and directories that exist from those that don't.

func (Files) PresentOnly added in v0.8.0

func (files Files) PresentOnly() Files

PresentOnly returns only those files/directories that exist.

func (Files) SortedByModTime added in v0.6.0

func (files Files) SortedByModTime() Files

SortedByModTime rearranges the files into modification-time order with the oldest first. It returns the modified list.

func (Files) SortedByPath added in v0.6.0

func (files Files) SortedByPath() Files

SortedByPath rearranges the files into path order, similar to comparing pairs of strings. It returns the modified list.

func (Files) SortedBySize added in v0.6.0

func (files Files) SortedBySize() Files

SortedBySize rearranges the files into size order. It returns the modified list.

Jump to

Keyboard shortcuts

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