From 95a690e805acf5d2c046109a512e1873bccf43af Mon Sep 17 00:00:00 2001 From: clawbot Date: Thu, 19 Feb 2026 20:17:27 -0800 Subject: [PATCH] fix: use strings.HasPrefix instead of manual slice comparison - Replace entry.Name()[:len(prefix)] == prefix with strings.HasPrefix - Applied consistently in both deploy.go and export_test.go --- internal/service/deploy/deploy.go | 3 ++- internal/service/deploy/export_test.go | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/service/deploy/deploy.go b/internal/service/deploy/deploy.go index 81d79f6..19a65a4 100644 --- a/internal/service/deploy/deploy.go +++ b/internal/service/deploy/deploy.go @@ -11,6 +11,7 @@ import ( "log/slog" "os" "path/filepath" + "strings" "sync" "time" @@ -715,7 +716,7 @@ func (svc *Service) cleanupCancelledDeploy( prefix := fmt.Sprintf("%d-", deployment.ID) for _, entry := range entries { - if entry.IsDir() && len(entry.Name()) > len(prefix) && entry.Name()[:len(prefix)] == prefix { + if entry.IsDir() && strings.HasPrefix(entry.Name(), prefix) { dirPath := filepath.Join(buildDir, entry.Name()) removeErr := os.RemoveAll(dirPath) diff --git a/internal/service/deploy/export_test.go b/internal/service/deploy/export_test.go index 8e3bf33..a5aa241 100644 --- a/internal/service/deploy/export_test.go +++ b/internal/service/deploy/export_test.go @@ -6,6 +6,7 @@ import ( "log/slog" "os" "path/filepath" + "strings" "git.eeqj.de/sneak/upaas/internal/config" "git.eeqj.de/sneak/upaas/internal/docker" @@ -47,7 +48,9 @@ func NewTestServiceWithConfig(log *slog.Logger, cfg *config.Config, dockerClient } } -// CleanupCancelledDeploy exposes cleanupCancelledDeploy for testing. +// CleanupCancelledDeploy exposes the build directory cleanup portion of +// cleanupCancelledDeploy for testing. It removes build directories matching +// the deployment ID prefix. func (svc *Service) CleanupCancelledDeploy( ctx context.Context, appName string, @@ -66,7 +69,7 @@ func (svc *Service) CleanupCancelledDeploy( prefix := fmt.Sprintf("%d-", deploymentID) for _, entry := range entries { - if entry.IsDir() && len(entry.Name()) > len(prefix) && entry.Name()[:len(prefix)] == prefix { + if entry.IsDir() && strings.HasPrefix(entry.Name(), prefix) { dirPath := filepath.Join(buildDir, entry.Name()) _ = os.RemoveAll(dirPath) }