hugofs

package
v0.65.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: Apache-2.0 Imports: 27 Imported by: 242

Documentation

Overview

Package hugofs provides the file systems used by Hugo.

Package hugofs provides the file systems used by Hugo.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPermissionSymlink = errors.New("symlinks not allowed in this filesystem")
)
View Source
var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) {
	m := make(map[string]FileMetaInfo)

	getKey := func(fim FileMetaInfo) string {
		return path.Join(fim.Meta().Lang(), fim.Name())
	}

	for _, fi := range lofi {
		fim := fi.(FileMetaInfo)
		m[getKey(fim)] = fim
	}

	for _, fi := range bofi {
		fim := fi.(FileMetaInfo)
		key := getKey(fim)
		_, found := m[key]
		if !found {
			m[key] = fim
		}
	}

	merged := make([]os.FileInfo, len(m))
	i := 0
	for _, v := range m {
		merged[i] = v
		i++
	}

	return merged, nil
}

LanguageDirsMerger implements the afero.DirsMerger interface, which is used to merge two directories.

View Source
var (

	// NoOpFs provides a no-op filesystem that implements the afero.Fs
	// interface.
	NoOpFs = &noOpFs{}
)
View Source
var (
	// Os points to the (real) Os filesystem.
	Os = &afero.OsFs{}
)

Functions

func DecorateBasePathFs added in v0.56.0

func DecorateBasePathFs(base *afero.BasePathFs) afero.Fs

DecorateBasePathFs adds Path info to files and directories in the provided BasePathFs, using the base as base.

func Glob added in v0.57.0

func Glob(fs afero.Fs, pattern string, handle func(fi FileMetaInfo) (bool, error)) error

Glob walks the fs and passes all matches to the handle func. The handle func can return true to signal a stop.

func MakeReadableAndRemoveAllModulePkgDir added in v0.65.0

func MakeReadableAndRemoveAllModulePkgDir(fs afero.Fs, dir string) (int, error)

MakeReadableAndRemoveAllModulePkgDir makes any subdir in dir readable and then removes the root. TODO(bep) move this to a more suitable place.

func NewBaseFileDecorator added in v0.56.0

func NewBaseFileDecorator(fs afero.Fs, callbacks ...func(fi FileMetaInfo)) afero.Fs

NewBaseFileDecorator decorates the given Fs to provide the real filename and an Opener func.

func NewCreateCountingFs added in v0.55.0

func NewCreateCountingFs(fs afero.Fs) afero.Fs

func NewFilterFs added in v0.56.0

func NewFilterFs(fs afero.Fs) (afero.Fs, error)

func NewHashingFs added in v0.45.1

func NewHashingFs(delegate afero.Fs, hashReceiver FileHashReceiver) afero.Fs

NewHashingFs creates a new filesystem that will receive MD5 checksums of any written file content on Close. Note that this is probably not a good idea for "full build" situations, but when doing fast render mode, the amount of files published is low, and it would be really nice to know exactly which of these files where actually changed. Note that this will only work for file operations that use the io.Writer to write content to file, but that is fine for the "publish content" use case.

func NewLanguageCompositeFs added in v0.38.1

func NewLanguageCompositeFs(base, overlay afero.Fs) afero.Fs

NewLanguageCompositeFs creates a composite and language aware filesystem. This is a hybrid filesystem. To get a specific file in Open, Stat etc., use the full filename to the target filesystem. This information is available in Readdir, Stat etc. via the special LanguageFileInfo FileInfo implementation.

func NewLanguageFs added in v0.38.1

func NewLanguageFs(langs map[string]int, fs afero.Fs) (afero.Fs, error)

func NewNoSymlinkFs added in v0.56.0

func NewNoSymlinkFs(fs afero.Fs, logger *loggers.Logger, allowFiles bool) afero.Fs

NewNoSymlinkFs creates a new filesystem that prevents symlinks.

func NewSliceFs added in v0.56.0

func NewSliceFs(dirs ...FileMetaInfo) (afero.Fs, error)

func NewStacktracerFs added in v0.55.0

func NewStacktracerFs(fs afero.Fs, pattern string) afero.Fs

NewStacktracerFs wraps the given fs printing stack traces for file creates matching the given regexp pattern.

Types

type DuplicatesReporter added in v0.55.0

type DuplicatesReporter interface {
	ReportDuplicates() string
}

DuplicatesReporter reports about duplicate filenames.

type FileHashReceiver added in v0.45.1

type FileHashReceiver interface {
	OnFileClose(name, md5sum string)
}

FileHashReceiver will receive the filename an the content's MD5 sum on file close.

type FileMeta added in v0.56.0

type FileMeta map[string]interface{}

func (FileMeta) Classifier added in v0.56.0

func (f FileMeta) Classifier() files.ContentClass

func (FileMeta) Filename added in v0.56.0

func (f FileMeta) Filename() string

func (FileMeta) Fs added in v0.56.0

func (f FileMeta) Fs() afero.Fs

func (FileMeta) GetBool added in v0.56.0

func (f FileMeta) GetBool(key string) bool

func (FileMeta) GetInt added in v0.56.0

func (f FileMeta) GetInt(key string) int

func (FileMeta) GetOpener added in v0.56.0

func (f FileMeta) GetOpener() func() (afero.File, error)

func (FileMeta) GetString added in v0.56.0

func (f FileMeta) GetString(key string) string

func (FileMeta) IsOrdered added in v0.56.0

func (f FileMeta) IsOrdered() bool
func (f FileMeta) IsSymlink() bool

IsSymlink returns whether this comes from a symlinked file or directory.

func (FileMeta) JoinStat added in v0.64.1

func (f FileMeta) JoinStat(name string) (FileMetaInfo, error)

func (FileMeta) Lang added in v0.56.0

func (f FileMeta) Lang() string

func (FileMeta) Module added in v0.65.0

func (f FileMeta) Module() string

func (FileMeta) MountRoot added in v0.63.0

func (f FileMeta) MountRoot() string

func (FileMeta) Name added in v0.56.0

func (f FileMeta) Name() string

func (FileMeta) Open added in v0.56.0

func (f FileMeta) Open() (afero.File, error)

func (FileMeta) Ordinal added in v0.56.0

func (f FileMeta) Ordinal() int

func (FileMeta) OriginalFilename added in v0.56.0

func (f FileMeta) OriginalFilename() string

func (FileMeta) Path added in v0.56.0

func (f FileMeta) Path() string

Path returns the relative file path to where this file is mounted.

func (FileMeta) PathFile added in v0.62.1

func (f FileMeta) PathFile() string

PathFile returns the relative file path for the file source.

func (FileMeta) SkipDir added in v0.56.0

func (f FileMeta) SkipDir() bool

func (FileMeta) TranslationBaseName added in v0.56.0

func (f FileMeta) TranslationBaseName() string

func (FileMeta) TranslationBaseNameWithExt added in v0.56.0

func (f FileMeta) TranslationBaseNameWithExt() string

func (FileMeta) Translations added in v0.56.0

func (f FileMeta) Translations() []string

func (FileMeta) Watch added in v0.56.0

func (f FileMeta) Watch() bool

func (FileMeta) Weight added in v0.56.0

func (f FileMeta) Weight() int

type FileMetaInfo added in v0.56.0

type FileMetaInfo interface {
	os.FileInfo
	Meta() FileMeta
}

func NewFileMetaInfo added in v0.56.0

func NewFileMetaInfo(fi os.FileInfo, m FileMeta) FileMetaInfo

type FilterFs added in v0.56.0

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

FilterFs is an ordered composite filesystem.

func (*FilterFs) Chmod added in v0.56.0

func (fs *FilterFs) Chmod(n string, m os.FileMode) error

func (*FilterFs) Chtimes added in v0.56.0

func (fs *FilterFs) Chtimes(n string, a, m time.Time) error

func (*FilterFs) Create added in v0.56.0

func (fs *FilterFs) Create(n string) (afero.File, error)

func (*FilterFs) LstatIfPossible added in v0.56.0

func (fs *FilterFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (*FilterFs) Mkdir added in v0.56.0

func (fs *FilterFs) Mkdir(n string, p os.FileMode) error

func (*FilterFs) MkdirAll added in v0.56.0

func (fs *FilterFs) MkdirAll(n string, p os.FileMode) error

func (*FilterFs) Name added in v0.56.0

func (fs *FilterFs) Name() string

func (*FilterFs) Open added in v0.56.0

func (fs *FilterFs) Open(name string) (afero.File, error)

func (*FilterFs) OpenFile added in v0.56.0

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

func (*FilterFs) ReadDir added in v0.56.0

func (fs *FilterFs) ReadDir(name string) ([]os.FileInfo, error)

func (*FilterFs) Remove added in v0.56.0

func (fs *FilterFs) Remove(n string) error

func (*FilterFs) RemoveAll added in v0.56.0

func (fs *FilterFs) RemoveAll(p string) error

func (*FilterFs) Rename added in v0.56.0

func (fs *FilterFs) Rename(o, n string) error

func (*FilterFs) Stat added in v0.56.0

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

type Fs added in v0.20.1

type Fs struct {
	// Source is Hugo's source file system.
	Source afero.Fs

	// Destination is Hugo's destination file system.
	Destination afero.Fs

	// Os is an OS file system.
	// NOTE: Field is currently unused.
	Os afero.Fs

	// WorkingDir is a read-only file system
	// restricted to the project working dir.
	WorkingDir *afero.BasePathFs
}

Fs abstracts the file system to separate source and destination file systems and allows both to be mocked for testing.

func NewDefault added in v0.20.1

func NewDefault(cfg config.Provider) *Fs

NewDefault creates a new Fs with the OS file system as source and destination file systems.

func NewFrom added in v0.20.1

func NewFrom(fs afero.Fs, cfg config.Provider) *Fs

NewFrom creates a new Fs based on the provided Afero Fs as source and destination file systems. Useful for testing.

func NewMem added in v0.20.1

func NewMem(cfg config.Provider) *Fs

NewMem creates a new Fs with the MemMapFs as source and destination file systems. Useful for testing.

type Reseter added in v0.55.0

type Reseter interface {
	Reset()
}

Reseter is implemented by some of the stateful filesystems.

type RootMapping added in v0.56.0

type RootMapping struct {
	From      string   // The virtual mount.
	To        string   // The source directory or file.
	ToBasedir string   // The base of To. May be empty if an absolute path was provided.
	Module    string   // The module path/ID.
	Meta      FileMeta // File metadata (lang etc.)
	// contains filtered or unexported fields
}

RootMapping describes a virtual file or directory mount.

type RootMappingFs added in v0.42.1

type RootMappingFs struct {
	afero.Fs
	// contains filtered or unexported fields
}

A RootMappingFs maps several roots into one. Note that the root of this filesystem is directories only, and they will be returned in Readdir and Readdirnames in the order given.

func NewRootMappingFs added in v0.42.1

func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error)

NewRootMappingFs creates a new RootMappingFs on top of the provided with root mappings with some optional metadata about the root. Note that From represents a virtual root that maps to the actual filename in To.

func (*RootMappingFs) Dirs added in v0.56.0

func (fs *RootMappingFs) Dirs(base string) ([]FileMetaInfo, error)

func (RootMappingFs) Filter added in v0.56.0

func (fs RootMappingFs) Filter(f func(m RootMapping) bool) *RootMappingFs

Filter creates a copy of this filesystem with only mappings matching a filter.

func (*RootMappingFs) LstatIfPossible added in v0.42.1

func (fs *RootMappingFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

LstatIfPossible returns the os.FileInfo structure describing a given file.

func (*RootMappingFs) Open added in v0.42.1

func (fs *RootMappingFs) Open(name string) (afero.File, error)

Open opens the named file for reading.

func (*RootMappingFs) Stat added in v0.42.1

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

Stat returns the os.FileInfo structure describing a given file. If there is an error, it will be of type *os.PathError.

type SliceFs added in v0.56.0

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

SliceFs is an ordered composite filesystem.

func (*SliceFs) Chmod added in v0.56.0

func (fs *SliceFs) Chmod(n string, m os.FileMode) error

func (*SliceFs) Chtimes added in v0.56.0

func (fs *SliceFs) Chtimes(n string, a, m time.Time) error

func (*SliceFs) Create added in v0.56.0

func (fs *SliceFs) Create(n string) (afero.File, error)

func (*SliceFs) LstatIfPossible added in v0.56.0

func (fs *SliceFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (*SliceFs) Mkdir added in v0.56.0

func (fs *SliceFs) Mkdir(n string, p os.FileMode) error

func (*SliceFs) MkdirAll added in v0.56.0

func (fs *SliceFs) MkdirAll(n string, p os.FileMode) error

func (*SliceFs) Name added in v0.56.0

func (fs *SliceFs) Name() string

func (*SliceFs) Open added in v0.56.0

func (fs *SliceFs) Open(name string) (afero.File, error)

func (*SliceFs) OpenFile added in v0.56.0

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

func (*SliceFs) ReadDir added in v0.56.0

func (fs *SliceFs) ReadDir(name string) ([]os.FileInfo, error)

func (*SliceFs) Remove added in v0.56.0

func (fs *SliceFs) Remove(n string) error

func (*SliceFs) RemoveAll added in v0.56.0

func (fs *SliceFs) RemoveAll(p string) error

func (*SliceFs) Rename added in v0.56.0

func (fs *SliceFs) Rename(o, n string) error

func (*SliceFs) Stat added in v0.56.0

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

type WalkFunc added in v0.56.0

type WalkFunc func(path string, info FileMetaInfo, err error) error

type WalkHook added in v0.56.0

type WalkHook func(dir FileMetaInfo, path string, readdir []FileMetaInfo) ([]FileMetaInfo, error)

type Walkway added in v0.56.0

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

func NewWalkway added in v0.56.0

func NewWalkway(cfg WalkwayConfig) *Walkway

func (*Walkway) Walk added in v0.56.0

func (w *Walkway) Walk() error

type WalkwayConfig added in v0.56.0

type WalkwayConfig struct {
	Fs       afero.Fs
	Root     string
	BasePath string

	Logger *loggers.Logger

	// One or both of these may be pre-set.
	Info       FileMetaInfo
	DirEntries []FileMetaInfo

	WalkFn   WalkFunc
	HookPre  WalkHook
	HookPost WalkHook
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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