From 661d79ce24340fadf6d8f4c8169a238956df0d39 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sat, 14 Jun 2025 15:05:18 +0300 Subject: [PATCH] fix: remove debug logs and fix cache clearing --- assets/coverage-badge.svg | 4 ++-- fix.go | 30 ++++++++++++++++++++++++-- internal/build/script_executor.go | 1 - internal/cliutils/utils.go | 3 --- internal/translations/default.pot | 18 ++++++++-------- internal/translations/po/ru/default.po | 25 ++++++++++----------- 6 files changed, 52 insertions(+), 29 deletions(-) diff --git a/assets/coverage-badge.svg b/assets/coverage-badge.svg index 42e7827..a1c07ea 100644 --- a/assets/coverage-badge.svg +++ b/assets/coverage-badge.svg @@ -11,7 +11,7 @@ coverage coverage - 17.6% - 17.6% + 17.5% + 17.5% diff --git a/fix.go b/fix.go index 9f4fc6b..94f25c5 100644 --- a/fix.go +++ b/fix.go @@ -20,6 +20,7 @@ package main import ( + "io/fs" "log/slog" "os" "path/filepath" @@ -57,7 +58,6 @@ func FixCmd() *cli.Command { paths := cfg.GetPaths() slog.Info(gotext.Get("Clearing cache directory")) - // Remove all nested directories of paths.CacheDir dir, err := os.Open(paths.CacheDir) if err != nil { @@ -71,7 +71,13 @@ func FixCmd() *cli.Command { } for _, entry := range entries { - err = os.RemoveAll(filepath.Join(paths.CacheDir, entry)) + fullPath := filepath.Join(paths.CacheDir, entry) + + if err := makeWritableRecursive(fullPath); err != nil { + slog.Debug("Failed to make path writable", "path", fullPath, "error", err) + } + + err = os.RemoveAll(fullPath) if err != nil { return cliutils.FormatCliExit(gotext.Get("Unable to remove cache item (%s)", entry), err) } @@ -101,3 +107,23 @@ func FixCmd() *cli.Command { }, } } + +func makeWritableRecursive(path string) error { + return filepath.WalkDir(path, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + + info, err := d.Info() + if err != nil { + return err + } + + newMode := info.Mode() | 0o200 + if d.IsDir() { + newMode |= 0o100 + } + + return os.Chmod(path, newMode) + }) +} diff --git a/internal/build/script_executor.go b/internal/build/script_executor.go index c67edfd..b0bb8f7 100644 --- a/internal/build/script_executor.go +++ b/internal/build/script_executor.go @@ -200,7 +200,6 @@ func buildPkgMetadata( preferedContents *[]string, ) (*nfpm.Info, error) { pkgInfo := getBasePkgInfo(vars, input) - slog.Warn("vars.Description", "vars.Description", vars.Description, "vars.Description.Resolved", vars.Description.Resolved()) pkgInfo.Description = vars.Description.Resolved() pkgInfo.Platform = "linux" pkgInfo.Homepage = vars.Homepage.Resolved() diff --git a/internal/cliutils/utils.go b/internal/cliutils/utils.go index 48c4dc7..010d2e0 100644 --- a/internal/cliutils/utils.go +++ b/internal/cliutils/utils.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "log/slog" - "runtime/debug" "github.com/leonelquinteros/gotext" "github.com/urfave/cli/v2" @@ -45,12 +44,10 @@ func HandleExitCoder(err error) { slog.Error(err.Error()) } } - debug.PrintStack() cli.OsExiter(exitErr.ExitCode()) return } - debug.PrintStack() slog.Error(err.Error()) cli.OsExiter(1) } diff --git a/internal/translations/default.pot b/internal/translations/default.pot index ce8bc93..42457b4 100644 --- a/internal/translations/default.pot +++ b/internal/translations/default.pot @@ -58,11 +58,11 @@ msgstr "" msgid "Done" msgstr "" -#: fix.go:38 +#: fix.go:39 msgid "Attempt to fix problems with ALR" msgstr "" -#: fix.go:59 +#: fix.go:60 msgid "Clearing cache directory" msgstr "" @@ -74,15 +74,15 @@ msgstr "" msgid "Unable to read cache directory contents" msgstr "" -#: fix.go:76 +#: fix.go:82 msgid "Unable to remove cache item (%s)" msgstr "" -#: fix.go:80 +#: fix.go:86 msgid "Rebuilding cache" msgstr "" -#: fix.go:84 +#: fix.go:90 msgid "Unable to create new cache directory" msgstr "" @@ -224,15 +224,15 @@ msgstr "" msgid "Building package metadata" msgstr "" -#: internal/build/script_executor.go:276 +#: internal/build/script_executor.go:275 msgid "Executing prepare()" msgstr "" -#: internal/build/script_executor.go:285 +#: internal/build/script_executor.go:284 msgid "Executing build()" msgstr "" -#: internal/build/script_executor.go:314 internal/build/script_executor.go:334 +#: internal/build/script_executor.go:313 internal/build/script_executor.go:333 msgid "Executing %s()" msgstr "" @@ -336,7 +336,7 @@ msgstr "" msgid "OPTIONS" msgstr "" -#: internal/cliutils/utils.go:72 +#: internal/cliutils/utils.go:69 msgid "" "This command is deprecated and would be removed in the future, use \"%s\" " "instead!" diff --git a/internal/translations/po/ru/default.po b/internal/translations/po/ru/default.po index dd7d42c..4b47a80 100644 --- a/internal/translations/po/ru/default.po +++ b/internal/translations/po/ru/default.po @@ -65,11 +65,11 @@ msgstr "Ошибка при перемещении пакета" msgid "Done" msgstr "Сделано" -#: fix.go:38 +#: fix.go:39 msgid "Attempt to fix problems with ALR" msgstr "Попытка устранить проблемы с ALR" -#: fix.go:59 +#: fix.go:60 msgid "Clearing cache directory" msgstr "Очистка каталога кэша" @@ -81,15 +81,15 @@ msgstr "Невозможно открыть каталог кэша" msgid "Unable to read cache directory contents" msgstr "Невозможно прочитать содержимое каталога кэша" -#: fix.go:76 +#: fix.go:82 msgid "Unable to remove cache item (%s)" msgstr "Невозможно удалить элемент кэша (%s)" -#: fix.go:80 +#: fix.go:86 msgid "Rebuilding cache" msgstr "Восстановление кэша" -#: fix.go:84 +#: fix.go:90 msgid "Unable to create new cache directory" msgstr "Не удалось создать новый каталог кэша" @@ -235,15 +235,15 @@ msgstr "" msgid "Building package metadata" msgstr "Сборка метаданных пакета" -#: internal/build/script_executor.go:276 +#: internal/build/script_executor.go:275 msgid "Executing prepare()" msgstr "Выполнение prepare()" -#: internal/build/script_executor.go:285 +#: internal/build/script_executor.go:284 msgid "Executing build()" msgstr "Выполнение build()" -#: internal/build/script_executor.go:314 internal/build/script_executor.go:334 +#: internal/build/script_executor.go:313 internal/build/script_executor.go:333 msgid "Executing %s()" msgstr "Выполнение %s()" @@ -347,7 +347,7 @@ msgstr "КАТЕГОРИЯ" msgid "OPTIONS" msgstr "ПАРАМЕТРЫ" -#: internal/cliutils/utils.go:72 +#: internal/cliutils/utils.go:69 msgid "" "This command is deprecated and would be removed in the future, use \"%s\" " "instead!" @@ -569,6 +569,10 @@ msgstr "Ошибка при проверке обновлений" msgid "There is nothing to do." msgstr "Здесь нечего делать." +#, fuzzy +#~ msgid "Failed to clear contents of cache directory" +#~ msgstr "Не удалось создать каталог кэша репозитория" + #~ msgid "Error iterating over packages" #~ msgstr "Ошибка при переборе пакетов" @@ -587,9 +591,6 @@ msgstr "Здесь нечего делать." #~ msgid "Unable to create config directory" #~ msgstr "Не удалось создать каталог конфигурации ALR" -#~ msgid "Unable to create repo cache directory" -#~ msgstr "Не удалось создать каталог кэша репозитория" - #~ msgid "Unable to create package cache directory" #~ msgstr "Не удалось создать каталог кэша пакетов"