ALR

Форк
1
/
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

19
package main
20

21
import (
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

31
var fixCmd = &cli.Command{
32
	Name:  "fix",
33
	Usage: "Attempt to fix problems with ALR",
34
	Action: func(c *cli.Context) error {
35
		ctx := c.Context
36
		log := loggerctx.From(ctx)
37

38
		db.Close()
39
		paths := config.GetPaths(ctx)
40

41
		log.Info("Removing cache directory").Send()
42

43
		err := os.RemoveAll(paths.CacheDir)
44
		if err != nil {
45
			log.Fatal("Unable to remove cache directory").Err(err).Send()
46
		}
47

48
		log.Info("Rebuilding cache").Send()
49

50
		err = os.MkdirAll(paths.CacheDir, 0o755)
51
		if err != nil {
52
			log.Fatal("Unable to create new cache directory").Err(err).Send()
53
		}
54

55
		err = repos.Pull(ctx, config.Config(ctx).Repos)
56
		if err != nil {
57
			log.Fatal("Error pulling repos").Err(err).Send()
58
		}
59

60
		log.Info("Done").Send()
61

62
		return nil
63
	},
64
}
65

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.