Compare commits

...

3 Commits

Author SHA1 Message Date
ed40673e85 Validate input path exists in addInputPath 2025-12-17 17:04:46 -08:00
2549695ab0 Update README TODO with completed items 2025-12-17 17:03:05 -08:00
e480c3f677 Fix redundant stat call in addFile
Use the FileInfo already provided by Walk instead of calling Stat again.
Only stat if fi is nil (defensive, shouldn't happen in normal Walk usage).
Also fixes potential nil pointer dereference if fi was nil.
2025-12-17 17:02:29 -08:00
2 changed files with 19 additions and 12 deletions

View File

@ -363,10 +363,10 @@ The manifest file would do several important things:
## Lower Priority
- [ ] **Add unit tests for `internal/checker`** - Currently has no test files; only tested indirectly via CLI tests.
- [ ] **Add unit tests for `internal/scanner`** - Currently has no test files.
- [ ] **Clean up FIXMEs in manifest.go** - Validate input paths exist, validate filesystem, avoid redundant stat calls.
- [ ] **Validate input paths before scanning** - Should fail fast with a clear error if paths don't exist.
- [x] **Add unit tests for `internal/checker`** - 88.5% coverage.
- [x] **Add unit tests for `internal/scanner`** - 80.1% coverage.
- [ ] **Clean up FIXMEs in manifest.go** - Validate input paths exist, validate filesystem.
- [x] **Validate input paths before scanning** - Fails fast with clear error if paths don't exist.
# Open Questions

View File

@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io/fs"
"os"
"path"
"path/filepath"
"strings"
@ -64,7 +65,10 @@ func (m *manifest) addInputPath(inputPath string) error {
if err != nil {
return err
}
// FIXME check to make sure inputPath/abs exists maybe
// Validate path exists
if _, err := os.Stat(abs); err != nil {
return fmt.Errorf("path does not exist: %s", inputPath)
}
afs := afero.NewReadOnlyFs(afero.NewBasePathFs(afero.NewOsFs(), abs))
return m.addInputFS(afs)
}
@ -156,22 +160,25 @@ func (m *manifest) addFile(p string, fi fs.FileInfo, sfsIndex int) error {
if !m.scanOptions.IncludeDotfiles && pathIsHidden(p) {
return nil
}
if fi != nil && fi.IsDir() {
if fi == nil {
// fi should come from Walk; if nil, stat to get info
var err error
fi, err = m.sourceFS[sfsIndex].Stat(p)
if err != nil {
return err
}
}
if fi.IsDir() {
// manifests contain only files, directories are implied.
return nil
}
// FIXME test if 'fi' is already result of stat
fileinfo, staterr := m.sourceFS[sfsIndex].Stat(p)
if staterr != nil {
return staterr
}
cleanPath := p
if cleanPath[0:1] == "/" {
cleanPath = cleanPath[1:]
}
nf := &manifestFile{
path: cleanPath,
info: fileinfo,
info: fi,
}
m.files = append(m.files, nf)
m.totalFileSize = m.totalFileSize + fi.Size()