Initial DDC release
This commit is contained in:
commit
434f6441da
57 files changed
+4606
No files matched your search
Executable
+56
@@ -0,0 +1,56 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func parseLibraryRoots(raw string) ([]string, error) {
|
||||
var roots []string
|
||||
seenRoots := make(map[string]bool)
|
||||
|
||||
for _, entry := range strings.Split(raw, ";") {
|
||||
entry = strings.TrimSpace(entry)
|
||||
if entry == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
root, err := resolveRoot(entry)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if seenRoots[root] {
|
||||
continue
|
||||
}
|
||||
seenRoots[root] = true
|
||||
roots = append(roots, root)
|
||||
}
|
||||
|
||||
if len(roots) == 0 {
|
||||
return nil, errors.New("LIBRARY_ROOTS must list at least one folder")
|
||||
}
|
||||
return roots, nil
|
||||
}
|
||||
|
||||
func resolveRoot(entry string) (string, error) {
|
||||
cleaned := filepath.Clean(entry)
|
||||
if !filepath.IsAbs(cleaned) || cleaned == "/" {
|
||||
return "", fmt.Errorf("LIBRARY_ROOTS: invalid path %q", entry)
|
||||
}
|
||||
|
||||
resolved, err := filepath.EvalSymlinks(cleaned)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("LIBRARY_ROOTS: %w", err)
|
||||
}
|
||||
info, err := os.Stat(resolved)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("LIBRARY_ROOTS: %w", err)
|
||||
}
|
||||
if !info.IsDir() {
|
||||
return "", fmt.Errorf("LIBRARY_ROOTS: %q is not a directory", entry)
|
||||
}
|
||||
return resolved, nil
|
||||
}
|
||||
Reference in new issue
Block a user