Documentation ¶
Overview ¶
Package mountfs defines a filesystem supporting the composition of multiple filesystems by mountpoints.
Index ¶
- Variables
- type MountFS
- func (fs MountFS) Lstat(name string) (os.FileInfo, error)
- func (fs MountFS) Mkdir(name string, perm os.FileMode) error
- func (fs *MountFS) Mount(mount vfs.Filesystem, path string) error
- func (fs MountFS) OpenFile(name string, flag int, perm os.FileMode) (vfs.File, error)
- func (fs MountFS) PathSeparator() uint8
- func (fs MountFS) ReadDir(path string) ([]os.FileInfo, error)
- func (fs MountFS) Remove(name string) error
- func (fs MountFS) Rename(oldpath, newpath string) error
- func (fs MountFS) Stat(name string) (os.FileInfo, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBoundary = errors.New("Crossing boundary")
ErrBoundary is returned if an operation can not act across filesystem boundaries.
Functions ¶
This section is empty.
Types ¶
type MountFS ¶
type MountFS struct {
// contains filtered or unexported fields
}
MountFS represents a filesystem build upon a root filesystem and multiple filesystems can be mounted inside it. In contrast to unix filesystems, the mount path may not be a directory or event exist.
Only filesystems with the same path separator are compatible. It's not possible to mount a specific source directory, only the root of the filesystem can be mounted, use a chroot in this case. The resulting filesystem is case-sensitive.
Example ¶
package main import ( "github.com/blang/vfs" "github.com/blang/vfs/memfs" "github.com/blang/vfs/mountfs" ) func main() { // Create a vfs supporting mounts // The root fs is accessing the filesystem of the underlying OS fs := mountfs.Create(vfs.OS()) // Mount a memfs inside /memfs // /memfs may not exist fs.Mount(memfs.Create(), "/memfs") // This will create /testdir inside the memfs fs.Mkdir("/memfs/testdir", 0777) // This will create /tmp/testdir inside your OS fs fs.Mkdir("/tmp/testdir", 0777) }
Output:
func Create ¶
func Create(rootFS vfs.Filesystem) *MountFS
Create a new MountFS based on a root filesystem.
func (*MountFS) Mount ¶
func (fs *MountFS) Mount(mount vfs.Filesystem, path string) error
Mount mounts a filesystem on the given path. Mounts inside mounts are supported, the longest path match will be taken. Mount paths may be overwritten if set on the same path. Path `/` can be used to change rootfs. Only absolute paths are allowed.
func (MountFS) OpenFile ¶
OpenFile find the mount of the given path and executes OpenFile on the corresponding filesystem. It wraps the resulting file to return the path inside mountfs on Name()
func (MountFS) PathSeparator ¶
PathSeparator returns the path separator
func (MountFS) ReadDir ¶
ReadDir reads the directory named by path and returns a list of sorted directory entries.