mountfs

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2018 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package mountfs defines a filesystem supporting the composition of multiple filesystems by mountpoints.

Index

Examples

Constants

This section is empty.

Variables

View Source
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) Lstat

func (fs MountFS) Lstat(name string) (os.FileInfo, error)

Lstat returns the fileinfo of a file or link.

func (MountFS) Mkdir

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

Mkdir creates a directory

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

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

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

func (fs MountFS) PathSeparator() uint8

PathSeparator returns the path separator

func (MountFS) ReadDir

func (fs MountFS) ReadDir(path string) ([]os.FileInfo, error)

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

func (MountFS) Remove

func (fs MountFS) Remove(name string) error

Remove removes a file or directory

func (MountFS) Rename

func (fs MountFS) Rename(oldpath, newpath string) error

Rename renames a file. Renames across filesystems are not allowed.

func (MountFS) Stat

func (fs MountFS) Stat(name string) (os.FileInfo, error)

Stat returns the fileinfo of a file

Jump to

Keyboard shortcuts

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