fileutils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

package fileutils contains file manipulation functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir(file string) (string, error)

Dir returns the directory portion of the given file.

func NewChecker added in v0.2.0

func NewChecker() *checker

func NewCopier added in v0.2.0

func NewCopier(log io.Writer, checker Checker) *copier

func Read

func Read(file string, base string) ([]byte, error)

Read reads the contents of the specified file. If the file is a relative path, it is relative to base. Either file or base may be URLs.

Types

type Checker added in v0.2.0

type Checker interface {
	/*
		Tests the existence of a file or directory at a given path. Returns true if and only if the file or
		directory exists.
	*/
	Exists(path string) bool

	/*
		Filemode returns the os.FileMode of the file with the given path. If the file does not exist, returns
		an error with tag ErrFileNotFound.
	*/
	Filemode(path string) (os.FileMode, error)
}

Checker is a helper interface for querying files and directories.

type Copier added in v0.2.0

type Copier interface {
	/*
		Copy copies a source file to a destination file. File contents are copied. File mode and permissions
		(as described in http://golang.org/pkg/os/#FileMode) are copied.

		Directories are copied, along with their contents.

		Copying a file or directory to itself succeeds but does not modify the filesystem.

		Symbolic links are not followed and are copied provided they refer to a file or directory being copied
		(otherwise a non-nil error is returned). The only exception is copying a symbolic link to itself, which
		always succeeds.
	*/
	Copy(destPath string, srcPath string) error
}

Copier is a helper interface for copying files and/or directories.

type ErrorId added in v0.2.0

type ErrorId string
const (
	ErrOpeningSourceDir     ErrorId = "cannot open source directory"
	ErrCannotListSourceDir  ErrorId = "cannot list source directory"
	ErrUnexpected           ErrorId = "unexpected error"
	ErrCreatingTargetDir    ErrorId = "cannot create target directory"
	ErrOpeningSourceFile    ErrorId = "cannot open source file"
	ErrOpeningTargetFile    ErrorId = "cannot open target file"
	ErrCopyingFile          ErrorId = "file copy failed"
	ErrReadingSourceSymlink ErrorId = "cannot read symbolic link source"
	ErrWritingTargetSymlink ErrorId = "cannot write target symbolic link"
	ErrExternalSymlink      ErrorId = "external symbolic link"
)
const ErrFileNotFound ErrorId = "file not found"

type FileError added in v0.2.0

type FileError struct {
	ErrorId ErrorId
	Cause   error
}

func (FileError) Error added in v0.2.0

func (fe FileError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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