This commit is contained in:
2025-04-12 15:51:39 +03:00
parent 5ca34a572a
commit 8070112bf2
45 changed files with 2728 additions and 1196 deletions

26
fix.go
View File

@ -22,12 +22,14 @@ package main
import (
"log/slog"
"os"
"path/filepath"
"github.com/leonelquinteros/gotext"
"github.com/urfave/cli/v2"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
database "gitea.plemya-x.ru/Plemya-x/ALR/internal/db"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
)
@ -36,6 +38,11 @@ func FixCmd() *cli.Command {
Name: "fix",
Usage: gotext.Get("Attempt to fix problems with ALR"),
Action: func(c *cli.Context) error {
if utils.DropCapsToAlrUser() != nil {
slog.Error(gotext.Get("Can't drop privileges"))
os.Exit(1)
}
ctx := c.Context
cfg := config.New()
err := cfg.Load()
@ -48,11 +55,26 @@ func FixCmd() *cli.Command {
slog.Info(gotext.Get("Removing cache directory"))
err = os.RemoveAll(paths.CacheDir)
dir, err := os.Open(paths.CacheDir)
if err != nil {
slog.Error(gotext.Get("Unable to remove cache directory"), "err", err)
slog.Error(gotext.Get("Unable to open cache directory"), "err", err)
os.Exit(1)
}
defer dir.Close()
entries, err := dir.Readdirnames(-1)
if err != nil {
slog.Error(gotext.Get("Unable to read cache directory contents"), "err", err)
os.Exit(1)
}
for _, entry := range entries {
err = os.RemoveAll(filepath.Join(paths.CacheDir, entry))
if err != nil {
slog.Error(gotext.Get("Unable to remove cache item"), "item", entry, "err", err)
os.Exit(1)
}
}
slog.Info(gotext.Get("Rebuilding cache"))