fs

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package fs is a collection of composable wrappers around the filesystem, useful for when a function accepts an interface rather than writing directly on the filesystem

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chroot

type Chroot struct {
	FS
	Base string
}

Chroot wraps a Filesystem interface modifying paths in order to constrain them to a specific directory

func (Chroot) Abs

func (c Chroot) Abs(name string) (string, error)

func (Chroot) Chmod

func (c Chroot) Chmod(name string, mode os.FileMode) error

func (Chroot) Chown

func (c Chroot) Chown(name string, uid, gid int) error

func (Chroot) Chtimes

func (c Chroot) Chtimes(name string, atime time.Time, mtime time.Time) error

func (Chroot) Create

func (c Chroot) Create(name string) (*os.File, error)

func (Chroot) Lchown

func (c Chroot) Lchown(name string, uid, gid int) error
func (c Chroot) Link(oldname, newname string) error

func (Chroot) Lstat

func (c Chroot) Lstat(name string) (os.FileInfo, error)

func (Chroot) Mkdir

func (c Chroot) Mkdir(name string, perm os.FileMode) error

func (Chroot) MkdirAll

func (c Chroot) MkdirAll(path string, perm os.FileMode) error

func (Chroot) NewFile

func (c Chroot) NewFile(fd uintptr, name string) *os.File

func (Chroot) Open

func (c Chroot) Open(name string) (*os.File, error)

func (Chroot) OpenFile

func (c Chroot) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
func (c Chroot) Readlink(name string) (string, error)

func (Chroot) Remove

func (c Chroot) Remove(name string) error

func (Chroot) RemoveAll

func (c Chroot) RemoveAll(path string) error

func (Chroot) Rename

func (c Chroot) Rename(oldpath, newpath string) error
func (c Chroot) Symlink(oldname, newname string) error

func (Chroot) Truncate

func (c Chroot) Truncate(name string, size int64) error

type FS

type FS interface {
	Chmod(name string, mode os.FileMode) error
	Chown(name string, uid, gid int) error
	Chtimes(name string, atime time.Time, mtime time.Time) error
	Create(name string) (*os.File, error)
	Lchown(name string, uid, gid int) error
	Link(oldname, newname string) error
	Lstat(name string) (os.FileInfo, error)
	Mkdir(name string, perm os.FileMode) error
	MkdirAll(path string, perm os.FileMode) error
	NewFile(fd uintptr, name string) *os.File
	Open(name string) (*os.File, error)
	OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
	Readlink(name string) (string, error)
	Remove(name string) error
	RemoveAll(path string) error
	Rename(oldpath, newpath string) error
	Symlink(oldname, newname string) error
	Truncate(name string, size int64) error
	// Abs returns an absolute representation of path
	Abs(path string) (string, error)
}

FS is the main interface that abstracts the os package functions that operate on files

type OS

type OS struct{}

OS is a wrapper around os package. Doesn't do anything fancy

func (OS) Abs

func (o OS) Abs(name string) (string, error)

func (OS) Chmod

func (o OS) Chmod(name string, mode os.FileMode) error

func (OS) Chown

func (o OS) Chown(name string, uid, gid int) error

func (OS) Chtimes

func (o OS) Chtimes(name string, atime time.Time, mtime time.Time) error

func (OS) Create

func (o OS) Create(name string) (*os.File, error)

func (OS) Lchown

func (o OS) Lchown(name string, uid, gid int) error
func (o OS) Link(oldname, newname string) error

func (OS) Lstat

func (o OS) Lstat(name string) (os.FileInfo, error)

func (OS) Mkdir

func (o OS) Mkdir(name string, perm os.FileMode) error

func (OS) MkdirAll

func (o OS) MkdirAll(path string, perm os.FileMode) error

func (OS) NewFile

func (o OS) NewFile(fd uintptr, name string) *os.File

func (OS) Open

func (o OS) Open(name string) (*os.File, error)

func (OS) OpenFile

func (o OS) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
func (o OS) Readlink(name string) (string, error)

func (OS) Remove

func (o OS) Remove(name string) error

func (OS) RemoveAll

func (o OS) RemoveAll(path string) error

func (OS) Rename

func (o OS) Rename(oldpath, newpath string) error
func (o OS) Symlink(oldname, newname string) error

func (OS) Truncate

func (o OS) Truncate(name string, size int64) error

type Spread

type Spread struct {
	FS
}

Spread wraps a filesystem and spreads files in directories accordin to their name in order not to have a single folder with millions of subdirectories. For example the filename test/banana will be spread in te/st/test/banana Make sure to have filenames longer than 4 characters, and to have filenames who can ensure a balanced distribution (eg with a random string in front) All functions will panic if the file is shorter than 4 characters

func (Spread) Abs

func (s Spread) Abs(path string) (string, error)

func (Spread) Chmod

func (s Spread) Chmod(name string, mode os.FileMode) error

func (Spread) Chown

func (s Spread) Chown(name string, uid, gid int) error

func (Spread) Chtimes

func (s Spread) Chtimes(name string, atime time.Time, mtime time.Time) error

func (Spread) Create

func (s Spread) Create(name string) (*os.File, error)

func (Spread) Lchown

func (s Spread) Lchown(name string, uid, gid int) error
func (s Spread) Link(oldname, newname string) error

func (Spread) Lstat

func (s Spread) Lstat(name string) (os.FileInfo, error)

func (Spread) Mkdir

func (s Spread) Mkdir(name string, perm os.FileMode) error

func (Spread) MkdirAll

func (s Spread) MkdirAll(path string, perm os.FileMode) error

func (Spread) NewFile

func (s Spread) NewFile(fd uintptr, name string) *os.File

func (Spread) Open

func (s Spread) Open(name string) (*os.File, error)

func (Spread) OpenFile

func (s Spread) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
func (s Spread) Readlink(name string) (string, error)

func (Spread) Remove

func (s Spread) Remove(name string) error

func (Spread) RemoveAll

func (s Spread) RemoveAll(path string) error

func (Spread) Rename

func (s Spread) Rename(oldpath, newpath string) error
func (s Spread) Symlink(oldname, newname string) error

func (Spread) Truncate

func (s Spread) Truncate(name string, size int64) error

Directories

Path Synopsis
Package fsutil builds on the underlying fs to add useful functions such as WriteFile or Walk
Package fsutil builds on the underlying fs to add useful functions such as WriteFile or Walk

Jump to

Keyboard shortcuts

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