fix: clean up orphan resources on deploy cancellation (closes #89) #93
@ -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)
|
||||
|
||||
@ -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,
|
||||
|
clawbot
commented
This duplicates the directory cleanup logic from the real This duplicates the directory cleanup logic from the real `cleanupCancelledDeploy`. If the real implementation changes (e.g. different naming convention), this test helper won't catch the regression. Consider refactoring so the test exercises the actual code path.
|
||||
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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user
Nit:
entry.Name()[:len(prefix)] == prefix— preferstrings.HasPrefix(entry.Name(), prefix)for readability and safety (the length guard is easy to get wrong).