filesystem

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Overview

Package filesystem contains a simple representation of hierarchical filesystems that is used by libpackagebuild.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Directory

type Directory struct {
	Entries  map[string]Node
	Metadata NodeMetadata
	Implicit bool
}

Directory is a type of Node that represents directories. This Node references the nodes contained in the directory recursively.

func NewDirectory

func NewDirectory() *Directory

NewDirectory initializes an empty Directory.

func (*Directory) FileModeForArchive

func (d *Directory) FileModeForArchive(includingFileType bool) uint32

FileModeForArchive implements the Node interface.

func (*Directory) Insert

func (d *Directory) Insert(entry Node, relPath []string, location string) error

Insert implements the Node interface.

func (*Directory) InstalledSizeInBytes

func (d *Directory) InstalledSizeInBytes() int

InstalledSizeInBytes implements the Node interface.

func (*Directory) PostponeUnmaterializable

func (d *Directory) PostponeUnmaterializable(absolutePath string) string

PostponeUnmaterializable implements the Node interface.

func (*Directory) ToTarArchive

func (d *Directory) ToTarArchive(w io.Writer, leadingDot, skipRootDirectory bool) error

ToTarArchive creates a TAR archive containing this directory and all the filesystem entries in it.

With `leadingDot = true`, generate entry paths like `./foo/bar.conf`. With `leadingDot = false`, generate entry paths like `foo/bar.conf`.

With `skipRootDirectory = true`, don't generate an entry for the root directory in the resulting package.

func (*Directory) ToTarGZArchive

func (d *Directory) ToTarGZArchive(w io.Writer, leadingDot, skipRootDirectory bool) error

ToTarGZArchive is identical to ToTarArchive, but GZip-compresses the result.

func (*Directory) ToTarXZArchive

func (d *Directory) ToTarXZArchive(w io.Writer, leadingDot, skipRootDirectory bool) error

ToTarXZArchive is identical to ToTarArchive, but GZip-compresses the result.

func (*Directory) Walk

func (d *Directory) Walk(absolutePath string, callback func(string, Node) error) error

Walk implements the Node interface.

type IntOrString

type IntOrString struct {
	Int uint32
	Str string
}

IntOrString is used for NodeMetadata.Owner and NodeMetadata.Group that can be either int or string.

Note that, from within a generator, you will always see `Str` to be empty. See Node.PostponeUnmaterializable() for details.

type Node

type Node interface {
	//Insert inserts a new node below the current node at the given relative
	//path. The path is given as a slice of strings, separated on slashes, e.g.
	//`[]string{"var","lib","foo"}` for the path `"var/lib/foo"`.
	//
	//The `location` argument contains the absolute path to the current node;
	//this can be used for error reporting.
	Insert(entry Node, relPath []string, location string) error
	//InstalledSizeInBytes approximates the apparent size of the given
	//directory and everything in it, as calculated by `du -s --apparent-size`,
	//but in a filesystem-independent way.
	InstalledSizeInBytes() int
	//FileModeForArchive returns the file mode of this Node as stored in a
	//tar or CPIO archive.
	FileModeForArchive(includingFileType bool) uint32
	//Walk visits all the nodes below this Node (including itself) and calls
	//the given callback at each node. It is guaranteed that the callback for a
	//node is called after the callback of its parent node (if any).
	//
	//The `callback` can arrange to skip over a directory by returning
	//filepath.SkipDir.
	Walk(absolutePath string, callback func(absolutePath string, node Node) error) error
	//PostponeUnmaterializable generates a shell script that applies all
	//filesystem metadata in this node and its children that cannot be
	//represented in a tar archive directly. Specifically, owners/groups
	//identified by name cannot be resolved into numeric IDs at build time, so
	//this call will generate a shell script calling chown/chmod/chgrp as
	//required.
	PostponeUnmaterializable(absolutePath string) string
}

Node instances represent an entry in the file system (such as a file or a directory).

type NodeMetadata

type NodeMetadata struct {
	Mode  os.FileMode
	Owner *IntOrString
	Group *IntOrString
}

NodeMetadata collects some metadata that is shared across Node-compatible types.

func (*NodeMetadata) GID

func (m *NodeMetadata) GID() uint32

GID returns Group.Int if it is set.

func (*NodeMetadata) UID

func (m *NodeMetadata) UID() uint32

UID returns Owner.Int if it is set.

type RegularFile

type RegularFile struct {
	Content  string
	Metadata NodeMetadata
}

RegularFile is a type of Node that represents regular files.

func (*RegularFile) FileModeForArchive

func (f *RegularFile) FileModeForArchive(includingFileType bool) uint32

FileModeForArchive implements the Node interface.

func (*RegularFile) Insert

func (f *RegularFile) Insert(entry Node, relPath []string, location string) error

Insert implements the Node interface.

func (*RegularFile) InstalledSizeInBytes

func (f *RegularFile) InstalledSizeInBytes() int

InstalledSizeInBytes implements the Node interface.

func (*RegularFile) MD5Digest

func (f *RegularFile) MD5Digest() string

MD5Digest returns the MD5 digest of this file's contents.

func (*RegularFile) PostponeUnmaterializable

func (f *RegularFile) PostponeUnmaterializable(absolutePath string) string

PostponeUnmaterializable implements the Node interface.

func (*RegularFile) SHA256Digest

func (f *RegularFile) SHA256Digest() string

SHA256Digest returns the SHA256 digest of this file's contents.

func (*RegularFile) Walk

func (f *RegularFile) Walk(absolutePath string, callback func(string, Node) error) error

Walk implements the Node interface.

type Symlink struct {
	Target string
}

Symlink is a type of Node that represents symbolic links,

func (*Symlink) FileModeForArchive

func (s *Symlink) FileModeForArchive(includingFileType bool) uint32

FileModeForArchive implements the Node interface.

func (*Symlink) Insert

func (s *Symlink) Insert(entry Node, relPath []string, location string) error

Insert implements the Node interface.

func (*Symlink) InstalledSizeInBytes

func (s *Symlink) InstalledSizeInBytes() int

InstalledSizeInBytes implements the Node interface.

func (*Symlink) PostponeUnmaterializable

func (s *Symlink) PostponeUnmaterializable(absolutePath string) string

PostponeUnmaterializable implements the Node interface.

func (*Symlink) Walk

func (s *Symlink) Walk(absolutePath string, callback func(string, Node) error) error

Walk implements the Node interface.

Jump to

Keyboard shortcuts

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