Normalize paths

This commit is contained in:
nemunaire 2022-10-04 19:04:57 +02:00
commit 8f64a349ec
2 changed files with 44 additions and 1 deletions

View file

@ -65,6 +65,11 @@ func LoadAction(path string) (string, string, error) {
}
func LoadActions(cfg *config.Config) (actions []*Action, err error) {
actionsDir, err := filepath.Abs(cfg.ActionsDir)
if err != nil {
return nil, err
}
err = filepath.Walk(cfg.ActionsDir, func(path string, d fs.FileInfo, err error) error {
if d.Mode().IsRegular() {
hash := sha512.Sum512([]byte(path))
@ -81,11 +86,15 @@ func LoadActions(cfg *config.Config) (actions []*Action, err error) {
return nil
}
if apath, err := filepath.Abs(path); err == nil {
path = apath
}
actions = append(actions, &Action{
Id: hash[:],
Name: name,
Description: description,
Path: path,
Path: strings.TrimPrefix(path, actionsDir+"/"),
Enabled: d.Mode().Perm()&0111 != 0,
})
}