file

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsZipPath

func IsZipPath(p string) bool

IsZipPath returns true if the path includes the zip separator byte, indicating it is within a zip file.

func ZipFilePath

func ZipFilePath(path string) (zipFilename, filename string)

func ZipFilename

func ZipFilename(zipFilename, filenameInZip string) string

func ZipPathDisplayName

func ZipPathDisplayName(path string) string

ZipPathDisplayName converts an zip path for display. It translates the zip file separator character into '/', since this character is also used for path separators within zip files. It returns the original provided path if it does not contain the zip file separator character.

Types

type Deleter added in v0.12.0

type Deleter struct {
	RenamerRemover RenamerRemover
	// contains filtered or unexported fields
}

Deleter is used to safely delete files and directories from the filesystem. During a transaction, files and directories are marked for deletion using the Files and Dirs methods. This will rename the files/directories to be deleted. If the transaction is rolled back, then the files/directories can be restored to their original state with the Abort method. If the transaction is committed, the marked files are then deleted from the filesystem using the Complete method.

func NewDeleter added in v0.12.0

func NewDeleter() *Deleter

func (*Deleter) Commit added in v0.12.0

func (d *Deleter) Commit()

Commit deletes all files marked for deletion and clears the marked list. Any errors encountered are logged. All files will be attempted, regardless of the errors encountered.

func (*Deleter) Dirs added in v0.12.0

func (d *Deleter) Dirs(paths []string) error

Dirs designates directories to be deleted. Each directory marked will be renamed to add a `.delete` suffix. An error is returned if a directory could not be renamed. Note that if an error is returned, then some directories may be left renamed. Abort should be called to restore marked files/directories if this function returns an error.

func (*Deleter) Files added in v0.12.0

func (d *Deleter) Files(paths []string) error

Files designates files to be deleted. Each file marked will be renamed to add a `.delete` suffix. An error is returned if a file could not be renamed. Note that if an error is returned, then some files may be left renamed. Abort should be called to restore marked files if this function returns an error.

func (*Deleter) Rollback added in v0.12.0

func (d *Deleter) Rollback()

Rollback tries to rename all marked files and directories back to their original names and clears the marked list. Any errors encountered are logged. All files will be attempted regardless of any errors occurred.

type FSHasher

type FSHasher struct{}

func (*FSHasher) MD5

func (h *FSHasher) MD5(src io.Reader) (string, error)

func (*FSHasher) OSHash

func (h *FSHasher) OSHash(src io.ReadSeeker, size int64) (string, error)

type FileBased

type FileBased interface {
	File() models.File
}

type Hasher

type Hasher interface {
	OSHash(src io.ReadSeeker, size int64) (string, error)
	MD5(src io.Reader) (string, error)
}

type RenamerRemover added in v0.12.0

type RenamerRemover interface {
	Rename(oldpath, newpath string) error
	Remove(name string) error
	RemoveAll(path string) error
	Stat(name string) (fs.FileInfo, error)
}

RenamerRemover provides access to the Rename and Remove functions.

type Scanned

type Scanned struct {
	Old *models.File
	New *models.File
}

func (Scanned) ContentsChanged

func (s Scanned) ContentsChanged() bool

ContentsChanged returns true if both old and new files are present and the file content is different.

func (Scanned) FileUpdated

func (s Scanned) FileUpdated() bool

FileUpdated returns true if both old and new files are present and not equal.

type Scanner

type Scanner struct {
	Hasher Hasher

	CalculateMD5    bool
	CalculateOSHash bool
}

func (Scanner) ScanExisting

func (o Scanner) ScanExisting(existing FileBased, file SourceFile) (h *Scanned, err error)

func (Scanner) ScanNew

func (o Scanner) ScanNew(file SourceFile) (*models.File, error)

type SourceFile

type SourceFile interface {
	Open() (io.ReadCloser, error)
	Path() string
	FileInfo() fs.FileInfo
}

func FSFile

func FSFile(path string, info fs.FileInfo) SourceFile

func ZipFile

func ZipFile(zipPath string, zf *zip.File) SourceFile

Jump to

Keyboard shortcuts

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