Clear Old Assets Path

This commit is contained in:
2026-04-18 11:02:38 +02:00
parent 5e900d00b5
commit b6ed92e3e8
2 changed files with 32 additions and 20 deletions
+5 -13
View File
@@ -145,10 +145,7 @@ func (p *Project) ValidateLayout() error {
} { } {
info, err := os.Stat(path) info, err := os.Stat(path)
if err != nil { if err != nil {
if label == "paths.assets" && errors.Is(err, os.ErrNotExist) && p.isCachePath(path) { if label == "paths.assets" && errors.Is(err, os.ErrNotExist) {
if mkErr := os.MkdirAll(path, 0o755); mkErr != nil {
failures = append(failures, fmt.Errorf("%s: create cache directory %s: %w", label, path, mkErr))
}
continue continue
} }
failures = append(failures, fmt.Errorf("%s: %w", label, err)) failures = append(failures, fmt.Errorf("%s: %w", label, err))
@@ -166,15 +163,6 @@ func (p *Project) ValidateLayout() error {
return nil return nil
} }
func (p *Project) isCachePath(path string) bool {
rel, err := filepath.Rel(p.Root, path)
if err != nil || strings.HasPrefix(rel, ".."+string(filepath.Separator)) || rel == ".." {
return false
}
parts := strings.Split(filepath.Clean(rel), string(filepath.Separator))
return len(parts) > 0 && parts[0] == ".cache"
}
func (p *Project) Scan() error { func (p *Project) Scan() error {
sourceFiles, sourceExts, err := scanDir(p.SourceDir(), func(path string) bool { sourceFiles, sourceExts, err := scanDir(p.SourceDir(), func(path string) bool {
ext := strings.ToLower(filepath.Ext(path)) ext := strings.ToLower(filepath.Ext(path))
@@ -189,8 +177,12 @@ func (p *Project) Scan() error {
return slices.Contains(AssetExtensions, ext) return slices.Contains(AssetExtensions, ext)
}) })
if err != nil { if err != nil {
if errors.Is(err, os.ErrNotExist) {
assetFiles = nil
} else {
return fmt.Errorf("scan assets tree: %w", err) return fmt.Errorf("scan assets tree: %w", err)
} }
}
var scripts []string var scripts []string
var sources []string var sources []string
+26 -6
View File
@@ -1,6 +1,7 @@
package project package project
import ( import (
"errors"
"os" "os"
"path/filepath" "path/filepath"
"slices" "slices"
@@ -82,7 +83,7 @@ func TestTopDataAssetsDirReturnsEmptyForNoConfig(t *testing.T) {
} }
} }
func TestValidateLayoutCreatesMissingCacheAssetsDir(t *testing.T) { func TestValidateLayoutAllowsMissingAssetsDir(t *testing.T) {
root := t.TempDir() root := t.TempDir()
mkdirAll(t, filepath.Join(root, "src")) mkdirAll(t, filepath.Join(root, "src"))
mkdirAll(t, filepath.Join(root, "build")) mkdirAll(t, filepath.Join(root, "build"))
@@ -91,17 +92,36 @@ func TestValidateLayoutCreatesMissingCacheAssetsDir(t *testing.T) {
Root: root, Root: root,
Config: Config{ Config: Config{
Module: ModuleConfig{Name: "Test", ResRef: "test"}, Module: ModuleConfig{Name: "Test", ResRef: "test"},
Paths: PathConfig{Source: "src", Assets: ".cache/module-assets", Build: "build"}, Paths: PathConfig{Source: "src", Assets: "assets", Build: "build"},
}, },
} }
if err := proj.ValidateLayout(); err != nil { if err := proj.ValidateLayout(); err != nil {
t.Fatalf("ValidateLayout returned error: %v", err) t.Fatalf("ValidateLayout returned error: %v", err)
} }
if info, err := os.Stat(filepath.Join(root, ".cache", "module-assets")); err != nil { if _, err := os.Stat(filepath.Join(root, "assets")); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("expected cache assets dir to be created: %v", err) t.Fatalf("expected missing assets dir to remain absent, got err=%v", err)
} else if !info.IsDir() { }
t.Fatalf("expected cache assets path to be a directory") }
func TestScanAllowsMissingAssetsDir(t *testing.T) {
root := t.TempDir()
mkdirAll(t, filepath.Join(root, "src"))
mkdirAll(t, filepath.Join(root, "build"))
proj := &Project{
Root: root,
Config: Config{
Module: ModuleConfig{Name: "Test", ResRef: "test"},
Paths: PathConfig{Source: "src", Assets: "assets", Build: "build"},
},
}
if err := proj.Scan(); err != nil {
t.Fatalf("Scan returned error: %v", err)
}
if len(proj.Inventory.AssetFiles) != 0 {
t.Fatalf("expected no asset files, got %#v", proj.Inventory.AssetFiles)
} }
} }