files

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package files provides a simple file tree abstraction.

It is specifically designed to match the simple needs for building a simple initramfs. So it only supports file types for regular files, directories and symbolic links.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEntryNotDir is returned if an entry is supposed to be a directory but is
	// not.
	ErrEntryNotDir = errors.New("entry is not a directory")
	// ErrEntryNotExists is returned if an entry that is looked up does not exist.
	ErrEntryNotExists = errors.New("entry does not exist")
	// ErrEntryExists is returned if an entry exists that was not expected.
	ErrEntryExists = errors.New("entry exists")
)

Functions

func LinkedLibs added in v0.1.1

func LinkedLibs(elfFilePath string) ([]string, error)

LinkedLibs fetches the list of dynamically linked libraries from the ELF file.

Types

type ELFLibResolver

type ELFLibResolver struct {
	SearchPaths []string
	Libs        []string
}

ELFLibResolver resolves dynamically linked libraries of ELF file. It collects the libraries deduplicated for all files resolved with ELFLibResolver.Resolve.

func (*ELFLibResolver) Resolve

func (r *ELFLibResolver) Resolve(elfFile string) error

Resolve analyzes the required linked libraries of the ELF file with the given path. The libraries are search for in the library search paths and are added with their absolute path to ELFLibResolver's list of libs. Call [ELFLibResolver.Libs] once all files are resolved.

type Entry

type Entry struct {
	// Type of this entry.
	Type Type
	// Related path depending on the file type. Empty for directories,
	// target path for links, source files for regular files.
	RelatedPath string
	// contains filtered or unexported fields
}

Entry is a single file tree entry.

func (*Entry) AddDirectory

func (e *Entry) AddDirectory(name string) (*Entry, error)

AddDirectory adds a new directory Entry children.

func (*Entry) AddEntry

func (e *Entry) AddEntry(name string, entry *Entry) (*Entry, error)

AddEntry adds an arbitrary Entry as children. The caller is responsible for using only valid [Type]s and according fields.

func (*Entry) AddFile

func (e *Entry) AddFile(name, relatedPath string) (*Entry, error)

AddFile adds a new regular file Entry children.

func (e *Entry) AddLink(name, relatedPath string) (*Entry, error)

AddLink adds a new link Entry children.

func (*Entry) GetEntry

func (e *Entry) GetEntry(name string) (*Entry, error)

GetEntry getsan Entry for the given name. Return ErrEntryNotExists if it doesn't exist.

func (*Entry) IsDir

func (e *Entry) IsDir() bool

IsDir returns true if the Entry is a directory.

func (e *Entry) IsLink() bool

IsLink returns true if the Entry is a link.

func (*Entry) IsRegular

func (e *Entry) IsRegular() bool

IsRegular returns true if the Entry is a regular file.

type Tree

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

Tree represents a simple file tree.

func (*Tree) GetEntry

func (t *Tree) GetEntry(path string) (*Entry, error)

GetEntry returns the entry for the given path. Returns ErrEntryNotExists if the entry does not exist.

func (*Tree) GetRoot

func (t *Tree) GetRoot() *Entry

GetRoot returns the root entry of the tree.

func (*Tree) Ln

func (t *Tree) Ln(target string, path string) error

Ln adds links to target for the given path.

func (*Tree) Mkdir

func (t *Tree) Mkdir(path string) (*Entry, error)

Mkdir adds a directory entry for the given path. Non existing parents are created recursively. If any of the parents exists but is not a directory ErrEntryNotDir is returned.

func (*Tree) Walk

func (f *Tree) Walk(fn WalkFunc) error

Walk walks the tree recursively, starting at the root, and runs the given function for each entry. If the function returns an error, the recursion is terminated immediately and the error is returned.

type Type

type Type int

Type defines the type of an Entry.

const (
	// A regular file is copied completely into the archive.
	TypeRegular Type = iota
	// A directory is created in the archive. Parent directories are not created
	// automatically. Ensure to create the complete file tree yourself.
	TypeDirectory
	// A symbolic link in the archive.
	TypeLink
)

type WalkFunc

type WalkFunc func(path string, entry *Entry) error

WalkFunc is called with the absolute path to the entry.

Jump to

Keyboard shortcuts

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