Files
narratio/internal/app/clean.go

44 lines
1.1 KiB
Go
Raw Normal View History

2026-05-21 22:48:18 -05:00
package app
import (
"fmt"
"os"
"path/filepath"
"strings"
)
func cleanableRootChildren(root, policy string) (string, []string, error) {
rootAbs, exists, err := validateCleanRoot(root, policy)
2026-05-21 22:48:18 -05:00
if err != nil {
return "", nil, err
2026-05-21 22:48:18 -05:00
}
if !exists {
return rootAbs, nil, nil
2026-05-21 22:48:18 -05:00
}
entries, err := os.ReadDir(rootAbs)
if err != nil {
return "", nil, fmt.Errorf("cleanup policy %s: read root %q: %w", policy, rootAbs, err)
}
out := make([]string, 0, len(entries))
for _, entry := range entries {
path := filepath.Join(rootAbs, entry.Name())
info, err := os.Lstat(path)
if err != nil {
return "", nil, fmt.Errorf("cleanup policy %s: stat child %q: %w", policy, path, err)
}
if info.Mode()&os.ModeSymlink != 0 {
return "", nil, fmt.Errorf("cleanup policy %s: refusing to delete symlink path %q", policy, path)
}
out = append(out, path)
}
return rootAbs, out, nil
}
func validateScopedFile(root, target, policy string) (scopedDir, error) {
return validateScopedTarget(root, target, policy, false)
2026-05-21 22:48:18 -05:00
}
func cleanIsFlac(path string) bool {
return strings.EqualFold(filepath.Ext(path), ".flac")
}