fs

package
v0.0.0-...-a907d41 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package fs is an abstraction for needed filesystem operations.

Index

Constants

View Source
const (
	PathKey = "path"
)

Variables

View Source
var (
	// ErrIsDir communicates that we didn't expect a directory.
	ErrIsDir = errors.New("file is a directory")

	// ErrIsNotDir communicates that we expected a directory.
	ErrIsNotDir = errors.New("file is not directory")

	// ErrDirNotEmpty communicates that the directory isn't empty.
	ErrDirNotEmpty = errors.New("directory not empty")

	// ErrIsNotFile communicates that the operation only works on normal files.
	ErrIsNotFile = errors.New("file is not a normal file")
)

Functions

This section is empty.

Types

type FilesystemObject

type FilesystemObject struct {
	Path        string    `json:"path"`
	ContentType string    `json:"content_type"`
	Size        int64     `json:"size"`
	ModTime     time.Time `json:"mod_time"`
	IsDir       bool      `json:"is_dir"`

	Mode     os.FileMode         `json:"-"`
	Root     bool                `json:"-"`
	Children []*FilesystemObject `json:"-"`

	sync.Mutex
	// contains filtered or unexported fields
}

FilesystemObject is a representation of a filesystem object.

func NewFSObj

func NewFSObj(path string, info os.FileInfo, root bool, logger *zap.Logger) (*FilesystemObject, error)

NewFSObj create a new FileSystemObject

func ObjFromPath

func ObjFromPath(path string, root bool, logger *zap.Logger) (*FilesystemObject, error)

ObjFromPath stats a path and creates a FilesystemObject from it.

func (*FilesystemObject) Clean

func (fso *FilesystemObject) Clean() error

Clean cleans out all empty directories under the FSO.

func (*FilesystemObject) Delete

func (fso *FilesystemObject) Delete() error

func (*FilesystemObject) DetectContentType

func (fso *FilesystemObject) DetectContentType() error

DetectContentType detects the mimetype of

func (*FilesystemObject) GetAllFiles

func (fso *FilesystemObject) GetAllFiles() []*FilesystemObject

GetAllFiles gets all files in the children of the FilesystemObject

func (*FilesystemObject) IsEqual

func (fso *FilesystemObject) IsEqual(path string, size int64, modTime time.Time) bool

IsEqual deterimines if the FSO is the same as on disk. Just a quick check to see if the checsum needs to be updated.

func (*FilesystemObject) Open

func (fso *FilesystemObject) Open() (*os.File, error)

func (*FilesystemObject) Scan

func (fso *FilesystemObject) Scan() error

Scan recursively scans the directory and populates its children.

type Registry

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

Registry is a struct that keeps track of what paths we serve.

func NewRegistry

func NewRegistry(logger *zap.Logger) *Registry

NewRegistry returns a new Register instance.

func (*Registry) GetAllFiles

func (r *Registry) GetAllFiles() ([]*WebObject, error)

GetAllFiles simply returns a list of all files of all registered roots.

func (*Registry) Register

func (r *Registry) Register(servePath, diskPath string) error

Register registers a filesystem root and its corresponding URL path.

type WebObject

type WebObject struct {
	*FilesystemObject
	// WebPath is where the file is downloadable.
	WebPath string `json:"web_path"`
}

WebObject wraps a FSO, to add a webpath.

Jump to

Keyboard shortcuts

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