state

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChunkRow

type ChunkRow struct {
	URL    string
	Dest   string
	Index  int
	Start  int64
	End    int64
	Size   int64
	SHA256 string
	Status string // pending | running | complete | dirty
}

type DB

type DB struct {
	SQL  *sql.DB
	Path string
	// contains filtered or unexported fields
}

func Open

func Open(cfg *config.Config) (*DB, error)

func (*DB) ClearHostCaps

func (db *DB) ClearHostCaps() error

ClearHostCaps deletes all host capabilities from the cache.

func (*DB) DeleteChunks

func (db *DB) DeleteChunks(url, dest string) error

DeleteChunks removes all chunk rows for a given url+dest pair.

func (*DB) DeleteChunksTx

func (db *DB) DeleteChunksTx(tx *sql.Tx, url, dest string) error

func (*DB) DeleteDownload

func (db *DB) DeleteDownload(url, dest string) error

DeleteDownload removes a download row for the given url+dest.

func (*DB) DeleteHostCaps

func (db *DB) DeleteHostCaps(host string) error

DeleteHostCaps deletes a single host from the cache.

func (*DB) GetHostCaps

func (db *DB) GetHostCaps(host string) (HostCaps, bool, error)

func (*DB) IncDownloadRetries

func (db *DB) IncDownloadRetries(url, dest string, delta int64) error

IncDownloadRetries increments the retries counter for a download row.

func (*DB) InitChunksTable

func (db *DB) InitChunksTable() error

func (*DB) InitHostCapsTable

func (db *DB) InitHostCapsTable() error

func (*DB) ListChunks

func (db *DB) ListChunks(url, dest string) ([]ChunkRow, error)

func (*DB) ListDownloads

func (db *DB) ListDownloads() ([]DownloadRow, error)

ListDownloads returns a snapshot of the downloads table

func (*DB) ListHostCaps

func (db *DB) ListHostCaps() ([]HostCaps, error)

ListHostCaps returns all cached host capabilities.

func (*DB) UpdateChunkSHA

func (db *DB) UpdateChunkSHA(url, dest string, idx int, sha string) error

func (*DB) UpdateChunkSHATx

func (db *DB) UpdateChunkSHATx(tx *sql.Tx, url, dest string, idx int, sha string) error

func (*DB) UpdateChunkStatus

func (db *DB) UpdateChunkStatus(url, dest string, idx int, status string) error

func (*DB) UpdateChunkStatusTx

func (db *DB) UpdateChunkStatusTx(tx *sql.Tx, url, dest string, idx int, status string) error

func (*DB) UpdateDownloadStatus

func (db *DB) UpdateDownloadStatus(url, dest, status, lastError string) error

UpdateDownloadStatus updates only status and last_error, preserving other fields.

func (*DB) UpsertChunk

func (db *DB) UpsertChunk(c ChunkRow) error

func (*DB) UpsertChunkTx

func (db *DB) UpsertChunkTx(tx *sql.Tx, c ChunkRow) error

Tx variants for grouping operations atomically

func (*DB) UpsertDownload

func (db *DB) UpsertDownload(row DownloadRow) error

func (*DB) UpsertHostCaps

func (db *DB) UpsertHostCaps(host string, headOK, acceptRanges bool) error

func (*DB) WithTx

func (db *DB) WithTx(fn func(tx *sql.Tx) error) error

WithTx executes fn inside a transaction. If fn returns an error, the transaction is rolled back.

type DownloadRow

type DownloadRow struct {
	URL            string
	Dest           string
	ExpectedSHA256 string
	ActualSHA256   string
	ETag           string
	LastModified   string
	Size           int64
	Status         string
	Retries        int64
	CreatedAt      int64
	UpdatedAt      int64
	LastError      string
}

type HostCaps

type HostCaps struct {
	Host         string
	HeadOK       bool
	AcceptRanges bool
}

Jump to

Keyboard shortcuts

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