fsgo

package module
v0.0.0-...-e16fd21 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

README

fsgo

Scope

A FileSystem Abstraction System for Go, based on the package Afero. This project is a subset of the functionality of Fsgo that eliminates the use of the crypto dependency. The Fsgo project includes concrete implementations of the abstraction that support multiple filesystems that are not needed for unit testing in a secure environment.

Fsgo is a filesystem framework providing a simple, uniform and universal API interacting with any filesystem, as an abstraction layer providing interfaces, types and methods. Fsgo has an exceptionally clean interface and simple design without needless constructors or initialization methods.

Fsgo is also a library providing a base set of interoperable backend filesystems that make it easy to work with fsgo while retaining all the power and benefit of the os and ioutil packages.

Fsgo provides significant improvements over using the os package alone, most notably the ability to create mock and testing filesystems without relying on the disk.

It is suitable for use in any situation where you would consider using the OS package as it provides an additional abstraction that makes it easy to use a memory backed file system during testing. It also adds support for the http filesystem for full interoperability.

Fsgo Features

  • A single consistent API for accessing a variety of filesystems
  • Interoperation between a variety of file system types
  • A set of interfaces to encourage and enforce interoperability between backends
  • An atomic cross platform memory backed file system
  • Support for compositional (union) file systems by combining multiple file systems acting as one
  • Specialized backends which modify existing filesystems (Read Only, Regexp filtered)
  • A set of utility functions ported from io, ioutil & hugo to be fsgo aware
  • Wrapper for go 1.16 filesystem abstraction io/fs.FS

Using Fsgo

Fsgo is easy to use and easier to adopt.

A few different ways you could use Fsgo:

  • Use the interfaces alone to define your own file system.
  • Wrapper for the OS packages.
  • Define different filesystems for different parts of your application.
  • Use Fsgo for mock filesystems while testing

Step 1: Install Fsgo

First use go get to install the latest version of the library.

$ go get github.com/IBM/fsgo

Next include Fsgo in your application.

import "github.com/IBM/fsgo"

Step 2: Declare a backend

First define a package variable and set it to a pointer to a filesystem.

var AppFs = fsgo.NewMemMapFs()

or

var AppFs = fsgo.NewOsFs()

It is important to note that if you repeat the composite literal you will be using a completely new and isolated filesystem. In the case of OsFs it will still use the same underlying filesystem but will reduce the ability to drop in other filesystems as desired.

Step 3: Use it like you would the OS package

Throughout your application use any function and method like you normally would.

So if my application before had:

os.Open("/tmp/foo")

We would replace it with:

AppFs.Open("/tmp/foo")

AppFs being the variable we defined above.

Notes

NOTE: This repository has been configured with the DCO bot. When you set up a new repository that uses the Apache license, you should use the DCO to manage contributions. The DCO bot will help enforce that. Please contact one of the IBM GH Org stewards.

If you have any questions or issues you can create a new [issue here][issues].

Pull requests are very welcome! Make sure your patches are well tested. Ideally create a topic branch for every separate change you make. For example:

  1. Fork the repo
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

All source files must include a Copyright and License header. The SPDX license header is preferred because it can be easily scanned.

If you would like to see the detailed LICENSE click here.

#
# Copyright 2020- IBM Inc. All rights reserved
# SPDX-License-Identifier: Apache2.0
#

Documentation

Overview

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>. Copyright 2013 tsuru authors. All rights reserved.

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com> Copyright 2013 tsuru authors. All rights reserved.

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Copyright 2022 IBM Inc. All rights reserved Copyright © 2014 Steve Francia <spf@spf13.com>

SPDX-License-Identifier: Apache2.0

Index

Constants

View Source
const BADFD = syscall.EBADF
View Source
const FilePathSeparator = string(filepath.Separator)

Filepath separator defined by os.Separator.

Variables

View Source
var (
	ErrFileClosed        = errors.New("File is closed")
	ErrOutOfRange        = errors.New("out of range")
	ErrTooLarge          = errors.New("too large")
	ErrFileNotFound      = os.ErrNotExist
	ErrFileExists        = os.ErrExist
	ErrDestinationExists = os.ErrExist
)
View Source
var ErrNoReadlink = errors.New("readlink not supported")

ErrNoReadlink is the error that will be wrapped in an os.Path if a file system does not support the readlink operation either directly or through its delegated filesystem. As expressed by support for the LinkReader interface.

View Source
var ErrNoSymlink = errors.New("symlink not supported")

ErrNoSymlink is the error that will be wrapped in an os.LinkError if a file system does not support Symlink's either directly or through its delegated filesystem. As expressed by support for the Linker interface.

Functions

func DirExists

func DirExists(fs Fs, path string) (bool, error)

DirExists checks if a path exists and is a directory.

func Exists

func Exists(fs Fs, path string) (bool, error)

Check if a file or directory exists.

func FileContainsAnyBytes

func FileContainsAnyBytes(fs Fs, filename string, subslices [][]byte) (bool, error)

Check if a file contains any of the specified byte slices.

func FileContainsBytes

func FileContainsBytes(fs Fs, filename string, subslice []byte) (bool, error)

Check if a file contains a specified byte slice.

func FullBaseFsPath

func FullBaseFsPath(basePathFs *BasePathFs, relativePath string) string

func GetTempDir

func GetTempDir(fs Fs, subPath string) string

GetTempDir returns the default temp directory with trailing slash if subPath is not empty then it will be created recursively with mode 777 rwx rwx rwx

func Glob

func Glob(fs Fs, pattern string) (matches []string, err error)

Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').

Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.

This was adapted from (http://golang.org/pkg/path/filepath) and uses several built-ins from that package.

func IsDir

func IsDir(fs Fs, path string) (bool, error)

IsDir checks if a given path is a directory.

func IsEmpty

func IsEmpty(fs Fs, path string) (bool, error)

IsEmpty checks if a given file or directory is empty.

func NeuterAccents

func NeuterAccents(s string) string

Transform characters with accents into plain forms.

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

ReadAll reads from r until an error or EOF and returns the data it read. A successful call returns err == nil, not err == EOF. Because ReadAll is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

func ReadDir

func ReadDir(fs Fs, dirname string) ([]os.FileInfo, error)

func ReadFile

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

func SafeWriteReader

func SafeWriteReader(fs Fs, path string, r io.Reader) (err error)

func TempDir

func TempDir(fs Fs, dir, prefix string) (name string, err error)

func UnicodeSanitize

func UnicodeSanitize(s string) string

Rewrite string to remove non-standard path characters

func Walk

func Walk(fs Fs, root string, walkFn filepath.WalkFunc) error

func WriteFile

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

func WriteReader

func WriteReader(fs Fs, path string, r io.Reader) (err error)

Types

type BasePathFile

type BasePathFile struct {
	File
	// contains filtered or unexported fields
}

func (*BasePathFile) Name

func (f *BasePathFile) Name() string

func (*BasePathFile) ReadDir

func (f *BasePathFile) ReadDir(n int) ([]fs.DirEntry, error)

type BasePathFs

type BasePathFs struct {
	// contains filtered or unexported fields
}

The BasePathFs restricts all operations to a given path within an Fs. The given file name to the operations on this Fs will be prepended with the base path before calling the base Fs. Any file name (after filepath.Clean()) outside this base path will be treated as non existing file.

Note that it does not clean the error messages on return, so you may reveal the real path on errors.

func (*BasePathFs) Chmod

func (b *BasePathFs) Chmod(name string, mode os.FileMode) (err error)

func (*BasePathFs) Chown

func (b *BasePathFs) Chown(name string, uid, gid int) (err error)

func (*BasePathFs) Chtimes

func (b *BasePathFs) Chtimes(name string, atime, mtime time.Time) (err error)

func (*BasePathFs) Create

func (b *BasePathFs) Create(name string) (f File, err error)

func (*BasePathFs) LstatIfPossible

func (b *BasePathFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (*BasePathFs) Mkdir

func (b *BasePathFs) Mkdir(name string, mode os.FileMode) (err error)

func (*BasePathFs) MkdirAll

func (b *BasePathFs) MkdirAll(name string, mode os.FileMode) (err error)

func (*BasePathFs) Name

func (b *BasePathFs) Name() string

func (*BasePathFs) Open

func (b *BasePathFs) Open(name string) (f File, err error)

func (*BasePathFs) OpenFile

func (b *BasePathFs) OpenFile(name string, flag int, mode os.FileMode) (f File, err error)

func (*BasePathFs) ReadlinkIfPossible

func (b *BasePathFs) ReadlinkIfPossible(name string) (string, error)

func (*BasePathFs) RealPath

func (b *BasePathFs) RealPath(name string) (path string, err error)

on a file outside the base path it returns the given file name and an error, else the given file with the base path prepended

func (*BasePathFs) Remove

func (b *BasePathFs) Remove(name string) (err error)

func (*BasePathFs) RemoveAll

func (b *BasePathFs) RemoveAll(name string) (err error)

func (*BasePathFs) Rename

func (b *BasePathFs) Rename(oldname, newname string) (err error)

func (*BasePathFs) Stat

func (b *BasePathFs) Stat(name string) (fi os.FileInfo, err error)

func (*BasePathFs) SymlinkIfPossible

func (b *BasePathFs) SymlinkIfPossible(oldname, newname string) error

type CopyOnWriteFs

type CopyOnWriteFs struct {
	// contains filtered or unexported fields
}

The CopyOnWriteFs is a union filesystem: a read only base file system with a possibly writeable layer on top. Changes to the file system will only be made in the overlay: Changing an existing file in the base layer which is not present in the overlay will copy the file to the overlay ("changing" includes also calls to e.g. Chtimes(), Chmod() and Chown()).

Reading directories is currently only supported via Open(), not OpenFile().

func (*CopyOnWriteFs) Chmod

func (u *CopyOnWriteFs) Chmod(name string, mode os.FileMode) error

func (*CopyOnWriteFs) Chown

func (u *CopyOnWriteFs) Chown(name string, uid, gid int) error

func (*CopyOnWriteFs) Chtimes

func (u *CopyOnWriteFs) Chtimes(name string, atime, mtime time.Time) error

func (*CopyOnWriteFs) Create

func (u *CopyOnWriteFs) Create(name string) (File, error)

func (*CopyOnWriteFs) LstatIfPossible

func (u *CopyOnWriteFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (*CopyOnWriteFs) Mkdir

func (u *CopyOnWriteFs) Mkdir(name string, perm os.FileMode) error

func (*CopyOnWriteFs) MkdirAll

func (u *CopyOnWriteFs) MkdirAll(name string, perm os.FileMode) error

func (*CopyOnWriteFs) Name

func (u *CopyOnWriteFs) Name() string

func (*CopyOnWriteFs) Open

func (u *CopyOnWriteFs) Open(name string) (File, error)

This function handles the 9 different possibilities caused by the union which are the intersection of the following...

layer: doesn't exist, exists as a file, and exists as a directory
base:  doesn't exist, exists as a file, and exists as a directory

func (*CopyOnWriteFs) OpenFile

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

func (*CopyOnWriteFs) ReadlinkIfPossible

func (u *CopyOnWriteFs) ReadlinkIfPossible(name string) (string, error)

func (*CopyOnWriteFs) Remove

func (u *CopyOnWriteFs) Remove(name string) error

Removing files present only in the base layer is not permitted. If a file is present in the base layer and the overlay, only the overlay will be removed.

func (*CopyOnWriteFs) RemoveAll

func (u *CopyOnWriteFs) RemoveAll(name string) error

func (*CopyOnWriteFs) Rename

func (u *CopyOnWriteFs) Rename(oldname, newname string) error

Renaming files present only in the base layer is not permitted

func (*CopyOnWriteFs) Stat

func (u *CopyOnWriteFs) Stat(name string) (os.FileInfo, error)

func (*CopyOnWriteFs) SymlinkIfPossible

func (u *CopyOnWriteFs) SymlinkIfPossible(oldname, newname string) error

type DirsMerger

type DirsMerger func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error)

DirsMerger is how UnionFile weaves two directories together. It takes the FileInfo slices from the layer and the base and returns a single view.

type File

type File interface {
	io.Closer
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Writer
	io.WriterAt

	Name() string
	Readdir(count int) ([]os.FileInfo, error)
	Readdirnames(n int) ([]string, error)
	Stat() (os.FileInfo, error)
	Sync() error
	Truncate(size int64) error
	WriteString(s string) (ret int, err error)
}

File represents a file in the filesystem.

func TempFile

func TempFile(fs Fs, dir, pattern string) (f File, err error)

type FromIOFS

type FromIOFS struct {
	fs.FS
}

FromIOFS adopts io/fs.FS to use it as fsgo.Fs Note that io/fs.FS is read-only so all mutating methods will return fs.PathError with fs.ErrPermission To store modifications you may use fsgo.CopyOnWriteFs

func (FromIOFS) Chmod

func (f FromIOFS) Chmod(name string, mode os.FileMode) error

func (FromIOFS) Chown

func (f FromIOFS) Chown(name string, uid, gid int) error

func (FromIOFS) Chtimes

func (f FromIOFS) Chtimes(name string, atime time.Time, mtime time.Time) error

func (FromIOFS) Create

func (f FromIOFS) Create(name string) (File, error)

func (FromIOFS) Mkdir

func (f FromIOFS) Mkdir(name string, perm os.FileMode) error

func (FromIOFS) MkdirAll

func (f FromIOFS) MkdirAll(path string, perm os.FileMode) error

func (FromIOFS) Name

func (f FromIOFS) Name() string

func (FromIOFS) Open

func (f FromIOFS) Open(name string) (File, error)

func (FromIOFS) OpenFile

func (f FromIOFS) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (FromIOFS) Remove

func (f FromIOFS) Remove(name string) error

func (FromIOFS) RemoveAll

func (f FromIOFS) RemoveAll(path string) error

func (FromIOFS) Rename

func (f FromIOFS) Rename(oldname, newname string) error

func (FromIOFS) Stat

func (f FromIOFS) Stat(name string) (os.FileInfo, error)

type Fs

type Fs interface {
	// Create creates a file in the filesystem, returning the file and an
	// error, if any happens.
	Create(name string) (File, error)

	// Mkdir creates a directory in the filesystem, return an error if any
	// happens.
	Mkdir(name string, perm os.FileMode) error

	// MkdirAll creates a directory path and all parents that does not exist
	// yet.
	MkdirAll(path string, perm os.FileMode) error

	// Open opens a file, returning it or an error, if any happens.
	Open(name string) (File, error)

	// OpenFile opens a file using the given flags and the given mode.
	OpenFile(name string, flag int, perm os.FileMode) (File, error)

	// Remove removes a file identified by name, returning an error, if any
	// happens.
	Remove(name string) error

	// RemoveAll removes a directory path and any children it contains. It
	// does not fail if the path does not exist (return nil).
	RemoveAll(path string) error

	// Rename renames a file.
	Rename(oldname, newname string) error

	// Stat returns a FileInfo describing the named file, or an error, if any
	// happens.
	Stat(name string) (os.FileInfo, error)

	// The name of this FileSystem
	Name() string

	// Chmod changes the mode of the named file to mode.
	Chmod(name string, mode os.FileMode) error

	// Chown changes the uid and gid of the named file.
	Chown(name string, uid, gid int) error

	//Chtimes changes the access and modification times of the named file
	Chtimes(name string, atime time.Time, mtime time.Time) error
}

Fs is the filesystem interface.

Any simulated or real filesystem should implement this interface.

func NewBasePathFs

func NewBasePathFs(source Fs, path string) Fs

func NewCopyOnWriteFs

func NewCopyOnWriteFs(base Fs, layer Fs) Fs

func NewMemMapFs

func NewMemMapFs() Fs

func NewOsFs

func NewOsFs() Fs

func NewReadOnlyFs

func NewReadOnlyFs(source Fs) Fs

type FsGo

type FsGo struct {
	Fs
}

func (FsGo) DirExists

func (a FsGo) DirExists(path string) (bool, error)

func (FsGo) Exists

func (a FsGo) Exists(path string) (bool, error)

func (FsGo) FileContainsAnyBytes

func (a FsGo) FileContainsAnyBytes(filename string, subslices [][]byte) (bool, error)

func (FsGo) FileContainsBytes

func (a FsGo) FileContainsBytes(filename string, subslice []byte) (bool, error)

func (FsGo) GetTempDir

func (a FsGo) GetTempDir(subPath string) string

func (FsGo) IsDir

func (a FsGo) IsDir(path string) (bool, error)

func (FsGo) IsEmpty

func (a FsGo) IsEmpty(path string) (bool, error)

func (FsGo) ReadDir

func (a FsGo) ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir reads the directory named by dirname and returns a list of sorted directory entries.

func (FsGo) ReadFile

func (a FsGo) ReadFile(filename string) ([]byte, error)

ReadFile reads the file named by filename and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.

func (FsGo) SafeWriteReader

func (a FsGo) SafeWriteReader(path string, r io.Reader) (err error)

Same as WriteReader but checks to see if file/directory already exists.

func (FsGo) TempDir

func (a FsGo) TempDir(dir, prefix string) (name string, err error)

TempDir creates a new temporary directory in the directory dir with a name beginning with prefix and returns the path of the new directory. If dir is the empty string, TempDir uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempDir simultaneously will not choose the same directory. It is the caller's responsibility to remove the directory when no longer needed.

func (FsGo) TempFile

func (a FsGo) TempFile(dir, pattern string) (f File, err error)

TempFile creates a new temporary file in the directory dir, opens the file for reading and writing, and returns the resulting *os.File. The filename is generated by taking pattern and adding a random string to the end. If pattern includes a "*", the random string replaces the last "*". If dir is the empty string, TempFile uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempFile simultaneously will not choose the same file. The caller can use f.Name() to find the pathname of the file. It is the caller's responsibility to remove the file when no longer needed.

func (FsGo) Walk

func (a FsGo) Walk(root string, walkFn filepath.WalkFunc) error

func (FsGo) WriteFile

func (a FsGo) WriteFile(filename string, data []byte, perm os.FileMode) error

WriteFile writes data to a file named by filename. If the file does not exist, WriteFile creates it with permissions perm; otherwise WriteFile truncates it before writing.

func (FsGo) WriteReader

func (a FsGo) WriteReader(path string, r io.Reader) (err error)

Takes a reader and a path and writes the content

type IOFS

type IOFS struct {
	Fs
}

IOFS adopts fsgo.Fs to stdlib io/fs.FS

func NewIOFS

func NewIOFS(fs Fs) IOFS

func (IOFS) Glob

func (iofs IOFS) Glob(pattern string) ([]string, error)

func (IOFS) Open

func (iofs IOFS) Open(name string) (fs.File, error)

func (IOFS) ReadDir

func (iofs IOFS) ReadDir(name string) ([]fs.DirEntry, error)

func (IOFS) ReadFile

func (iofs IOFS) ReadFile(name string) ([]byte, error)

func (IOFS) Sub

func (iofs IOFS) Sub(dir string) (fs.FS, error)

type LinkReader

type LinkReader interface {
	ReadlinkIfPossible(name string) (string, error)
}

LinkReader is an optional interface in Fsgo. It is only implemented by the filesystems saying so.

type Linker

type Linker interface {
	SymlinkIfPossible(oldname, newname string) error
}

Linker is an optional interface in Fsgo. It is only implemented by the filesystems saying so. It will call Symlink if the filesystem itself is, or it delegates to, the os filesystem, or the filesystem otherwise supports Symlink's.

type Lstater

type Lstater interface {
	LstatIfPossible(name string) (os.FileInfo, bool, error)
}

Lstater is an optional interface in Fsgo. It is only implemented by the filesystems saying so. It will call Lstat if the filesystem iself is, or it delegates to, the os filesystem. Else it will call Stat. In addtion to the FileInfo, it will return a boolean telling whether Lstat was called or not.

type MemMapFs

type MemMapFs struct {
	// contains filtered or unexported fields
}

func (*MemMapFs) Chmod

func (m *MemMapFs) Chmod(name string, mode os.FileMode) error

func (*MemMapFs) Chown

func (m *MemMapFs) Chown(name string, uid, gid int) error

func (*MemMapFs) Chtimes

func (m *MemMapFs) Chtimes(name string, atime time.Time, mtime time.Time) error

func (*MemMapFs) Create

func (m *MemMapFs) Create(name string) (File, error)

func (*MemMapFs) List

func (m *MemMapFs) List()

func (*MemMapFs) LstatIfPossible

func (m *MemMapFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (*MemMapFs) Mkdir

func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error

func (*MemMapFs) MkdirAll

func (m *MemMapFs) MkdirAll(path string, perm os.FileMode) error

func (*MemMapFs) Name

func (*MemMapFs) Name() string

func (*MemMapFs) Open

func (m *MemMapFs) Open(name string) (File, error)

func (*MemMapFs) OpenFile

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

func (*MemMapFs) Remove

func (m *MemMapFs) Remove(name string) error

func (*MemMapFs) RemoveAll

func (m *MemMapFs) RemoveAll(path string) error

func (*MemMapFs) Rename

func (m *MemMapFs) Rename(oldname, newname string) error

func (*MemMapFs) Stat

func (m *MemMapFs) Stat(name string) (os.FileInfo, error)

type OsFs

type OsFs struct{}

OsFs is a Fs implementation that uses functions provided by the os package.

For details in any method, check the documentation of the os package (http://golang.org/pkg/os/).

func (OsFs) Chmod

func (OsFs) Chmod(name string, mode os.FileMode) error

func (OsFs) Chown

func (OsFs) Chown(name string, uid, gid int) error

func (OsFs) Chtimes

func (OsFs) Chtimes(name string, atime time.Time, mtime time.Time) error

func (OsFs) Create

func (OsFs) Create(name string) (File, error)

func (OsFs) LstatIfPossible

func (OsFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (OsFs) Mkdir

func (OsFs) Mkdir(name string, perm os.FileMode) error

func (OsFs) MkdirAll

func (OsFs) MkdirAll(path string, perm os.FileMode) error

func (OsFs) Name

func (OsFs) Name() string

func (OsFs) Open

func (OsFs) Open(name string) (File, error)

func (OsFs) OpenFile

func (OsFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (OsFs) ReadlinkIfPossible

func (OsFs) ReadlinkIfPossible(name string) (string, error)

func (OsFs) Remove

func (OsFs) Remove(name string) error

func (OsFs) RemoveAll

func (OsFs) RemoveAll(path string) error

func (OsFs) Rename

func (OsFs) Rename(oldname, newname string) error

func (OsFs) Stat

func (OsFs) Stat(name string) (os.FileInfo, error)

func (OsFs) SymlinkIfPossible

func (OsFs) SymlinkIfPossible(oldname, newname string) error

type ReadOnlyFs

type ReadOnlyFs struct {
	// contains filtered or unexported fields
}

func (*ReadOnlyFs) Chmod

func (r *ReadOnlyFs) Chmod(n string, m os.FileMode) error

func (*ReadOnlyFs) Chown

func (r *ReadOnlyFs) Chown(n string, uid, gid int) error

func (*ReadOnlyFs) Chtimes

func (r *ReadOnlyFs) Chtimes(n string, a, m time.Time) error

func (*ReadOnlyFs) Create

func (r *ReadOnlyFs) Create(n string) (File, error)

func (*ReadOnlyFs) LstatIfPossible

func (r *ReadOnlyFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (*ReadOnlyFs) Mkdir

func (r *ReadOnlyFs) Mkdir(n string, p os.FileMode) error

func (*ReadOnlyFs) MkdirAll

func (r *ReadOnlyFs) MkdirAll(n string, p os.FileMode) error

func (*ReadOnlyFs) Name

func (r *ReadOnlyFs) Name() string

func (*ReadOnlyFs) Open

func (r *ReadOnlyFs) Open(n string) (File, error)

func (*ReadOnlyFs) OpenFile

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

func (*ReadOnlyFs) ReadDir

func (r *ReadOnlyFs) ReadDir(name string) ([]os.FileInfo, error)

func (*ReadOnlyFs) ReadlinkIfPossible

func (r *ReadOnlyFs) ReadlinkIfPossible(name string) (string, error)

func (*ReadOnlyFs) Remove

func (r *ReadOnlyFs) Remove(n string) error

func (*ReadOnlyFs) RemoveAll

func (r *ReadOnlyFs) RemoveAll(p string) error

func (*ReadOnlyFs) Rename

func (r *ReadOnlyFs) Rename(o, n string) error

func (*ReadOnlyFs) Stat

func (r *ReadOnlyFs) Stat(name string) (os.FileInfo, error)

func (*ReadOnlyFs) SymlinkIfPossible

func (r *ReadOnlyFs) SymlinkIfPossible(oldname, newname string) error

type Symlinker

type Symlinker interface {
	Lstater
	Linker
	LinkReader
}

Symlinker is an optional interface in Fsgo. It is only implemented by the filesystems saying so. It indicates support for 3 symlink related interfaces that implement the behaviors of the os methods:

  • Lstat
  • Symlink, and
  • Readlink

type UnionFile

type UnionFile struct {
	Base   File
	Layer  File
	Merger DirsMerger
	// contains filtered or unexported fields
}

The UnionFile implements the fsgo.File interface and will be returned when reading a directory present at least in the overlay or opening a file for writing.

The calls to Readdir() and Readdirnames() merge the file os.FileInfo / names from the base and the overlay - for files present in both layers, only those from the overlay will be used.

When opening files for writing (Create() / OpenFile() with the right flags) the operations will be done in both layers, starting with the overlay. A successful read in the overlay will move the cursor position in the base layer by the number of bytes read.

func (*UnionFile) Close

func (f *UnionFile) Close() error

func (*UnionFile) Name

func (f *UnionFile) Name() string

func (*UnionFile) Read

func (f *UnionFile) Read(s []byte) (int, error)

func (*UnionFile) ReadAt

func (f *UnionFile) ReadAt(s []byte, o int64) (int, error)

func (*UnionFile) Readdir

func (f *UnionFile) Readdir(c int) (ofi []os.FileInfo, err error)

Readdir will weave the two directories together and return a single view of the overlayed directories. At the end of the directory view, the error is io.EOF if c > 0.

func (*UnionFile) Readdirnames

func (f *UnionFile) Readdirnames(c int) ([]string, error)

func (*UnionFile) Seek

func (f *UnionFile) Seek(o int64, w int) (pos int64, err error)

func (*UnionFile) Stat

func (f *UnionFile) Stat() (os.FileInfo, error)

func (*UnionFile) Sync

func (f *UnionFile) Sync() (err error)

func (*UnionFile) Truncate

func (f *UnionFile) Truncate(s int64) (err error)

func (*UnionFile) Write

func (f *UnionFile) Write(s []byte) (n int, err error)

func (*UnionFile) WriteAt

func (f *UnionFile) WriteAt(s []byte, o int64) (n int, err error)

func (*UnionFile) WriteString

func (f *UnionFile) WriteString(s string) (n int, err error)

Directories

Path Synopsis
examples
mem
os
internal

Jump to

Keyboard shortcuts

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