store

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyArchive = errors.New("empty archive (no files after extraction)")

ErrEmptyArchive is returned when an archive contains no files.

Functions

func DefaultRegistryPath

func DefaultRegistryPath() string

DefaultRegistryPath returns ~/.allegro/projects.json.

func ExtractByType

func ExtractByType(data []byte, distType, destDir, packageName string) error

ExtractByType extracts an archive based on dist.type.

func ExtractGzip

func ExtractGzip(data []byte, destDir string) error

ExtractGzip decompresses gzip then extracts tar.

func ExtractTar

func ExtractTar(r io.Reader, destDir string) error

ExtractTar extracts a tar archive from a reader to destDir.

func ExtractXz

func ExtractXz(data []byte, destDir string) error

ExtractXz decompresses xz then extracts tar using system xz command.

func ExtractZip

func ExtractZip(data []byte, destDir string) error

ExtractZip extracts a zip archive to destDir.

func HashBytes

func HashBytes(data []byte) string

HashBytes computes the SHA-256 hex digest of a byte slice.

func HashFile

func HashFile(path string) (string, error)

HashFile computes the SHA-256 hex digest of a file's content.

func RegisterProject

func RegisterProject(path string, entry ProjectEntry) error

RegisterProject adds or updates a project entry in the registry.

func ResolvePath

func ResolvePath(flagValue, envValue string) string

ResolvePath returns the store directory path based on precedence: flagValue > envValue > default (~/.allegro/store).

func ShardPrefix

func ShardPrefix(hash string) string

ShardPrefix returns the first 2 hex characters of a hash.

func StripTopLevelDir

func StripTopLevelDir(dir string) error

StripTopLevelDir detects if all files share a common top-level directory and moves them up if so.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm os.FileMode) error

WriteFileAtomic writes data to path atomically (unique temp + fsync + rename).

Types

type FileEntry

type FileEntry struct {
	Path       string `json:"path"`
	Hash       string `json:"hash"`
	Size       int64  `json:"size"`
	Executable bool   `json:"executable"`
}

FileEntry represents a single file in a package manifest.

type GCResult

type GCResult struct {
	ManifestsPruned int
	FilesPruned     int
	BytesFreed      int64
	StaleWarned     int
	ProjectsRemoved int
}

GCResult holds the outcome of a garbage collection run.

func GarbageCollect

func GarbageCollect(storePath, registryPath string, staleDays int, dryRun bool) (*GCResult, error)

GarbageCollect performs smart prune with project awareness (Unix: with flock).

func (*GCResult) String

func (r *GCResult) String() string

FormatGCResult formats the result for display.

type Manifest

type Manifest struct {
	Name     string      `json:"name"`
	Version  string      `json:"version"`
	DistHash string      `json:"dist_hash"`
	Files    []FileEntry `json:"files"`
	StoredAt time.Time   `json:"stored_at"`
}

Manifest represents a package version's manifest in the CAS.

type ProjectEntry

type ProjectEntry struct {
	Path        string            `json:"path"`
	LastInstall time.Time         `json:"last_install"`
	LockHash    string            `json:"lock_hash"`
	Packages    map[string]string `json:"packages"`
}

ProjectEntry represents a single project in the registry.

type ProjectRegistry

type ProjectRegistry struct {
	Projects []ProjectEntry `json:"projects"`
}

ProjectRegistry represents ~/.allegro/projects.json.

func ReadRegistry

func ReadRegistry(path string) (*ProjectRegistry, error)

ReadRegistry reads ~/.allegro/projects.json. Returns empty registry if missing.

type Store

type Store struct {
	Root string // e.g. ~/.allegro/store
}

Store manages the content-addressable store.

func New

func New(root string) *Store

New creates a Store at the given root path.

func (*Store) EnsureDirectories

func (s *Store) EnsureDirectories() error

EnsureDirectories creates the store directory tree if missing.

func (*Store) EnsureMetadata

func (s *Store) EnsureMetadata() error

EnsureMetadata creates allegro.json if missing, validates store version.

func (*Store) FileExists

func (s *Store) FileExists(hash string) bool

FileExists checks if a CAS file exists.

func (*Store) FilePath

func (s *Store) FilePath(hash string) string

FilePath returns the CAS path for a content hash.

func (*Store) ManifestExists

func (s *Store) ManifestExists(name, version string) bool

ManifestExists checks if a manifest exists for a package version.

func (*Store) ManifestPath

func (s *Store) ManifestPath(name, version string) string

ManifestPath returns the path for a package manifest.

func (*Store) MetadataPath

func (s *Store) MetadataPath() string

MetadataPath returns the path to allegro.json.

func (*Store) ReadManifest

func (s *Store) ReadManifest(name, version string) (*Manifest, error)

ReadManifest reads a package manifest from disk.

func (*Store) StoreFile

func (s *Store) StoreFile(srcPath, hash string, executable bool) error

StoreFile moves a file to its CAS location with correct permissions.

func (*Store) TmpDir

func (s *Store) TmpDir() string

TmpDir returns the store tmp directory path.

func (*Store) WriteManifest

func (s *Store) WriteManifest(m *Manifest) error

WriteManifest writes a package manifest atomically.

type StoreMetadata

type StoreMetadata struct {
	StoreVersion int       `json:"store_version"`
	CreatedAt    time.Time `json:"created_at"`
}

StoreMetadata represents ~/.allegro/allegro.json.

Jump to

Keyboard shortcuts

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