fshandler

package
v0.0.0-...-564440e Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadEntryType = errors.New("bad entry type")

Functions

func ConvertToLocal

func ConvertToLocal(path string) string

func GenerateFileName

func GenerateFileName(filesize int) string

GenerateFileName creates a filename matching the format expected by the Mensago platform

func GenerateTempFileName

func GenerateTempFileName() string

GenerateTempFileName creates a temporary file name. It is similar to an Mensago file name except that the file's size is not included.

func HashFile

func HashFile(path string, hash ezn.CryptoString) (bool, error)

HashFile performs a hash check on a file and determines if it matches or not. Note that this file only works on the local filesystem because it is expected to mostly operate on temp files. Temp files are initially stored in / tmp <wid>, so using a LocalMPath object will fail because LocalMPath expects to operate within a workspace. At the same time, using the Mensago formatting for a file path *is* expected.

func IsFileLocked

func IsFileLocked(filename string) (bool, error)

func LockFile

func LockFile(filename string) error

func RLockFile

func RLockFile(filename string) error

func RUnlockFile

func RUnlockFile(filename string) error

func UnlockFile

func UnlockFile(filename string) error

func ValidateFileName

func ValidateFileName(filename string) bool

ValidateFileName returns whether or not a filename conforms to the format expected by the platform

func ValidateMensagoPath

func ValidateMensagoPath(path string) bool

ValidateMensagoPath confirms the validity of an Mensago path

func ValidateTempFileName

func ValidateTempFileName(filename string) bool

ValidateTempFileName returns whether or not a filename for a temp file conforms to the format expected by the platform

Types

type LocalFSHandle

type LocalFSHandle struct {
	Path   string
	Handle *os.File
}

LocalFSHandle represents an open file and provides Open(), Read(), and Close() methods

type LocalFSHandler

type LocalFSHandler struct {
	BasePath      string
	PathSeparator string
	Files         map[string]LocalFSHandle
}

LocalFSHandler represents local storage on the server

func GetFSProvider

func GetFSProvider() *LocalFSHandler

GetFSProvider returns a new filesystem provider which interacts with the local filesystem. It obtains the necessary information about the local filesystem directly from the server configuration data.

func (*LocalFSHandler) CloseFile

func (lfs *LocalFSHandler) CloseFile(handle string) error

CloseFile closes the specified file handle. It is not normally needed unless Read() returns an error or the caller must abort reading the file.

func (*LocalFSHandler) CopyFile

func (lfs *LocalFSHandler) CopyFile(source string, dest string) (string, error)

CopyFile creates a duplicate of the specified source file in the specified destination folder and returns the name of the new file

func (*LocalFSHandler) DeleteFile

func (lfs *LocalFSHandler) DeleteFile(path string) error

DeleteFile deletes the specified workspace file.

func (*LocalFSHandler) DeleteTempFile

func (lfs *LocalFSHandler) DeleteTempFile(wid string, name string) error

DeleteTempFile deletes the specified temporary file.

func (*LocalFSHandler) Exists

func (lfs *LocalFSHandler) Exists(path string) (bool, error)

Exists checks to see if the specified path exists

func (*LocalFSHandler) GetDiskUsage

func (lfs *LocalFSHandler) GetDiskUsage(path string) (uint64, error)

GetDiskUsage calculates the disk usage of a workspace path

func (*LocalFSHandler) GetFileSize

func (lfs *LocalFSHandler) GetFileSize(path string) (int64, error)

func (*LocalFSHandler) InstallTempFile

func (lfs *LocalFSHandler) InstallTempFile(wid string, name string, dest string) (string, error)

InstallTempFile moves a file from the temporary file area to its location in a workspace

func (*LocalFSHandler) ListDirectories

func (lfs *LocalFSHandler) ListDirectories(path string) ([]string, error)

ListDirectories returns the names of all subdirectories of the specified path

func (*LocalFSHandler) ListFiles

func (lfs *LocalFSHandler) ListFiles(path string, afterTime int64) ([]string, error)

ListFiles returns all files in the specified path after the specified time. Note that the time is in UNIX time, i.e. seconds since the epoch. To return all files, pass a 0.

func (*LocalFSHandler) MakeDirectory

func (lfs *LocalFSHandler) MakeDirectory(path string) error

MakeDirectory creates a directory in the local filesystem relative to the workspace folder

func (*LocalFSHandler) MakeTempFile

func (lfs *LocalFSHandler) MakeTempFile(wid string) (*os.File, string, error)

MakeTempFile creates a file in the temporary file area and returns a handle to it. The caller is responsible for closing the handle when finished.

func (*LocalFSHandler) MoveFile

func (lfs *LocalFSHandler) MoveFile(source string, dest string) error

MoveFile moves the specified file to the specified directory. Note that dest MUST point to a directory.

func (*LocalFSHandler) OpenFile

func (lfs *LocalFSHandler) OpenFile(path string) (string, error)

OpenFile opens the specified file for reading data and returns a file handle as a string. The contents of the handle are specific to the provider and should not be expected to follow any particular format

func (*LocalFSHandler) OpenTempFile

func (lfs *LocalFSHandler) OpenTempFile(wid string, name string, offset int64) (*os.File, error)

OpenTempFile opens the specified temp file for reading or writing. If offset is >= 0, the read/write pointer is moved to the specified offset. A negative offset moves the read/write pointer to the end of the file. Attempting to open a nonexistent temp file will result in an error.

func (*LocalFSHandler) ReadFile

func (lfs *LocalFSHandler) ReadFile(handle string, buffer []byte) (int, error)

ReadFile reads data from a file opened with OpenFile. If the Read() call encounters the end of the file, less data than specified will be returned and the file handle will automatically be closed.

func (*LocalFSHandler) RemoveDirectory

func (lfs *LocalFSHandler) RemoveDirectory(path string, recursive bool) error

RemoveDirectory creates a directory in the local filesystem relative to the workspace folder

func (*LocalFSHandler) SeekFile

func (lfs *LocalFSHandler) SeekFile(handle string, offset int64) error

SeekFile performs a file pointer seek from the file's beginning. Unlike the os.Seek() function, SeekFile returns an error if a seek beyond the end of the file is requested

func (*LocalFSHandler) Select

func (lfs *LocalFSHandler) Select(path string) (LocalMPath, error)

Select confirms that the given path is a valid working directory for the user

type LocalMPath

type LocalMPath struct {
	// Path contains the path as formatted for the Mensago platform
	Path string

	// LocalPath holds the path as needed by the local filesystem
	LocalPath string
}

LocalMPath is an MPath interface that interacts with the local filesystem. It handles the operating system-specific path separators, among other things.

func (*LocalMPath) FromPath

func (ap *LocalMPath) FromPath(path MPath) error

FromPath assigns an Mensago path to the object

func (*LocalMPath) MensagoPath

func (ap *LocalMPath) MensagoPath() string

MensagoPath returns the Mensago path version of the path set

func (*LocalMPath) PathType

func (ap *LocalMPath) PathType() string

PathType returns the type of path handled

func (*LocalMPath) ProviderPath

func (ap *LocalMPath) ProviderPath() string

ProviderPath returns the local filesystem version of the path set

func (*LocalMPath) Set

func (ap *LocalMPath) Set(path string) error

Set assigns an Mensago path to the object

type MPath

type MPath interface {
	// PathType returns a string which indicates the kind of implementation the path object
	// handles. It is expected to be all lowercase. As with FSProvider, subtypes can be indicated
	// by a period separator.
	PathType() string

	// FromPath simply assigns to the object from the Mensago path of another
	FromPath(path MPath) error

	// Set expects an Mensago path. If the path is invalid or some other error occurs, the
	// object is not changed and the error is returned.
	Set(path string) error

	// ProviderPath returns a string which
	ProviderPath() string
	MensagoPath() string
}

MPath encapsulates all the translation between a standard Mensago path into whatever format a filesystem needs. These are leveraged by the filesytem providers to assist with going between the two realms

Jump to

Keyboard shortcuts

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