Refactor fetch and pacman packages into subpackages

Split fetch into alpm and aur subpackages for better organization.
Rename state to log. Split pacman into read and sync subpackages.
Remove validation in favor of read.DBFreshness.
This commit is contained in:
AI Bot
2026-04-18 18:18:23 +02:00
committed by Riyyi
parent 88ff093365
commit 83de6acc74
10 changed files with 607 additions and 536 deletions
+49
View File
@@ -0,0 +1,49 @@
package log
import (
"fmt"
"io"
"os"
"path/filepath"
"time"
)
// -----------------------------------------
var logFile *os.File
// -----------------------------------------
func OpenLog() error {
logPath := filepath.Join("/var/log", "declpac.log")
f, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
logFile = f
writeTimestamp()
return nil
}
func GetLogWriter() io.Writer {
return logFile
}
func Write(msg []byte) {
logFile.Write(msg)
}
func Close() error {
if logFile == nil {
return nil
}
return logFile.Close()
}
// -----------------------------------------
func writeTimestamp() {
ts := time.Now().Format("2006-01-02 15:04:05")
header := fmt.Sprintf("\n--- %s ---\n", ts)
logFile.Write([]byte(header))
}