Skip to content

Commit f32ac9e

Browse files
mirkoCrobumirkoCrobu
andauthored
feat: add cache cleanup in system update
Co-authored-by: mirkoCrobu <mirkocrobu@NB-0531.localdomain>
1 parent 395dd88 commit f32ac9e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
%sysupgrade ALL=(ALL) NOPASSWD: /usr/bin/apt-get update, /usr/sbin/needrestart -r a, /usr/bin/dpkg --configure -a, /usr/bin/apt-get install --only-upgrade -y *, /usr/bin/hostnamectl set-hostname *
1+
%sysupgrade ALL=(ALL) NOPASSWD: /usr/bin/apt-get update, /usr/sbin/needrestart -r a, /usr/bin/dpkg --configure -a, /usr/bin/apt-get install --only-upgrade -y *, /usr/bin/apt-get clean -y, /usr/bin/hostnamectl set-hostname *

internal/update/apt/service.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ func (s *Service) UpgradePackages(ctx context.Context, names []string) (<-chan u
8585
}
8686
eventsCh <- update.Event{Type: update.UpgradeLineEvent, Data: line}
8787
}
88+
eventsCh <- update.Event{Type: update.StartEvent, Data: "apt cleaning cache is starting"}
89+
for line, err := range runAptCleanCommand(ctx) {
90+
if err != nil {
91+
eventsCh <- update.Event{
92+
Type: update.ErrorEvent,
93+
Err: err,
94+
Data: "Error running apt clean command",
95+
}
96+
slog.Error("error processing apt clean command output", "error", err)
97+
return
98+
}
99+
eventsCh <- update.Event{Type: update.UpgradeLineEvent, Data: line}
100+
}
88101
// TEMPORARY PATCH: stopping and destroying docker containers and images since IDE does not implement it yet.
89102
// TODO: Remove this workaround once IDE implements it.
90103
// Tracking issue: https://github.com/arduino/arduino-app-cli/issues/623
@@ -189,6 +202,24 @@ func runUpgradeCommand(ctx context.Context, names []string) iter.Seq2[string, er
189202

190203
}
191204

205+
func runAptCleanCommand(ctx context.Context) iter.Seq2[string, error] {
206+
return func(yield func(string, error) bool) {
207+
cleanCmd, err := paths.NewProcess(nil, "sudo", "apt-get", "clean", "-y")
208+
if err != nil {
209+
_ = yield("", err)
210+
return
211+
}
212+
stdout := orchestrator.NewCallbackWriter(func(line string) {
213+
_ = yield(line, nil)
214+
})
215+
cleanCmd.RedirectStderrTo(stdout)
216+
cleanCmd.RedirectStdoutTo(stdout)
217+
if err := cleanCmd.RunWithinContext(ctx); err != nil {
218+
_ = yield("", err)
219+
}
220+
}
221+
}
222+
192223
func pullDockerImages(ctx context.Context) iter.Seq2[string, error] {
193224
return func(yield func(string, error) bool) {
194225
cmd, err := paths.NewProcess(nil, "arduino-app-cli", "system", "init")

0 commit comments

Comments
 (0)