feat: 增加环境预检查与多根目录支持,调整构建操作布局
This commit is contained in:
1 parent
2cb70beb69
commit
7984785610
17 files changed
+852
-97
No files matched your search
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Repeated -workspace-root flags keep the allowed trees explicit, without exposing /home/tt.
|
||||
type workspaceRootFlags []string
|
||||
|
||||
func (roots *workspaceRootFlags) String() string { return strings.Join(*roots, ", ") }
|
||||
func (roots *workspaceRootFlags) Set(value string) error {
|
||||
path, e := filepath.Abs(value)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
*roots = append(*roots, filepath.Clean(path))
|
||||
return nil
|
||||
}
|
||||
func (s *Server) allowedWorkspaceRoots() []string {
|
||||
input := s.workspaceRoots
|
||||
if len(input) == 0 {
|
||||
root := s.workspaceRoot
|
||||
if root == "" {
|
||||
root = filepath.Join(s.root, "projects")
|
||||
}
|
||||
input = []string{root}
|
||||
}
|
||||
result := []string{}
|
||||
seen := map[string]bool{}
|
||||
for _, root := range input {
|
||||
abs, e := filepath.Abs(root)
|
||||
if e != nil {
|
||||
continue
|
||||
}
|
||||
key := abs
|
||||
if runtime.GOOS == "windows" {
|
||||
key = strings.ToLower(key)
|
||||
}
|
||||
if !seen[key] {
|
||||
seen[key] = true
|
||||
result = append(result, abs)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
func (s *Server) containingWorkspaceRoot(path string, allowRoot bool) (string, bool) {
|
||||
if !filepath.IsAbs(path) {
|
||||
return "", false
|
||||
}
|
||||
best := ""
|
||||
for _, root := range s.allowedWorkspaceRoots() {
|
||||
rel, e := filepath.Rel(root, path)
|
||||
if e != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
|
||||
continue
|
||||
}
|
||||
if rel == "." && !allowRoot {
|
||||
return "", false
|
||||
}
|
||||
if len(root) > len(best) {
|
||||
best = root
|
||||
}
|
||||
}
|
||||
return best, best != ""
|
||||
}
|
||||
Reference in new issue
Block a user