state

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultInlineHashTimeout bounds synchronous hash work during pause persistence.
	// If hashing takes longer than this, we skip storing file_hash for this snapshot.
	DefaultInlineHashTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func AddToMasterList

func AddToMasterList(entry types.DownloadEntry) error

AddToMasterList adds or updates a download entry

func CheckDownloadExists

func CheckDownloadExists(url string) (bool, error)

CheckDownloadExists checks if a download with the given URL exists in the database

func CloseDB

func CloseDB()

func Configure

func Configure(path string)

Configure sets the path for the SQLite database

func DeleteState

func DeleteState(id string) error

DeleteState removes the state from SQLite

func DeleteTasks

func DeleteTasks(id string) error

DeleteTasks removes chunk task rows while preserving the download entry itself.

func GetDB

func GetDB() (*sql.DB, error)

GetDB is safe for concurrent use; it lazily opens the database so callers need not coordinate initialisation order with Configure().

func GetDownload

func GetDownload(id string) (*types.DownloadEntry, error)

GetDownload returns a single download by ID

func ListAllDownloads

func ListAllDownloads() ([]types.DownloadEntry, error)

ListAllDownloads returns all downloads

func LoadCompletedDownloads

func LoadCompletedDownloads() ([]types.DownloadEntry, error)

LoadCompletedDownloads returns all completed downloads

func LoadMasterList

func LoadMasterList() (*types.MasterList, error)

LoadMasterList loads ALL downloads (paused and completed)

func LoadPausedDownloads

func LoadPausedDownloads() ([]types.DownloadEntry, error)

LoadPausedDownloads returns all paused downloads

func LoadState

func LoadState(url string, destPath string) (*types.DownloadState, error)

LoadState loads download state from SQLite

func LoadStates

func LoadStates(ids []string) (map[string]*types.DownloadState, error)

LoadStates loads multiple download states from SQLite in batch

func NormalizeStaleDownloads

func NormalizeStaleDownloads() (int, error)

NormalizeStaleDownloads converts any downloads stuck in "downloading" status to "paused". This handles crash recovery: if the process was killed (SIGKILL, power loss, terminal close without graceful shutdown) while a download was active, the entry remains in "downloading" status with no worker attached. Without normalization these entries are invisible to resumePausedDownloads() and appear as dead/frozen items in the TUI.

func PauseAllDownloads

func PauseAllDownloads() error

PauseAllDownloads pauses all non-completed downloads

func RemoveCompletedDownloads

func RemoveCompletedDownloads() (int64, error)

RemoveCompletedDownloads removes all completed downloads and returns count

func RemoveFromMasterList

func RemoveFromMasterList(id string) error

RemoveFromMasterList removes a download entry

func ResumeAllDownloads

func ResumeAllDownloads() error

ResumeAllDownloads resumes all paused downloads (sets to queued)

func SaveState

func SaveState(url string, destPath string, state *types.DownloadState) error

SaveState saves download state to SQLite

func SaveStateWithOptions

func SaveStateWithOptions(url string, destPath string, state *types.DownloadState, opts SaveStateOptions) error

SaveStateWithOptions saves download state to SQLite with custom persistence options.

func URLHash

func URLHash(url string) string

URLHash returns a short hash of the URL for master list keying This is used for tracking completed downloads by URL

func UpdateStatus

func UpdateStatus(id string, status string) error

UpdateStatus updates the status of a download by ID

func UpdateURL

func UpdateURL(id string, newURL string) error

UpdateURL updates the URL of a download by ID

func ValidateIntegrity

func ValidateIntegrity() (int, error)

ValidateIntegrity checks that paused .surge files still exist and haven't been tampered with. Removes orphaned or corrupted entries from the database. Returns the number of entries removed.

Types

type SaveStateOptions

type SaveStateOptions struct {
	// SkipFileHash disables file_hash computation entirely for this save.
	SkipFileHash bool
	// InlineHashTimeout limits synchronous hashing time.
	// If zero or negative, DefaultInlineHashTimeout is used.
	InlineHashTimeout time.Duration
}

SaveStateOptions controls pause-state persistence behavior.

Jump to

Keyboard shortcuts

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