hugofs

package
v0.0.0-...-42d6f5d Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

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 {
	for _, fi1 := range bofi {
		fim1 := fi1.(FileMetaInfo)
		var found bool
		for _, fi2 := range lofi {
			fim2 := fi2.(FileMetaInfo)
			if fi1.Name() == fi2.Name() && fim1.Meta().Lang == fim2.Meta().Lang {
				found = true
				break
			}
		}
		if !found {
			lofi = append(lofi, fi1)
		}
	}

	return lofi
}

LanguageDirsMerger implements the overlayfs.DirsMerger func, 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 = &afero.OsFs{}

Os points to the (real) Os filesystem.

Functions

func DecorateBasePathFs

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

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 IsOsFs

func IsOsFs(fs afero.Fs) bool

IsOsFs returns whether fs is an OsFs or if it fs wraps an OsFs. TODO(bep) make this more robust.

func MakeReadableAndRemoveAllModulePkgDir

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

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

func NewCreateCountingFs(fs afero.Fs) afero.Fs

func NewFilterFs

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

func NewHasBytesReceiver

func NewHasBytesReceiver(delegate afero.Fs, shouldCheck func(name string) bool, hasBytesCallback func(name string, match bool), pattern []byte) afero.Fs

func NewHashingFs

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 NewLanguageFs

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

func NewNoSymlinkFs

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

NewNoSymlinkFs creates a new filesystem that prevents symlinks.

func NewSliceFs

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

func NewStacktracerFs

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.

func WalkFilesystems

func WalkFilesystems(fs afero.Fs, fn WalkFn) bool

WalkFilesystems walks fs recursively and calls fn. If fn returns true, walking is stopped.

Types

type DuplicatesReporter

type DuplicatesReporter interface {
	ReportDuplicates() string
}

DuplicatesReporter reports about duplicate filenames.

type FileHashReceiver

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

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

type FileMeta

type FileMeta struct {
	Name             string
	Filename         string
	Path             string
	PathWalk         string
	OriginalFilename string
	BaseDir          string

	SourceRoot string
	MountRoot  string
	Module     string

	Weight     int
	IsOrdered  bool
	IsSymlink  bool
	IsRootFile bool
	IsProject  bool
	Watch      bool

	Classifier files.ContentClass

	SkipDir bool

	Lang                       string
	TranslationBaseName        string
	TranslationBaseNameWithExt string
	Translations               []string

	Fs           afero.Fs
	OpenFunc     func() (afero.File, error)
	JoinStatFunc func(name string) (FileMetaInfo, error)

	// Include only files or directories that match.
	InclusionFilter *glob.FilenameFilter
}

func NewFileMeta

func NewFileMeta() *FileMeta

func (*FileMeta) Copy

func (m *FileMeta) Copy() *FileMeta

func (*FileMeta) JoinStat

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

func (*FileMeta) Merge

func (m *FileMeta) Merge(from *FileMeta)

func (*FileMeta) Open

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

func (*FileMeta) PathFile

func (f *FileMeta) PathFile() string

PathFile returns the relative file path for the file source.

type FileMetaInfo

type FileMetaInfo interface {
	os.FileInfo
	// Meta is for internal use.
	Meta() *FileMeta
}

func NewFileMetaInfo

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

type FilesystemUnwrapper

type FilesystemUnwrapper interface {
	UnwrapFilesystem() afero.Fs
}

FilesystemUnwrapper returns the underlying filesystem.

type FilesystemsUnwrapper

type FilesystemsUnwrapper interface {
	UnwrapFilesystems() []afero.Fs
}

FilesystemsUnwrapper returns the underlying filesystems.

type FilterFs

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

FilterFs is an ordered composite filesystem.

func (*FilterFs) Chmod

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

func (*FilterFs) Chown

func (fs *FilterFs) Chown(n string, uid, gid int) error

func (*FilterFs) Chtimes

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

func (*FilterFs) Create

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

func (*FilterFs) LstatIfPossible

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

func (*FilterFs) Mkdir

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

func (*FilterFs) MkdirAll

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

func (*FilterFs) Name

func (fs *FilterFs) Name() string

func (*FilterFs) Open

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

func (*FilterFs) OpenFile

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

func (*FilterFs) ReadDir

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

func (*FilterFs) Remove

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

func (*FilterFs) RemoveAll

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

func (*FilterFs) Rename

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

func (*FilterFs) Stat

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

func (*FilterFs) UnwrapFilesystem

func (fs *FilterFs) UnwrapFilesystem() afero.Fs

type Fs

type Fs struct {
	// Source is Hugo's source file system.
	// Note that this will always be a "plain" Afero filesystem:
	// * afero.OsFs when running in production
	// * afero.MemMapFs for many of the tests.
	Source afero.Fs

	// PublishDir is where Hugo publishes its rendered content.
	// It's mounted inside publishDir (default /public).
	PublishDir afero.Fs

	// PublishDirStatic is the file system used for static files.
	PublishDirStatic afero.Fs

	// PublishDirServer is the file system used for serving the public directory with Hugo's development server.
	// This will typically be the same as PublishDir, but not if --renderStaticToDisk is set.
	PublishDirServer afero.Fs

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

	// WorkingDirReadOnly is a read-only file system
	// restricted to the project working dir.
	WorkingDirReadOnly afero.Fs

	// WorkingDirWritable is a writable file system
	// restricted to the project working dir.
	WorkingDirWritable afero.Fs
}

Fs holds the core filesystems used by Hugo.

func NewDefault

func NewDefault(conf config.BaseConfig) *Fs

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

func NewDefaultOld

func NewDefaultOld(cfg config.Provider) *Fs

func NewFrom

func NewFrom(fs afero.Fs, conf config.BaseConfig) *Fs

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

func NewFromOld

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

func NewFromSourceAndDestination

func NewFromSourceAndDestination(source, destination afero.Fs, cfg config.Provider) *Fs

NewFromSourceAndDestination creates a new Fs based on the provided Afero Fss as the source and destination file systems.

type Reseter

type Reseter interface {
	Reset()
}

Reseter is implemented by some of the stateful filesystems.

type RootMapping

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.
	IsProject bool      // Whether this is a mount in the main project.
	Meta      *FileMeta // File metadata (lang etc.)
	// contains filtered or unexported fields
}

RootMapping describes a virtual file or directory mount.

type RootMappingFs

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

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

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

func (RootMappingFs) Filter

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

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

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

func (*RootMappingFs) Open

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

Open opens the named file for reading.

func (*RootMappingFs) Stat

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.

func (*RootMappingFs) UnwrapFilesystem

func (fs *RootMappingFs) UnwrapFilesystem() afero.Fs

type SliceFs

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

SliceFs is an ordered composite filesystem.

func (*SliceFs) Chmod

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

func (*SliceFs) Chown

func (fs *SliceFs) Chown(n string, uid, gid int) error

func (*SliceFs) Chtimes

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

func (*SliceFs) Create

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

func (*SliceFs) LstatIfPossible

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

func (*SliceFs) Mkdir

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

func (*SliceFs) MkdirAll

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

func (*SliceFs) Name

func (fs *SliceFs) Name() string

func (*SliceFs) Open

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

func (*SliceFs) OpenFile

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

func (*SliceFs) ReadDir

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

func (*SliceFs) Remove

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

func (*SliceFs) RemoveAll

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

func (*SliceFs) Rename

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

func (*SliceFs) Stat

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

func (*SliceFs) UnwrapFilesystems

func (fs *SliceFs) UnwrapFilesystems() []afero.Fs

type WalkFn

type WalkFn func(fs afero.Fs) bool

WalkFn is the walk func for WalkFilesystems.

type WalkFunc

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

type WalkHook

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

type Walkway

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

func NewWalkway

func NewWalkway(cfg WalkwayConfig) *Walkway

func (*Walkway) Walk

func (w *Walkway) Walk() error

type WalkwayConfig

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