files

package
v0.0.0-...-7578c0e Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMode = os.FileMode(0764)
View Source
const DefaultUploadTempFolder = "filepush"

Variables

This section is empty.

Functions

func ChangeOwner

func ChangeOwner(path, owner, group string) error

func ChangeOwnerExecWithSudo

func ChangeOwnerExecWithSudo(path, owner, group string) error

func GetFileUIDAndGID

func GetFileUIDAndGID(file string) (uid, gid uint32, err error)

func Md5HashFromReader

func Md5HashFromReader(source io.Reader) (hashSum []byte, err error)

func Md5HashMatch

func Md5HashMatch(expectedHashSum []byte, path string, fileAPI FileAPI) (match bool, err error)

func MoveExecWithSudo

func MoveExecWithSudo(sourcePath, targetPath string) error

func Rename

func Rename(oldPath, newPath string) error

Types

type FileAPI

type FileAPI interface {
	ReadDir(dir string) ([]os.FileInfo, error)
	MakeDirAll(dir string) error
	WriteJSON(file string, content interface{}) error
	Write(file string, content string) error
	ReadJSON(file string, dest interface{}) error
	Open(file string) (io.ReadWriteCloser, error)
	Exist(path string) (bool, error)
	CreateFile(path string, sourceReader io.Reader) (writtenBytes int64, err error)
	ChangeOwner(path, owner, group string) error
	ChangeMode(path string, targetMode os.FileMode) error
	CreateDirIfNotExists(path string, mode os.FileMode) (wasCreated bool, err error)
	Remove(name string) error
	Rename(oldPath, newPath string) error
	GetFileMode(file string) (os.FileMode, error)
	GetFileOwnerAndGroup(file string) (uid, gid uint32, err error)
}

type FileSystem

type FileSystem struct {
}

func NewFileSystem

func NewFileSystem() *FileSystem

func (*FileSystem) ChangeMode

func (f *FileSystem) ChangeMode(path string, targetMode os.FileMode) error

func (*FileSystem) ChangeOwner

func (f *FileSystem) ChangeOwner(path, owner, group string) error

func (*FileSystem) CreateDirIfNotExists

func (f *FileSystem) CreateDirIfNotExists(path string, mode os.FileMode) (wasCreated bool, err error)

func (*FileSystem) CreateFile

func (f *FileSystem) CreateFile(path string, sourceReader io.Reader) (writtenBytes int64, err error)

func (*FileSystem) Exist

func (f *FileSystem) Exist(path string) (bool, error)

Exist returns a boolean indicating whether a file or directory with a given path exists.

func (*FileSystem) GetFileMode

func (f *FileSystem) GetFileMode(file string) (os.FileMode, error)

func (*FileSystem) GetFileOwnerAndGroup

func (f *FileSystem) GetFileOwnerAndGroup(file string) (uid, gid uint32, err error)

func (*FileSystem) MakeDirAll

func (f *FileSystem) MakeDirAll(dir string) error

MakeDirAll creates a given directory along with any necessary parents. If path is already a directory, it does nothing and returns nil. It is created with mode 0777.

func (*FileSystem) Open

func (f *FileSystem) Open(file string) (io.ReadWriteCloser, error)

func (*FileSystem) ReadDir

func (f *FileSystem) ReadDir(dir string) ([]os.FileInfo, error)

ReadDir reads the given directory and returns a list of directory entries sorted by filename.

func (*FileSystem) ReadJSON

func (f *FileSystem) ReadJSON(file string, dest interface{}) error

ReadJSON reads a given file and stores the parsed content into a destination value. A successful call returns err == nil, not err == EOF.

func (*FileSystem) Remove

func (f *FileSystem) Remove(name string) error

func (*FileSystem) Rename

func (f *FileSystem) Rename(oldPath, newPath string) error

func (*FileSystem) Write

func (f *FileSystem) Write(fileName string, content string) error

Write creates or truncates a given file and writes a given content to it. If the file does not exist, it is created with mode 0666.

func (*FileSystem) WriteJSON

func (f *FileSystem) WriteJSON(fileName string, content interface{}) error

WriteJSON creates or truncates a given file and writes a given content to it as JSON with indentation. If the file does not exist, it is created with mode 0666.

Jump to

Keyboard shortcuts

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