fs

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package fs provides wrappers for os/fs dependent operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileInfo

type FileInfo interface {
	Name() string       // base name of the file
	Size() int64        // length in bytes for regular files; system-dependent for others
	Mode() os.FileMode  // file mode bits
	ModTime() time.Time // modification time
	IsDir() bool        // abbreviation for Mode().IsDir()
	Sys() interface{}   // underlying data source (can return nil)
}

A FileInfo describes a file and is returned by Stat and Lstat.

type Fs

type Fs struct {
	Util *gofsutil.FS
}

Fs implementation of FsInterface that uses default os/file calls

func (*Fs) Chmod added in v1.4.0

func (fs *Fs) Chmod(name string, perm os.FileMode) error

func (*Fs) Create

func (fs *Fs) Create(name string) (*os.File, error)

Create is a wrapper of os.Create

func (*Fs) ExecCommand

func (fs *Fs) ExecCommand(name string, args ...string) ([]byte, error)

ExecCommand is a wrapper of exec.Command that returns CombinedOutput

func (*Fs) ExecCommandOutput

func (fs *Fs) ExecCommandOutput(name string, args ...string) ([]byte, error)

ExecCommandOutput is a wrapper of exec.Command that returns default Output

func (*Fs) GetUtil

func (fs *Fs) GetUtil() UtilInterface

GetUtil returns gofsutil.fs wrapper -- UtilInterface.

func (*Fs) IsNotExist

func (fs *Fs) IsNotExist(err error) bool

IsNotExist is a wrapper of os.IsNotExist

func (*Fs) MkFileIdempotent

func (fs *Fs) MkFileIdempotent(path string) (bool, error)

MkFileIdempotent creates file if there is none

func (*Fs) Mkdir

func (fs *Fs) Mkdir(name string, perm os.FileMode) error

Mkdir is a wrapper of os.Mkdir

func (*Fs) MkdirAll

func (fs *Fs) MkdirAll(name string, perm os.FileMode) error

MkdirAll is a wrapper of os.MkdirAll

func (*Fs) NetDial

func (fs *Fs) NetDial(endpoint string) (net.Conn, error)

NetDial is a wrapper for net.Dial func. Uses UDP and 80 port.

func (*Fs) OpenFile

func (fs *Fs) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)

OpenFile is a wrapper of os.OpenFile

func (*Fs) ParseProcMounts

func (fs *Fs) ParseProcMounts(
	ctx context.Context,
	content io.Reader) ([]gofsutil.Info, error)

ParseProcMounts is wrapper of gofsutil.ReadProcMountsFrom global function

func (*Fs) ReadFile

func (fs *Fs) ReadFile(name string) ([]byte, error)

ReadFile is a wrapper of ioutil.ReadFile

func (*Fs) Remove

func (fs *Fs) Remove(name string) error

Remove is a wrapper of os.Remove

func (*Fs) RemoveAll

func (fs *Fs) RemoveAll(name string) error

RemoveAll is a wrapper of os.RemoveAll

func (*Fs) Stat

func (fs *Fs) Stat(name string) (FileInfo, error)

Stat is a wrapper of os.Stat

func (*Fs) WriteFile

func (fs *Fs) WriteFile(filename string, data []byte, perm os.FileMode) error

WriteFile is a wrapper of ioutil.WriteFile

func (*Fs) WriteString

func (fs *Fs) WriteString(file *os.File, string string) (int, error)

WriteString is a wrapper of file.WriteString

type FsInterface

type FsInterface interface {
	OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
	Stat(name string) (FileInfo, error)
	Create(name string) (*os.File, error)
	ReadFile(name string) ([]byte, error)
	WriteFile(filename string, data []byte, perm os.FileMode) error
	IsNotExist(err error) bool
	Mkdir(name string, perm os.FileMode) error
	MkdirAll(name string, perm os.FileMode) error
	Chmod(name string, perm os.FileMode) error
	Remove(name string) error
	RemoveAll(name string) error
	WriteString(file *os.File, str string) (int, error)
	ExecCommand(name string, args ...string) ([]byte, error)
	ExecCommandOutput(name string, args ...string) ([]byte, error)

	GetUtil() UtilInterface

	// wrapper
	ParseProcMounts(ctx context.Context, content io.Reader) ([]gofsutil.Info, error)
	MkFileIdempotent(path string) (bool, error)
	//Network
	NetDial(endpoint string) (net.Conn, error)
}

FsInterface wraps usual os and fs related calls so they can be mocked. Also FsInterface provides access to the gofsutil wrapper UtilInterface with GetUtil() method.

type UtilInterface

type UtilInterface interface {
	GetDiskFormat(ctx context.Context, disk string) (string, error)
	Format(ctx context.Context, source, target, fsType string, options ...string) error
	FormatAndMount(ctx context.Context, source, target, fsType string, options ...string) error
	Mount(ctx context.Context, source, target, fsType string, options ...string) error
	BindMount(ctx context.Context, source, target string, options ...string) error
	Unmount(ctx context.Context, target string) error
	GetMounts(ctx context.Context) ([]gofsutil.Info, error)
	GetDevMounts(ctx context.Context, dev string) ([]gofsutil.Info, error)
	ValidateDevice(ctx context.Context, source string) (string, error)
	WWNToDevicePath(ctx context.Context, wwn string) (string, string, error)
	RescanSCSIHost(ctx context.Context, targets []string, lun string) error
	RemoveBlockDevice(ctx context.Context, blockDevicePath string) error
	TargetIPLUNToDevicePath(ctx context.Context, targetIP string, lunID int) (map[string]string, error)
	MultipathCommand(ctx context.Context, timeoutSeconds time.Duration, chroot string, arguments ...string) ([]byte, error)
	GetFCHostPortWWNs(ctx context.Context) ([]string, error)
	IssueLIPToAllFCHosts(ctx context.Context) error
	GetSysBlockDevicesForVolumeWWN(ctx context.Context, volumeWWN string) ([]string, error)
	DeviceRescan(ctx context.Context, devicePath string) error
	ResizeFS(ctx context.Context, volumePath, devicePath, mpathDevice, fsType string) error
	GetMountInfoFromDevice(ctx context.Context, devID string) (*gofsutil.DeviceMountInfo, error)
	ResizeMultipath(ctx context.Context, deviceName string) error
	FindFSType(ctx context.Context, mountpoint string) (fsType string, err error)
	GetMpathNameFromDevice(ctx context.Context, device string) (string, error)
}

UtilInterface is a wrapper of gofsutil.fs functions so they can be mocked

Jump to

Keyboard shortcuts

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