filesystem

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriftDir     = storage.DriftDir
	ChunksDir    = storage.ChunksDir
	SnapshotsDir = storage.SnapshotsDir
	ManifestsDir = storage.ManifestsDir
	RefsDir      = storage.RefsDir
	PreviewsDir  = storage.PreviewsDir
	HeadsDir     = storage.HeadsDir
	TagsDir      = storage.TagsDir
	LogsDir      = storage.LogsDir
	HeadFile     = storage.HeadFile
	IndexFile    = storage.IndexFile
	ConfigFile   = storage.ConfigFile
	PacksDir     = storage.PacksDir
)

Layout constants are re-exported from the storage interface package so existing references within the filesystem backend continue to work. The single source of truth is storage/layout.go; keeping the canonical constants in the storage package lets the remote package depend on storage only, without reaching into a concrete backend.

Variables

This section is empty.

Functions

This section is empty.

Types

type FSStorage

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

func NewFSStorage

func NewFSStorage(root string) (*FSStorage, error)

func (*FSStorage) Close

func (fs *FSStorage) Close() error

func (*FSStorage) CompactChunks

func (fs *FSStorage) CompactChunks(ctx context.Context, reachable map[core.Hash]bool, dryRun bool) (storage.CompactReport, error)

CompactChunks implements storage.ChunkCompactor for the filesystem backend.

func (*FSStorage) DeleteChunk

func (fs *FSStorage) DeleteChunk(ctx context.Context, hash core.Hash) error

DeleteChunk removes a loose chunk from disk and evicts it from the in-memory cache. It is idempotent: a missing file is not an error.

DeleteChunk only removes loose chunks; packed chunks are not affected and must be reclaimed via CompactChunks.

func (*FSStorage) DeleteRef

func (fs *FSStorage) DeleteRef(ctx context.Context, name string) error

func (*FSStorage) DeleteSnapshot

func (fs *FSStorage) DeleteSnapshot(ctx context.Context, id core.SnapshotID) error

DeleteSnapshot removes a snapshot and its manifest from disk. It is idempotent: a missing file is not an error.

func (*FSStorage) GetChunk

func (fs *FSStorage) GetChunk(ctx context.Context, hash core.Hash) (*core.Chunk, error)

func (*FSStorage) GetConfig

func (fs *FSStorage) GetConfig(ctx context.Context) (*core.Config, error)

GetConfig reads the drift configuration from the config file. The file is unmarshaled on top of DefaultConfig(), so fields absent from the JSON retain their default values rather than Go zero values. This matters for bool fields like Compression (zero=false vs default=true) and for int fields where 0 is not a valid size.

func (*FSStorage) GetIndex

func (fs *FSStorage) GetIndex(ctx context.Context) (*core.Index, error)

GetIndex reads the staging index from disk.

func (*FSStorage) GetPreview

func (fs *FSStorage) GetPreview(ctx context.Context, hash core.Hash, size int) ([]byte, error)

GetPreview is a noop stub (Phase 1). Returns ErrNotFound so callers can distinguish "no preview" from "preview feature disabled"; matches the memory backend's behavior.

func (*FSStorage) GetRef

func (fs *FSStorage) GetRef(ctx context.Context, name string) (*core.Reference, error)

func (*FSStorage) GetSnapshot

func (fs *FSStorage) GetSnapshot(ctx context.Context, id core.SnapshotID) (*core.Snapshot, error)

GetSnapshot reads a snapshot from disk and verifies its integrity.

Memory layout: the file is read in full (io.ReadAll), unmarshalled into a SnapshotProto, then the proto is re-marshaled with IdHash cleared for the BLAKE3 integrity check. Peak memory is therefore roughly raw + decoded + re-marshaled. To minimize the peak we:

  • drop the raw buffer reference before re-marshaling (the decoder has already produced an independent copy of the message);
  • run the hash incrementally over the re-marshaled bytes via a streaming blake3 hasher and drop each chunk immediately, so the re-marshaled buffer does not need to live alongside the decoded message.

google.golang.org/protobuf (v1.36.x) does not expose a reader-based streaming decoder (proto.NewDecoder was removed in the github.com/golang/protobuf v1.5.0 shim), so the initial io.ReadAll is unavoidable without a much larger refactor.

func (*FSStorage) HasChunk

func (fs *FSStorage) HasChunk(ctx context.Context, hash core.Hash) (bool, error)

func (*FSStorage) ListChunks

func (fs *FSStorage) ListChunks(ctx context.Context) ([]core.Hash, error)

func (*FSStorage) ListRefs

func (fs *FSStorage) ListRefs(ctx context.Context, prefix string) ([]*core.Reference, error)

func (*FSStorage) ListSnapshots

func (fs *FSStorage) ListSnapshots(ctx context.Context, opts *storage.ListOptions) ([]*core.SnapshotSummary, error)

ListSnapshots lists all snapshots via lightweight manifests, sorted by timestamp descending, with optional limit/offset pagination. Returns snapshot summaries without file lists — call GetSnapshot for full details.

Snapshots without a manifest (e.g. created before manifests were introduced) fall back to reading the full snapshot file and backfilling a manifest so subsequent listings are fast.

func (*FSStorage) PutChunk

func (fs *FSStorage) PutChunk(ctx context.Context, chunk *core.Chunk) error

PutChunk stores a chunk to disk. The chunk data is verified against its declared hash before persisting, so a caller-supplied mismatch can never reach disk and cause later GetChunk integrity failures. If the chunk already exists (loose or in a pack), PutChunk is a no-op.

Writes are not verified by re-reading; on-disk corruption is detected on the subsequent GetChunk via the BLAKE3 integrity check.

func (*FSStorage) PutPreview

func (fs *FSStorage) PutPreview(ctx context.Context, hash core.Hash, size int, data []byte) error

PutPreview is a noop stub (Phase 1).

func (*FSStorage) PutSnapshot

func (fs *FSStorage) PutSnapshot(ctx context.Context, snapshot *core.Snapshot) error

PutSnapshot writes a snapshot and its lightweight manifest to disk.

func (*FSStorage) SetCompressionConfig

func (fs *FSStorage) SetCompressionConfig(enabled bool, level int) error

SetCompressionConfig applies the compression settings to the backend. enabled toggles zstd compression of chunk payloads; level is the zstd command-line level (1-19) and is converted to the library's EncoderLevel internally. This satisfies storage.ConfigStorer so porcelain can apply config uniformly across backends without type-asserting to FSStorage.

func (*FSStorage) SetConfig

func (fs *FSStorage) SetConfig(ctx context.Context, config *core.Config) error

SetConfig writes the drift configuration to the config file.

func (*FSStorage) SetIndex

func (fs *FSStorage) SetIndex(ctx context.Context, index *core.Index) error

SetIndex writes the staging index to disk.

func (*FSStorage) SetRef

func (fs *FSStorage) SetRef(ctx context.Context, name string, ref *core.Reference) error

Jump to

Keyboard shortcuts

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