storage

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMinFreeSpace is the default minimum free space (1GB).
	DefaultMinFreeSpace = 1 * 1024 * 1024 * 1024

	// DefaultWarningThreshold is the default warning threshold (90%).
	DefaultWarningThreshold = 0.9

	// LargeFileThreshold defines what constitutes a large file (100MB).
	LargeFileThreshold = 100 * 1024 * 1024

	// OldFileAge defines what constitutes an old file (30 days).
	OldFileAge = 30 * 24 * time.Hour

	// PartialFileExtension is the extension used for partial downloads.
	PartialFileExtension = ".gdl.partial"

	// TempFilePrefix is the prefix used for temporary files.
	TempFilePrefix = "gdl_temp_"
)

Constants for space calculations.

Variables

This section is empty.

Functions

This section is empty.

Types

type CleanupCallback

type CleanupCallback func(suggestions []CleanupSuggestion)

CleanupCallback is called when cleanup suggestions are generated.

type CleanupSuggestion

type CleanupSuggestion struct {
	Type        CleanupType `json:"type"`
	Path        string      `json:"path"`
	Size        uint64      `json:"size"`
	Description string      `json:"description"`
	Priority    Priority    `json:"priority"`
	Safe        bool        `json:"safe"` // Whether it's safe to delete automatically
}

CleanupSuggestion represents a cleanup recommendation.

type CleanupType

type CleanupType int
const (
	// CleanupTemporaryFiles represents temporary files that can be safely deleted.
	CleanupTemporaryFiles CleanupType = iota

	// CleanupOldDownloads represents old download files.
	CleanupOldDownloads

	// CleanupPartialDownloads represents incomplete/corrupted downloads.
	CleanupPartialDownloads

	// CleanupDuplicateFiles represents duplicate files.
	CleanupDuplicateFiles

	// CleanupEmptyDirectories represents empty directories.
	CleanupEmptyDirectories

	// CleanupLargeFiles represents unusually large files.
	CleanupLargeFiles
)

func (CleanupType) String

func (ct CleanupType) String() string

String returns the string representation of CleanupType.

type Priority

type Priority int

Priority represents the cleanup priority.

const (
	// PriorityLow for low priority cleanup items.
	PriorityLow Priority = iota

	// PriorityMedium for medium priority cleanup items.
	PriorityMedium

	// PriorityHigh for high priority cleanup items.
	PriorityHigh

	// PriorityCritical for critical cleanup items.
	PriorityCritical
)

func (Priority) String

func (p Priority) String() string

String returns the string representation of Priority.

type SpaceCallback

type SpaceCallback func(current *SpaceInfo, initial *SpaceInfo, bytesDownloaded uint64)

SpaceCallback is called during space monitoring.

type SpaceChecker

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

SpaceChecker provides disk space monitoring and management functionality.

func NewSpaceChecker

func NewSpaceChecker() *SpaceChecker

NewSpaceChecker creates a new disk space checker.

func (*SpaceChecker) AddCleanupCallback

func (sc *SpaceChecker) AddCleanupCallback(callback CleanupCallback)

AddCleanupCallback adds a callback for cleanup suggestions.

func (*SpaceChecker) CheckAvailableSpace

func (sc *SpaceChecker) CheckAvailableSpace(path string, requiredBytes uint64) error

CheckAvailableSpace validates if there's enough space for a download.

func (*SpaceChecker) CleanupTempFiles

func (sc *SpaceChecker) CleanupTempFiles() (uint64, error)

CleanupTempFiles removes temporary files created by gdl.

func (*SpaceChecker) CreateTempFile

func (sc *SpaceChecker) CreateTempFile(dir, pattern string) (*os.File, error)

CreateTempFile creates a temporary file for download operations.

func (*SpaceChecker) ExecuteCleanup

func (sc *SpaceChecker) ExecuteCleanup(
	suggestions []CleanupSuggestion,
	safeOnly bool,
) (uint64, error)

ExecuteCleanup performs cleanup based on suggestions.

func (*SpaceChecker) GenerateCleanupSuggestions

func (sc *SpaceChecker) GenerateCleanupSuggestions(paths []string) ([]CleanupSuggestion, error)

GenerateCleanupSuggestions analyzes directories and generates cleanup recommendations.

func (*SpaceChecker) GetSpaceInfo

func (sc *SpaceChecker) GetSpaceInfo(path string) (*SpaceInfo, error)

GetSpaceInfo retrieves disk space information for a given path.

func (*SpaceChecker) StartMonitoring

func (sc *SpaceChecker) StartMonitoring(path string) (*SpaceMonitor, error)

StartMonitoring begins monitoring disk space during a download.

func (*SpaceChecker) WithDownloadDirs

func (sc *SpaceChecker) WithDownloadDirs(dirs []string) *SpaceChecker

WithDownloadDirs sets the download directories to monitor.

func (*SpaceChecker) WithMinFreeSpace

func (sc *SpaceChecker) WithMinFreeSpace(bytes uint64) *SpaceChecker

WithMinFreeSpace sets the minimum required free space.

func (*SpaceChecker) WithTempDirs

func (sc *SpaceChecker) WithTempDirs(dirs []string) *SpaceChecker

WithTempDirs sets the temporary directories to monitor.

func (*SpaceChecker) WithWarningThreshold

func (sc *SpaceChecker) WithWarningThreshold(threshold float64) *SpaceChecker

WithWarningThreshold sets the warning threshold (0.0-1.0).

type SpaceInfo

type SpaceInfo struct {
	TotalBytes     uint64  `json:"total_bytes"`
	FreeBytes      uint64  `json:"free_bytes"`
	UsedBytes      uint64  `json:"used_bytes"`
	AvailableBytes uint64  `json:"available_bytes"` // Available to non-privileged users
	UsagePercent   float64 `json:"usage_percent"`
	Path           string  `json:"path"`
}

SpaceInfo represents disk space information.

type SpaceMonitor

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

SpaceMonitor tracks space usage during downloads.

func (*SpaceMonitor) AddCallback

func (sm *SpaceMonitor) AddCallback(callback SpaceCallback)

AddCallback adds a space monitoring callback.

func (*SpaceMonitor) Monitor

func (sm *SpaceMonitor) Monitor(bytesDownloaded uint64)

Monitor continuously monitors disk space usage.

func (*SpaceMonitor) Stop

func (sm *SpaceMonitor) Stop()

Stop stops the space monitoring.

Jump to

Keyboard shortcuts

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