Skip to content

Commit 55084ef

Browse files
giulio93lucarin91
andcommitted
Update internal/orchestrator/orchestrator.go
Co-authored-by: Luca Rinaldi <l.rinaldi@arduino.cc>
1 parent 9040206 commit 55084ef

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

internal/api/handlers/app_delete.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import (
1919
"log/slog"
2020
"net/http"
2121

22+
"github.com/docker/cli/cli/command"
23+
2224
"github.com/arduino/arduino-app-cli/internal/api/models"
2325
"github.com/arduino/arduino-app-cli/internal/orchestrator"
2426
"github.com/arduino/arduino-app-cli/internal/orchestrator/app"
2527
"github.com/arduino/arduino-app-cli/internal/render"
26-
"github.com/docker/cli/cli/command"
2728
)
2829

2930
func HandleAppDelete(

internal/orchestrator/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func CleanAppCache(
3232
return ErrCleanCacheRunningApp
3333
}
3434
// We try to remove docker related resources at best effort
35-
for range StopAndDestroyApp(ctx, app) {
35+
for range StopAndDestroyApp(ctx, docker, app) {
3636
// just consume the iterator
3737
}
3838
}

internal/orchestrator/orchestrator.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func stopAppWithCmd(ctx context.Context, docker command.Cli, app app.ArduinoApp,
388388
return
389389
}
390390
if appStatus.Status != StatusStarting && appStatus.Status != StatusRunning {
391-
yield(StreamMessage{error: fmt.Errorf("App %q is not running", app.Name)})
391+
yield(StreamMessage{data: fmt.Sprintf("app %q is not running", app.Name)})
392392
return
393393
}
394394

@@ -406,7 +406,6 @@ func stopAppWithCmd(ctx context.Context, docker command.Cli, app app.ArduinoApp,
406406
}
407407
})
408408

409-
fmt.Printf("this is the main sketch path:%s", app.MainSketchPath)
410409
if app.MainSketchPath != nil {
411410
// TODO: check that the app sketch is running before attempting to stop it.
412411

@@ -901,11 +900,18 @@ func CloneApp(
901900
}
902901

903902
func DeleteApp(ctx context.Context, dockerClient command.Cli, app app.ArduinoApp) error {
904-
for msg := range StopApp(ctx, dockerClient, app) {
905-
if msg.error != nil {
906-
return fmt.Errorf("failed to stop app: %w", msg.error)
903+
904+
runningApp, err := getRunningApp(ctx, dockerClient.Client())
905+
if err != nil {
906+
return err
907+
}
908+
if runningApp != nil && runningApp.FullPath.EqualsTo(app.FullPath) {
909+
// We try to remove docker related resources at best effort
910+
for range StopAndDestroyApp(ctx, dockerClient, app) {
911+
// just consume the iterator
907912
}
908913
}
914+
909915
return app.FullPath.RemoveAll()
910916
}
911917

0 commit comments

Comments
 (0)