@@ -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+
192223func 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