From 25315c3ed095e644aa8e1107145b27dfb81936a2 Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Tue, 2 Dec 2025 17:40:06 +0100 Subject: [PATCH 1/4] fix: force error on apt update --- internal/update/apt/service.go | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/internal/update/apt/service.go b/internal/update/apt/service.go index 860be68f..e21bd169 100644 --- a/internal/update/apt/service.go +++ b/internal/update/apt/service.go @@ -153,7 +153,19 @@ func runDpkgConfigureCommand(ctx context.Context) error { } func runUpdateCommand(ctx context.Context) error { - cmd, err := paths.NewProcess(nil, "sudo", "apt-get", "update") + // Create a temporary apt config file for passing custom option, + // without changing the sudoers file. + config, rmConfig, err := getAptUpdateConfigFile() + if err != nil { + slog.Warn("cannot write apt config file, skipped", slog.String("error", err.Error())) + return err + } + defer rmConfig() + + cmd, err := paths.NewProcess( + []string{"APT_CONFIG", config.String()}, + "sudo", "apt-get", "update", + ) if err != nil { return err } @@ -163,6 +175,27 @@ func runUpdateCommand(ctx context.Context) error { return nil } +func getAptUpdateConfigFile() (*paths.Path, func(), error) { + // Configure apt return error on any warning during update. + configContent := []byte(`APT::Update::Error-Mode "any";`) + + config, err := paths.MkTempFile(nil, "apt.config") + if err != nil { + return nil, nil, fmt.Errorf("cannot create apt config file: %w", err) + } + + if _, err = config.Write(configContent); err != nil { + return nil, nil, fmt.Errorf("cannot write temporary apt config file: %w", err) + } + + path, err := paths.New(config.Name()).Abs() + if err != nil { + return nil, nil, fmt.Errorf("cannot get absolute apt config file path: %w", err) + } + + return path, func() { _ = path.Remove() }, nil +} + func runUpgradeCommand(ctx context.Context, names []string) iter.Seq2[string, error] { env := []string{"NEEDRESTART_MODE=l"} From 7f06d141a5bf05a43db6115c2c6b4137c6b53a07 Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Tue, 2 Dec 2025 17:50:53 +0100 Subject: [PATCH 2/4] embed file --- internal/update/apt/apt_update.config | 1 + internal/update/apt/service.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 internal/update/apt/apt_update.config diff --git a/internal/update/apt/apt_update.config b/internal/update/apt/apt_update.config new file mode 100644 index 00000000..d0670512 --- /dev/null +++ b/internal/update/apt/apt_update.config @@ -0,0 +1 @@ + APT::Update::Error-Mode "any"; diff --git a/internal/update/apt/service.go b/internal/update/apt/service.go index e21bd169..d4599285 100644 --- a/internal/update/apt/service.go +++ b/internal/update/apt/service.go @@ -18,6 +18,7 @@ package apt import ( "bufio" "context" + _ "embed" "fmt" "io" "iter" @@ -175,16 +176,16 @@ func runUpdateCommand(ctx context.Context) error { return nil } -func getAptUpdateConfigFile() (*paths.Path, func(), error) { - // Configure apt return error on any warning during update. - configContent := []byte(`APT::Update::Error-Mode "any";`) +//go:embed apt_update.config +var aptUpdateConfig []byte +func getAptUpdateConfigFile() (*paths.Path, func(), error) { config, err := paths.MkTempFile(nil, "apt.config") if err != nil { return nil, nil, fmt.Errorf("cannot create apt config file: %w", err) } - if _, err = config.Write(configContent); err != nil { + if _, err = config.Write(aptUpdateConfig); err != nil { return nil, nil, fmt.Errorf("cannot write temporary apt config file: %w", err) } From 9db56a5397a1089da25af64b2bb05d91a0900f4f Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Tue, 2 Dec 2025 18:16:00 +0100 Subject: [PATCH 3/4] use global apt config --- .../etc/apt/apt.conf.d/20updateerrors | 1 + internal/update/apt/apt_update.config | 1 - internal/update/apt/service.go | 35 +------------------ 3 files changed, 2 insertions(+), 35 deletions(-) create mode 100644 debian/arduino-app-cli/etc/apt/apt.conf.d/20updateerrors delete mode 100644 internal/update/apt/apt_update.config diff --git a/debian/arduino-app-cli/etc/apt/apt.conf.d/20updateerrors b/debian/arduino-app-cli/etc/apt/apt.conf.d/20updateerrors new file mode 100644 index 00000000..7f64d78a --- /dev/null +++ b/debian/arduino-app-cli/etc/apt/apt.conf.d/20updateerrors @@ -0,0 +1 @@ +APT::Update::Error-Mode "any"; diff --git a/internal/update/apt/apt_update.config b/internal/update/apt/apt_update.config deleted file mode 100644 index d0670512..00000000 --- a/internal/update/apt/apt_update.config +++ /dev/null @@ -1 +0,0 @@ - APT::Update::Error-Mode "any"; diff --git a/internal/update/apt/service.go b/internal/update/apt/service.go index d4599285..eff39a7e 100644 --- a/internal/update/apt/service.go +++ b/internal/update/apt/service.go @@ -154,19 +154,7 @@ func runDpkgConfigureCommand(ctx context.Context) error { } func runUpdateCommand(ctx context.Context) error { - // Create a temporary apt config file for passing custom option, - // without changing the sudoers file. - config, rmConfig, err := getAptUpdateConfigFile() - if err != nil { - slog.Warn("cannot write apt config file, skipped", slog.String("error", err.Error())) - return err - } - defer rmConfig() - - cmd, err := paths.NewProcess( - []string{"APT_CONFIG", config.String()}, - "sudo", "apt-get", "update", - ) + cmd, err := paths.NewProcess(nil, "sudo", "apt-get", "update") if err != nil { return err } @@ -176,27 +164,6 @@ func runUpdateCommand(ctx context.Context) error { return nil } -//go:embed apt_update.config -var aptUpdateConfig []byte - -func getAptUpdateConfigFile() (*paths.Path, func(), error) { - config, err := paths.MkTempFile(nil, "apt.config") - if err != nil { - return nil, nil, fmt.Errorf("cannot create apt config file: %w", err) - } - - if _, err = config.Write(aptUpdateConfig); err != nil { - return nil, nil, fmt.Errorf("cannot write temporary apt config file: %w", err) - } - - path, err := paths.New(config.Name()).Abs() - if err != nil { - return nil, nil, fmt.Errorf("cannot get absolute apt config file path: %w", err) - } - - return path, func() { _ = path.Remove() }, nil -} - func runUpgradeCommand(ctx context.Context, names []string) iter.Seq2[string, error] { env := []string{"NEEDRESTART_MODE=l"} From ff87813a88ad080cf3370c844e2f3fd50b4a916c Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Tue, 2 Dec 2025 18:25:37 +0100 Subject: [PATCH 4/4] fixup! use global apt config --- internal/update/apt/service.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/update/apt/service.go b/internal/update/apt/service.go index eff39a7e..860be68f 100644 --- a/internal/update/apt/service.go +++ b/internal/update/apt/service.go @@ -18,7 +18,6 @@ package apt import ( "bufio" "context" - _ "embed" "fmt" "io" "iter"