cache clean implemented

This commit is contained in:
2026-05-29 03:46:47 -06:00
parent a9de607743
commit 248c1370d7
9 changed files with 48 additions and 17 deletions
+22 -12
View File
@@ -3,14 +3,18 @@ package main
import (
"fmt"
"os"
"strconv"
"strings"
"time"
"github.com/BurntSushi/toml"
)
type rawConfig struct {
Config
EnvFile string `toml:"env_file"`
EnvFile string `toml:"env_file"`
MaxCacheSize string `toml:"max_cache_size"`
MaxCacheAgeStr string `toml:"max_cache_age"`
}
type Config struct {
@@ -19,19 +23,10 @@ type Config struct {
MirroredRepos []string `toml:"mirrored_repos"`
Port string `toml:"port"`
Token string
MaxCacheSize int64
MaxCacheAge time.Duration
}
/* Function kept for reference for future logic
func NewConfig() *Config {
return &Config{
CacheRoot: "/home/ewpt3ch/dev/pacman-cache-server/tmprepo",
MirrorURLs: "https://us.mirrors.cicku.me/archlinux/",
Port: "8090",
Auth: AuthConfig{Token: "FakeToken"},
}
}
*/
func ReadConfig(path string) (*Config, error) {
var rawcfg rawConfig
@@ -47,6 +42,21 @@ func ReadConfig(path string) (*Config, error) {
return nil, fmt.Errorf("error getting token: %v", err)
}
if rawcfg.MaxCacheSize == "" {
return nil, fmt.Errorf("max_cache_size must be set")
}
sizeBytes, err := strconv.ParseInt(strings.TrimSuffix(rawcfg.MaxCacheSize, "GB"), 10, 64)
sizeBytes = sizeBytes * 1024 * 1024 * 1024
if err != nil {
return nil, fmt.Errorf("invalid cache size string")
}
cfg.MaxCacheSize = sizeBytes
cfg.MaxCacheAge, err = time.ParseDuration(rawcfg.MaxCacheAgeStr)
if err != nil {
return nil, fmt.Errorf("error getting max_cache_age: %v", err)
}
if err = cfg.validate(); err != nil {
return nil, fmt.Errorf("invalid config: %w", err)
}