ALR
/
fix.go
64 строки · 1.6 Кб
1/*
2* ALR - Any Linux Repository
3* Copyright (C) 2024 Евгений Храмов
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19package main
20
21import (
22"os"
23
24"github.com/urfave/cli/v2"
25"plemya-x.ru/alr/internal/config"
26"plemya-x.ru/alr/internal/db"
27"plemya-x.ru/alr/pkg/loggerctx"
28"plemya-x.ru/alr/pkg/repos"
29)
30
31var fixCmd = &cli.Command{
32Name: "fix",
33Usage: "Attempt to fix problems with ALR",
34Action: func(c *cli.Context) error {
35ctx := c.Context
36log := loggerctx.From(ctx)
37
38db.Close()
39paths := config.GetPaths(ctx)
40
41log.Info("Removing cache directory").Send()
42
43err := os.RemoveAll(paths.CacheDir)
44if err != nil {
45log.Fatal("Unable to remove cache directory").Err(err).Send()
46}
47
48log.Info("Rebuilding cache").Send()
49
50err = os.MkdirAll(paths.CacheDir, 0o755)
51if err != nil {
52log.Fatal("Unable to create new cache directory").Err(err).Send()
53}
54
55err = repos.Pull(ctx, config.Config(ctx).Repos)
56if err != nil {
57log.Fatal("Error pulling repos").Err(err).Send()
58}
59
60log.Info("Done").Send()
61
62return nil
63},
64}
65