files

package
v2.1.6 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package files provides unified file system operations for package building.

Package files provides unified file system operations for package building.

Package files provides unified file system operations for package building.

Index

Constants

View Source
const (
	TagLink             = 0o120000
	TagDirectory        = 0o40000
	TypeFile            = "file"
	TypeDir             = "dir"
	TypeImplicitDir     = "implicit dir"
	TypeSymlink         = "symlink"
	TypeTree            = "tree"
	TypeConfig          = "config"
	TypeConfigNoReplace = "config|noreplace"
)

File type constants

Variables

This section is empty.

Functions

func CalculateDataHash

func CalculateDataHash(baseDir string, skipPatterns []string) (string, error)

CalculateDataHash calculates a hash of all data files for package metadata. This is used by formats like APK that need a hash of the entire data payload.

func CheckWritable

func CheckWritable(path string) error

CheckWritable checks if a file is writable.

func Chmod

func Chmod(path string, perm os.FileMode) error

Chmod changes file permissions.

func Create

func Create(path string) (*os.File, error)

Create creates a new file.

func CreateWrite

func CreateWrite(path, data string) error

CreateWrite creates a file and writes data to it.

func Exists

func Exists(path string) bool

Exists checks if a file or directory exists.

func ExistsMakeDir

func ExistsMakeDir(path string) error

ExistsMakeDir creates a directory if it doesn't exist.

func GetDirSize

func GetDirSize(path string) (int64, error)

GetDirSize calculates the total size of a directory.

func GetFileType

func GetFileType(path string) string

GetFileType returns the ELF type of a file, or empty string for non-ELF files.

func IsEmptyDir

func IsEmptyDir(path string, dirEntry os.DirEntry) bool

IsEmptyDir checks if a directory is empty.

func IsStaticLibrary

func IsStaticLibrary(path string) bool

IsStaticLibrary checks if a file is a static library (.a file or archive).

func Open

func Open(path string) (*os.File, error)

Open opens a file for reading.

func ResolveSourceDateEpoch

func ResolveSourceDateEpoch(pkgbuildDir string) (time.Time, error)

ResolveSourceDateEpoch returns a deterministic build timestamp for reproducible builds.

Resolution order:

  1. If SOURCE_DATE_EPOCH is already set in the environment, parse and return it (honouring explicit user/CI override).
  2. Otherwise, use the modification time of the PKGBUILD file located in pkgbuildDir (matching makepkg behaviour).

The resolved value is also exported into the process environment so that child processes (gcc, tar, gzip, …) that natively support SOURCE_DATE_EPOCH will use it.

func SourceDateEpochFromEnv

func SourceDateEpochFromEnv() time.Time

SourceDateEpochFromEnv reads SOURCE_DATE_EPOCH from the environment and returns the corresponding time. If the variable is absent or invalid, it returns time.Now(). This is a lightweight reader for use in packaging code that runs after ResolveSourceDateEpoch has already been called.

Types

type Entry

type Entry struct {
	Source      string      // Absolute path to the source file
	Destination string      // Relative path in the package (starts with /)
	Type        string      // File type (file, dir, symlink, config, etc.)
	Mode        os.FileMode // File permissions
	Size        int64       // File size in bytes
	ModTime     time.Time   // Last modification time
	LinkTarget  string      // Target path for symlinks
	SHA256      []byte      // SHA256 hash for regular files
	IsBackup    bool        // Whether this file should be treated as a config backup
}

Entry represents a file or directory entry in a package. This consolidates the various file entry types used across package formats.

func (*Entry) IsConfigFile

func (e *Entry) IsConfigFile() bool

IsConfigFile returns true if this entry represents a configuration file.

func (*Entry) IsDirectory

func (e *Entry) IsDirectory() bool

IsDirectory returns true if this entry represents a directory.

func (*Entry) IsRegularFile

func (e *Entry) IsRegularFile() bool

IsRegularFile returns true if this entry represents a regular file.

func (e *Entry) IsSymlink() bool

IsSymlink returns true if this entry represents a symbolic link.

type WalkOptions

type WalkOptions struct {
	SkipDotFiles bool     // Skip files starting with '.'
	BackupFiles  []string // List of backup/config files
	SkipPatterns []string // File patterns to skip
}

WalkOptions configures the behavior of directory walking.

type Walker

type Walker struct {
	BaseDir string
	Options WalkOptions
}

Walker provides unified directory walking functionality for all package managers.

func NewWalker

func NewWalker(baseDir string, options WalkOptions) *Walker

NewWalker creates a new filesystem walker.

func (*Walker) Walk

func (w *Walker) Walk() ([]*Entry, error)

Walk traverses the directory and returns file entries. This consolidates all the walking logic from different package formats.

Jump to

Keyboard shortcuts

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