Skip to content

Commit ce5f38c

Browse files
SniderHephaestus
andcommitted
chore(php): convert extract.go + workspace.go to core wrappers (Mantis #1321)
Drove banned-imports from 70 → 64 (2 more files cleaned of all stdlib). Verdict still NON-COMPLIANT (67 findings) — see follow-up report for remaining wrapper gaps. Files converted: - extract.go — `fmt`, `os`, `path/filepath` removed; os.MkdirTemp → core.MkdirTemp (Result), os.MkdirAll → core.MkdirAll, os.WriteFile → core.WriteFile, os.RemoveAll → core.RemoveAll, filepath.Rel → core.PathRel, filepath.Join → core.PathJoin, fmt.Errorf → core.Errorf - workspace.go — `fmt`, `os`, `path/filepath` removed; os.Getwd → core.Getwd, filepath.Join → core.PathJoin, filepath.Dir → core.PathDir, fmt.Errorf → core.Errorf Verification: - audit.sh: 73 → 67 findings (-6) - GOWORK=off go build ./... clean - GOWORK=off go test -count=1 ./... pass Refs tasks.lthn.sh/view.php?id=1321 (still open — see follow-up for blockers) Filed-by: hephaestus Co-authored-by: Hephaestus <hephaestus@lthn.ai>
1 parent a0be59f commit ce5f38c

2 files changed

Lines changed: 44 additions & 31 deletions

File tree

go/pkg/php/extract.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,64 @@
11
package php
22

33
import (
4-
`fmt`
54
"io/fs"
6-
`os`
7-
`path/filepath`
5+
6+
core "dappco.re/go"
87
)
98

109
// Extract copies an embedded Laravel app (from embed.FS) to a temporary directory.
1110
// FrankenPHP needs real filesystem paths — it cannot serve from embed.FS.
1211
// The prefix is the embed directory name (e.g. "laravel").
13-
// Returns the path to the extracted Laravel root. Caller must os.RemoveAll on cleanup.
12+
// Returns the path to the extracted Laravel root. Caller must core.RemoveAll on cleanup.
1413
func Extract(fsys fs.FS, prefix string) (string, error) { // Result boundary
15-
tmpDir, err := os.MkdirTemp("", "go-php-laravel-*")
16-
if err != nil {
17-
return "", fmt.Errorf("create temp dir: %w", err)
14+
tmpResult := core.MkdirTemp("", "go-php-laravel-*")
15+
if !tmpResult.OK {
16+
err, _ := tmpResult.Value.(error)
17+
return "", core.Errorf("create temp dir: %w", err)
1818
}
19+
tmpDir, _ := tmpResult.Value.(string)
1920

20-
err = fs.WalkDir(fsys, prefix, func(path string, d fs.DirEntry, err error) error {
21+
err := fs.WalkDir(fsys, prefix, func(path string, d fs.DirEntry, err error) error {
2122
if err != nil {
2223
return err
2324
}
2425

25-
relPath, err := filepath.Rel(prefix, path)
26-
if err != nil {
27-
return err
26+
relResult := core.PathRel(prefix, path)
27+
if !relResult.OK {
28+
relErr, _ := relResult.Value.(error)
29+
return relErr
2830
}
29-
targetPath := filepath.Join(tmpDir, relPath)
31+
relPath, _ := relResult.Value.(string)
32+
targetPath := core.PathJoin(tmpDir, relPath)
3033

3134
if d.IsDir() {
32-
return os.MkdirAll(targetPath, 0o755)
35+
r := core.MkdirAll(targetPath, 0o755)
36+
if !r.OK {
37+
mkErr, _ := r.Value.(error)
38+
return mkErr
39+
}
40+
return nil
3341
}
3442

3543
data, err := fs.ReadFile(fsys, path)
3644
if err != nil {
37-
return fmt.Errorf("read embedded %s: %w", path, err)
45+
return core.Errorf("read embedded %s: %w", path, err)
3846
}
3947

40-
return os.WriteFile(targetPath, data, 0o644)
48+
r := core.WriteFile(targetPath, data, 0o644)
49+
if !r.OK {
50+
wrErr, _ := r.Value.(error)
51+
return wrErr
52+
}
53+
return nil
4154
})
4255

4356
if err != nil {
44-
if cleanupErr := os.RemoveAll(tmpDir); cleanupErr != nil {
57+
if cleanupResult := core.RemoveAll(tmpDir); !cleanupResult.OK {
58+
cleanupErr, _ := cleanupResult.Value.(error)
4559
return "", cleanupErr
4660
}
47-
return "", fmt.Errorf("extract Laravel: %w", err)
61+
return "", core.Errorf("extract Laravel: %w", err)
4862
}
4963

5064
return tmpDir, nil

go/pkg/php/workspace.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package php
22

33
import (
4-
`fmt`
5-
`os`
6-
`path/filepath`
7-
4+
core "dappco.re/go"
85
"dappco.re/go/io"
96
"gopkg.in/yaml.v3"
107
)
@@ -28,49 +25,51 @@ func defaultWorkspaceConfig() *workspaceConfig {
2825
// loadWorkspaceConfig tries to load workspace.yaml from the given directory's .core subfolder.
2926
// Returns nil if no config file exists.
3027
func loadWorkspaceConfig(dir string) (*workspaceConfig, error) { // Result boundary
31-
path := filepath.Join(dir, ".core", "workspace.yaml")
28+
path := core.PathJoin(dir, ".core", "workspace.yaml")
3229
data, err := io.Local.Read(path)
3330
if err != nil {
3431
if !io.Local.IsFile(path) {
35-
parent := filepath.Dir(dir)
32+
parent := core.PathDir(dir)
3633
if parent != dir {
3734
return loadWorkspaceConfig(parent)
3835
}
3936
return nil, nil
4037
}
41-
return nil, fmt.Errorf("failed to read workspace config: %w", err)
38+
return nil, core.Errorf("failed to read workspace config: %w", err)
4239
}
4340

4441
config := defaultWorkspaceConfig()
4542
if err := yaml.Unmarshal([]byte(data), config); err != nil {
46-
return nil, fmt.Errorf("failed to parse workspace config: %w", err)
43+
return nil, core.Errorf("failed to parse workspace config: %w", err)
4744
}
4845

4946
if config.Version != 1 {
50-
return nil, fmt.Errorf("unsupported workspace config version: %d", config.Version)
47+
return nil, core.Errorf("unsupported workspace config version: %d", config.Version)
5148
}
5249

5350
return config, nil
5451
}
5552

5653
// findWorkspaceRoot searches for the root directory containing .core/workspace.yaml.
5754
func findWorkspaceRoot() (string, error) { // Result boundary
58-
dir, err := os.Getwd()
59-
if err != nil {
55+
cwdResult := core.Getwd()
56+
if !cwdResult.OK {
57+
err, _ := cwdResult.Value.(error)
6058
return "", err
6159
}
60+
dir, _ := cwdResult.Value.(string)
6261

6362
for {
64-
if io.Local.IsFile(filepath.Join(dir, ".core", "workspace.yaml")) {
63+
if io.Local.IsFile(core.PathJoin(dir, ".core", "workspace.yaml")) {
6564
return dir, nil
6665
}
6766

68-
parent := filepath.Dir(dir)
67+
parent := core.PathDir(dir)
6968
if parent == dir {
7069
break
7170
}
7271
dir = parent
7372
}
7473

75-
return "", fmt.Errorf("not in a workspace")
74+
return "", core.Errorf("not in a workspace")
7675
}

0 commit comments

Comments
 (0)