Skip to content

Commit b1e3dbf

Browse files
authored
feat: enhance file path handling in Process method (#212)
Updated the Process method to differentiate between specific file paths and wildcard patterns. Added checks for the existence of specific files and improved error handling for non-existent files. This enhancement allows for more robust file matching and validation in the processing workflow.
1 parent 44c4e51 commit b1e3dbf

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

pkg/backend/processor/base.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
"context"
2121
"fmt"
2222
"io"
23+
"os"
2324
"path/filepath"
2425
"sort"
26+
"strings"
2527
"sync"
2628

2729
internalpb "github.com/CloudNativeAI/modctl/internal/pb"
@@ -60,12 +62,33 @@ func (b *base) Process(ctx context.Context, builder build.Builder, workDir strin
6062

6163
var matchedPaths []string
6264
for _, pattern := range b.patterns {
63-
matches, err := filepath.Glob(filepath.Join(absWorkDir, pattern))
64-
if err != nil {
65-
return nil, err
65+
// Check if the pattern is a specific file path (no wildcards)
66+
if !strings.ContainsAny(pattern, "*?[]") {
67+
// For specific file paths, check if the file exists
68+
var fullPath string
69+
if filepath.IsAbs(pattern) {
70+
fullPath = pattern
71+
} else {
72+
fullPath = filepath.Join(absWorkDir, pattern)
73+
}
74+
75+
if _, err := os.Stat(fullPath); err != nil {
76+
if os.IsNotExist(err) {
77+
return nil, fmt.Errorf("file specified in Modelfile does not exist: %s", pattern)
78+
}
79+
return nil, fmt.Errorf("failed to check file: %s, error: %w", pattern, err)
80+
}
81+
82+
matchedPaths = append(matchedPaths, fullPath)
83+
} else {
84+
// For patterns with wildcards, use glob matching
85+
matches, err := filepath.Glob(filepath.Join(absWorkDir, pattern))
86+
if err != nil {
87+
return nil, err
88+
}
89+
90+
matchedPaths = append(matchedPaths, matches...)
6691
}
67-
68-
matchedPaths = append(matchedPaths, matches...)
6992
}
7093

7194
sort.Strings(matchedPaths)

0 commit comments

Comments
 (0)