Ariver
2026-06-29 9d4f977026bbb4516f8cc97f715c0dc28bf2a13f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package model
 
import (
    "fmt"
    "os"
    "path/filepath"
)
 
type ValidationResult struct {
    Valid    bool
    Files    map[string]string
    Missing  []string
    Problems []string
}
 
func ValidateModelDir(profile ModelProfile, dir string) ValidationResult {
    result := ValidationResult{
        Valid: true,
        Files: make(map[string]string),
    }
 
    info, err := os.Stat(dir)
    if err != nil {
        result.Valid = false
        result.Missing = append(result.Missing, dir)
        return result
    }
    if !info.IsDir() {
        result.Valid = false
        result.Problems = append(result.Problems, fmt.Sprintf("%s is not a directory", dir))
        return result
    }
 
    for _, rule := range profile.RequiredFiles {
        if !rule.Required {
            continue
        }
 
        if len(rule.AllOf) > 0 {
            for _, rel := range rule.AllOf {
                path := filepath.Join(dir, rel)
                if !validRequiredPath(path, rule.Directory) {
                    result.Valid = false
                    result.Missing = append(result.Missing, rel)
                    continue
                }
                if rule.Role != "" && result.Files[rule.Role] == "" {
                    result.Files[rule.Role] = path
                }
            }
        }
 
        if len(rule.AnyOf) > 0 {
            var selected string
            for _, rel := range rule.AnyOf {
                path := filepath.Join(dir, rel)
                if validRequiredPath(path, rule.Directory) {
                    selected = path
                    break
                }
            }
            if selected == "" {
                result.Valid = false
                result.Missing = append(result.Missing, fmt.Sprintf("%s:anyOf(%v)", rule.Role, rule.AnyOf))
            } else if rule.Role != "" {
                result.Files[rule.Role] = selected
            }
        }
    }
 
    return result
}
 
func validRequiredFile(path string) bool {
    return validRequiredPath(path, false)
}
 
func validRequiredPath(path string, directory bool) bool {
    info, err := os.Stat(path)
    if err != nil {
        return false
    }
    if directory {
        return info.IsDir()
    }
    if info.IsDir() {
        return false
    }
    return info.Size() > 0
}