valueobject

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppendDirsMerger overlayfs.DirsMerger = func(lofi, bofi []iofs.DirEntry) []iofs.DirEntry {
	for _, fi1 := range bofi {
		var found bool

		if fi1.IsDir() {
			for _, fi2 := range lofi {
				if fi2.IsDir() && fi2.Name() == fi1.Name() {
					found = true
					break
				}
			}
		}
		if !found {
			lofi = append(lofi, fi1)
		}
	}

	return lofi
}

AppendDirsMerger merges two directories keeping all regular files with the first slice as the base. Duplicate directories in the second slice will be ignored. This strategy is used for the i18n and data fs where we need all entries.

View Source
var LanguageDirsMerger overlayfs.DirsMerger = func(lofi, bofi []iofs.DirEntry) []iofs.DirEntry {
	for _, fi1 := range bofi {
		var found bool
		for _, fi2 := range lofi {
			if fi1.Name() == fi2.Name() {
				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{}
)

Functions

func DirEntriesToFileMetaInfos

func DirEntriesToFileMetaInfos(fis []iofs.DirEntry) []fs.FileMetaInfo

func GetVirtualFileInfo

func GetVirtualFileInfo() (os.FileInfo, error)

GetVirtualFileInfo returns the FileInfo of the virtual file

func Glob

func Glob(afs afero.Fs, pattern string, handle func(fi fs.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 LstatIfPossible

func LstatIfPossible(fs afero.Fs, path string) (os.FileInfo, bool, error)

LstatIfPossible if the filesystem supports it, use Lstat, else use fs.Stat

func NewBaseFs

func NewBaseFs(fs afero.Fs) afero.Fs

func NewBasePathFs

func NewBasePathFs(source afero.Fs, path string) afero.Fs

NewBasePathFs creates a new BasePathFs.

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 NewReadOnlyFs

func NewReadOnlyFs(source afero.Fs) afero.Fs

NewReadOnlyFs creates a new ReadOnlyFs.

func RealFilename

func RealFilename(cfs *ComponentFs, rel string) string

func WalkFilesystems

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

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

func WrapFilesystem

func WrapFilesystem(container, content afero.Fs) afero.Fs

WrapFilesystem is typically used to wrap a afero.BasePathFs to allow access to the underlying filesystem if needed.

Types

type ComponentFs

type ComponentFs struct {
	afero.Fs

	// The ComponentDir name, e.g. "content", "layouts" etc.
	Component string

	OverlayFs afero.Fs
	// contains filtered or unexported fields
}

func NewComponentFs

func NewComponentFs(component string, overlayFs *overlayfs.OverlayFs) *ComponentFs

func (*ComponentFs) MakePathRelative

func (cfs *ComponentFs) MakePathRelative(filename string, checkExists bool) (string, bool)

MakePathRelative creates a relative path from the given filename.

func (*ComponentFs) Open

func (cfs *ComponentFs) Open(name string) (afero.File, error)

func (*ComponentFs) RealDirs

func (cfs *ComponentFs) RealDirs(from string) []string

RealDirs gets a list of absolute paths to directories starting from the given path.

func (*ComponentFs) ReverseLookup

func (cfs *ComponentFs) ReverseLookup(filename string, checkExists bool) ([]ComponentPath, error)

ReverseLookup returns the ComponentDir paths for the given filename.

func (*ComponentFs) Stat

func (cfs *ComponentFs) Stat(name string) (os.FileInfo, error)

func (*ComponentFs) UnwrapFilesystem

func (cfs *ComponentFs) UnwrapFilesystem() afero.Fs

type ComponentPath

type ComponentPath struct {
	Component string
	Path      string
	Lang      string
}

func (ComponentPath) ComponentPathJoined

func (c ComponentPath) ComponentPathJoined() string

type ContentClass

type ContentClass string
const (
	ContentClassLeaf    ContentClass = "leaf"
	ContentClassBranch  ContentClass = "branch"
	ContentClassFile    ContentClass = "zfile" // Sort below
	ContentClassContent ContentClass = "zcontent"
)

type DirFile

type DirFile struct {
	*File
	// contains filtered or unexported fields
}

func NewDirFile

func NewDirFile(file afero.File, meta FileMeta, fs afero.Fs) *DirFile

func NewDirFileWithVirtualOpener

func NewDirFileWithVirtualOpener(f *File, opener DirOpener) *DirFile

func (*DirFile) ReadDir

func (f *DirFile) ReadDir(count int) ([]fs.DirEntry, error)

type DirOpener

type DirOpener func() ([]fs.DirEntry, error)

type File

type File struct {
	afero.File
	FileMeta
	// contains filtered or unexported fields
}

func NewFile

func NewFile(file afero.File, filename string) *File

func (*File) Close

func (f *File) Close() error

func (*File) ReadDir

func (f *File) ReadDir(count int) ([]fs.DirEntry, error)

type FileChangeDetector

type FileChangeDetector struct {
	sync.Mutex

	IrrelevantRe *regexp.Regexp
	// contains filtered or unexported fields
}

func NewFileChangeDetector

func NewFileChangeDetector() *FileChangeDetector

func (*FileChangeDetector) OnFileClose

func (f *FileChangeDetector) OnFileClose(name, md5sum string)

func (*FileChangeDetector) PrepareNew

func (f *FileChangeDetector) PrepareNew()

type FileHashReceiver

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

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

type FileInfo

type FileInfo struct {
	fs.FileInfo
	*FileMeta
}

func NewFileInfo

func NewFileInfo(fi os.FileInfo, filename string) *FileInfo

func NewFileInfoWithMeta

func NewFileInfoWithMeta(fi os.FileInfo, meta *FileMeta) *FileInfo

func NewFileInfoWithName

func NewFileInfoWithName(filename string) *FileInfo

func NewFileInfoWithNewMeta

func NewFileInfoWithNewMeta(fi os.FileInfo, meta *FileMeta) *FileInfo

func NewFileInfoWithOpener

func NewFileInfoWithOpener(fi os.FileInfo, filename string, opener FileOpener) *FileInfo

func NewFileInfoWithRoot

func NewFileInfoWithRoot(fi os.FileInfo, filename, root string, opener FileOpener) *FileInfo

func (*FileInfo) Info

func (fi *FileInfo) Info() (fs.FileInfo, error)

func (*FileInfo) Meta

func (fi *FileInfo) Meta() *FileMeta

func (*FileInfo) Type

func (fi *FileInfo) Type() fs.FileMode

type FileMeta

type FileMeta struct {
	ComponentRoot string
	ComponentDir  string

	OpenFunc FileOpener
	// contains filtered or unexported fields
}

func NewFileMeta

func NewFileMeta() *FileMeta

func (*FileMeta) Component

func (f *FileMeta) Component() string

func (*FileMeta) Copy

func (f *FileMeta) Copy() *FileMeta

func (*FileMeta) FileName

func (f *FileMeta) FileName() string

func (*FileMeta) Merge

func (f *FileMeta) Merge(from *FileMeta)

func (*FileMeta) NormalizedFilename

func (f *FileMeta) NormalizedFilename() string

func (*FileMeta) Open

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

func (*FileMeta) RelativeFilename

func (f *FileMeta) RelativeFilename() string

func (*FileMeta) Root

func (f *FileMeta) Root() string

type FileOpener

type FileOpener func() (afero.File, error)

type FilesystemsCollector

type FilesystemsCollector struct {
	SourceProject afero.Fs // Source for project folders
	SourceModules afero.Fs // Source for modules/themes

	OverlayMounts        *overlayfs.OverlayFs
	OverlayMountsContent *overlayfs.OverlayFs
	OverlayMountsStatic  *overlayfs.OverlayFs
	OverlayMountsFull    *overlayfs.OverlayFs
	OverlayFull          *overlayfs.OverlayFs
	OverlayResources     *overlayfs.OverlayFs

	RootFss []*RootMappingFs

	AbsResourcesDir string
}

func (*FilesystemsCollector) Collect

func (c *FilesystemsCollector) Collect(mods module.Modules) error

type MetaProvider

type MetaProvider interface {
	Meta() *FileMeta
}

type ReverseLookupProvider

type ReverseLookupProvider interface {
	ReverseLookup(filename string) ([]ComponentPath, error)
	ReverseLookupComponent(component, filename string) ([]ComponentPath, error)
}

type RootMapping

type RootMapping struct {
	// The virtual mount.
	From     string
	FromBase string // The base directory of the virtual mount. //TODO
	// The source directory or file.
	To     string
	ToBase string // The base of To. May be empty if an absolute path was provided.

	ToFi *FileInfo
}

RootMapping describes a virtual file or directory mount.

func GetRms

func GetRms(t *radixtree.Tree, key string) []RootMapping

func (RootMapping) Filename

func (rm RootMapping) Filename(name string) string

type RootMappingFs

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

func NewRootMappingFs

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

func (*RootMappingFs) Mounts

func (rmfs *RootMappingFs) Mounts(base string) ([]fs.FileMetaInfo, error)

func (*RootMappingFs) Open

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

Open opens the named file for reading.

func (*RootMappingFs) ReverseLookup

func (rmfs *RootMappingFs) ReverseLookup(filename string) ([]ComponentPath, error)

func (*RootMappingFs) ReverseLookupComponent

func (rmfs *RootMappingFs) ReverseLookupComponent(component, filename string) ([]ComponentPath, error)

func (*RootMappingFs) Stat

func (rmfs *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 (rmfs *RootMappingFs) UnwrapFilesystem() afero.Fs

type WalkFn

type WalkFn func(fs afero.Fs) bool

WalkFn is the walk func for WalkFilesystems.

type Walkway

type Walkway struct {
	// The filesystem to walk.
	Fs afero.Fs

	// The ComponentRoot to start from in Fs.
	Root string
	// contains filtered or unexported fields
}

func NewWalkway

func NewWalkway(fs afero.Fs, cb fs.WalkCallback) (*Walkway, error)

func (*Walkway) Walk

func (w *Walkway) Walk() error

func (*Walkway) WalkWith

func (w *Walkway) WalkWith(root string, cfg fs.WalkwayConfig) error

Jump to

Keyboard shortcuts

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