2 Commits

2 changed files with 3 additions and 7 deletions

View File

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

View File

@@ -6,7 +6,6 @@ import (
"log/slog"
"os"
"path/filepath"
"strings"
"git.eeqj.de/sneak/upaas/internal/config"
"git.eeqj.de/sneak/upaas/internal/docker"
@@ -48,9 +47,7 @@ func NewTestServiceWithConfig(log *slog.Logger, cfg *config.Config, dockerClient
}
}
// CleanupCancelledDeploy exposes the build directory cleanup portion of
// cleanupCancelledDeploy for testing. It removes build directories matching
// the deployment ID prefix.
// CleanupCancelledDeploy exposes cleanupCancelledDeploy for testing.
func (svc *Service) CleanupCancelledDeploy(
ctx context.Context,
appName string,
@@ -69,7 +66,7 @@ func (svc *Service) CleanupCancelledDeploy(
prefix := fmt.Sprintf("%d-", deploymentID)
for _, entry := range entries {
if entry.IsDir() && strings.HasPrefix(entry.Name(), prefix) {
if entry.IsDir() && len(entry.Name()) > len(prefix) && entry.Name()[:len(prefix)] == prefix {
dirPath := filepath.Join(buildDir, entry.Name())
_ = os.RemoveAll(dirPath)
}