blobstore

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyWithContext

func CopyWithContext(ctx context.Context, dst io.Writer, src io.Reader, buf []byte) (int64, error)

CopyWithContext copies bytes from src to dst using the provided buffer, periodically checking ctx for cancellation.

It behaves similarly to io.CopyBuffer, but allows the caller to cancel long-running copy operations (e.g., very large archives) via context.

The function:

  • Reads into the provided reusable buffer (no allocations inside the loop)
  • Writes each chunk fully before proceeding
  • Returns the total number of bytes successfully written
  • Stops early if ctx is canceled

This is useful when ingesting large blobs where we want the CLI to remain interruptible (Ctrl+C, timeouts, etc.) without relying on OS-level signals to interrupt a blocking read.

func EnsureBlobRecorded

func EnsureBlobRecorded(
	ctx context.Context,
	q *dbq.Queries,
	sha256 string,
	kind string,
	sizeBytes int64,
	originalName *string,
) error

EnsureBlobRecorded ensures the blobs table has a row for sha256, enforcing invariants:

  • if the blob already exists, its kind and size must match
  • otherwise, insert it

verified_at is set only on insert. For existing blobs, verified_at is reserved for doctor --deep (rehash verification), not for "we saw a file".

Types

type BackupResult

type BackupResult struct {
	SHA256Hex string
	SizeBytes int64
	// Existed is true if the blob was already in the backup store (deduped)
	Existed bool
}

BackupResult is the outcome of a successful IngestBackup call

func IngestBackup

func IngestBackup(
	ctx context.Context,
	db *sql.DB,
	q *dbq.Queries,
	bs Store,
	srcPath string,
	gameInstallID int64,
	targetID int64,
	relpath string,
	operationID sql.NullInt64,
	originalContentSha256 string,
) (BackupResult, error)

IngestBackup copies srcPath into the backup blob store, records the blob, and upserts the backups row - all within a single transaction.

srcPath is the on-disk path of the pre-existing file to back up. originalContentSha256 is the hash of the file computed before ingestion, if already available; pass empty string if not.

type IngestResult

type IngestResult struct {
	SHA256Hex string
	SizeBytes int64
	Existed   bool
}

type Kind

type Kind string
const (
	KindArchive  Kind = "archive"
	KindBackup   Kind = "backup"
	KindOverride Kind = "override"
)

type Store

type Store struct {
	ArchivesDir  string
	BackupsDir   string
	OverridesDir string
	TmpDir       string
}

func (Store) IngestFile

func (s Store) IngestFile(ctx context.Context, kind Kind, srcPath string) (IngestResult, error)

IngestFile streams srcPath into the blob store, addressed by sha256. Writes a temp file in the destination directory and renames into place atomically.

func (Store) PathFor

func (s Store) PathFor(kind Kind, shaHex string) (string, error)

PathFor returns: <root>/ab/<fullhash>

func (Store) RootFor

func (s Store) RootFor(kind Kind) (string, error)

Jump to

Keyboard shortcuts

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