storage

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContentHashAlgorithm is the hash algorithm used for content addressing.
	ContentHashAlgorithm = "xxh3"

	// DirPerm is the default permission for directories.
	DirPerm = 0o755

	// TempContentPattern is the pattern for temporary content files.
	TempContentPattern = ".content-*"

	// TempSnapshotPattern is the pattern for temporary snapshot files.
	TempSnapshotPattern = ".snapshot-*"
)

Variables

This section is empty.

Functions

func ContentDigest

func ContentDigest(digest string) string

ContentDigest returns the digest by adding the hash algorithm prefix.

func ParseFilenameFromDigest

func ParseFilenameFromDigest(digest string) string

ParseFilenameFromDigest parses the filename from the digest.

Types

type File

type File struct {
	// RelativePath is the relative path of the file.
	RelativePath string

	// ReadOnly indicates whether the file is read-only.
	ReadOnly bool
}

File defines the file information for snapshotting and restoring.

type Storage

type Storage interface {
	// StatContent returns the content info.
	StatContent(ctx context.Context, baseDir string, file File) (os.FileInfo, error)

	// WriteContent writes the content to the storage.
	WriteContent(ctx context.Context, baseDir string, file File) (os.FileInfo, error)

	// GetContentPath returns the path to the content.
	GetContentPath(ctx context.Context, filename string) string

	// StatSnapshot returns the snapshot info.
	StatSnapshot(ctx context.Context, filename string) (os.FileInfo, error)

	// HardlinkSnapshot creates a hardlink to the snapshot.
	HardlinkSnapshot(ctx context.Context, baseDir string, srcfile File, destFilename string) error

	// RestoreSnapshotFromContent restores the snapshot from content.
	RestoreSnapshotFromContent(ctx context.Context, filename string) error

	// Export outputs the content or snapshot to output directory.
	// It will copy the content if the file is not read-only, otherwise it will hardlink from snapshot.
	Export(ctx context.Context, outputDir string, file metadata.File, srcFilename string) error

	// Prune removes unused content and snapshot files.
	Prune(ctx context.Context, filename string) error
}

Storage is an interface for storage.

func New

func New(rootDir string) (Storage, error)

New creates a new storage instance.

Jump to

Keyboard shortcuts

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