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
This commit is contained in:
clawbot 2026-02-19 20:17:27 -08:00
parent 802518b917
commit 95a690e805
2 changed files with 7 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import (
"log/slog" "log/slog"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"sync" "sync"
"time" "time"
@ -715,7 +716,7 @@ func (svc *Service) cleanupCancelledDeploy(
prefix := fmt.Sprintf("%d-", deployment.ID) prefix := fmt.Sprintf("%d-", deployment.ID)
for _, entry := range entries { 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()) dirPath := filepath.Join(buildDir, entry.Name())
removeErr := os.RemoveAll(dirPath) removeErr := os.RemoveAll(dirPath)

View File

@ -6,6 +6,7 @@ import (
"log/slog" "log/slog"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"git.eeqj.de/sneak/upaas/internal/config" "git.eeqj.de/sneak/upaas/internal/config"
"git.eeqj.de/sneak/upaas/internal/docker" "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( func (svc *Service) CleanupCancelledDeploy(
ctx context.Context, ctx context.Context,
appName string, appName string,
@ -66,7 +69,7 @@ func (svc *Service) CleanupCancelledDeploy(
prefix := fmt.Sprintf("%d-", deploymentID) prefix := fmt.Sprintf("%d-", deploymentID)
for _, entry := range entries { 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()) dirPath := filepath.Join(buildDir, entry.Name())
_ = os.RemoveAll(dirPath) _ = os.RemoveAll(dirPath)
} }