walkRoot performs a full filesystem walk of absRoot and returns a populated Index containing all discovered files and directories.
(absRoot string)
| 58 | // walkRoot performs a full filesystem walk of absRoot and returns |
| 59 | // a populated Index containing all discovered files and directories. |
| 60 | func walkRoot(absRoot string) (*Index, error) { |
| 61 | idx := NewIndex() |
| 62 | err := filepath.Walk(absRoot, func(path string, info os.FileInfo, walkErr error) error { |
| 63 | if walkErr != nil { |
| 64 | return nil //nolint:nilerr |
| 65 | } |
| 66 | base := filepath.Base(path) |
| 67 | if _, skip := skipDirs[base]; skip && info.IsDir() { |
| 68 | return filepath.SkipDir |
| 69 | } |
| 70 | if path == absRoot { |
| 71 | return nil |
| 72 | } |
| 73 | relPath, relErr := filepath.Rel(absRoot, path) |
| 74 | if relErr != nil { |
| 75 | return nil //nolint:nilerr |
| 76 | } |
| 77 | relPath = filepath.ToSlash(relPath) |
| 78 | var flags uint16 |
| 79 | if info.IsDir() { |
| 80 | flags = uint16(FlagDir) |
| 81 | } else if info.Mode()&os.ModeSymlink != 0 { |
| 82 | flags = uint16(FlagSymlink) |
| 83 | } |
| 84 | idx.Add(relPath, flags) |
| 85 | return nil |
| 86 | }) |
| 87 | return idx, err |
| 88 | } |
| 89 | |
| 90 | // NewEngine creates a new Engine. |
| 91 | func NewEngine(logger slog.Logger) *Engine { |