package mfer import ( "fmt" "io" "io/fs" "strings" "github.com/spf13/afero" ) type ManifestFile struct { Path string FileInfo fs.FileInfo } type Manifest struct { SourceFS afero.Fs Files []*ManifestFile ScanOptions *ManifestScanOptions TotalFileSize int64 } type ManifestScanOptions struct { IgnoreDotfiles bool FollowSymLinks bool } func NewFromPath(inputPath string, options *ManifestScanOptions) (*Manifest, error) { afs := afero.NewBasePathFs(afero.NewOsFs(), inputPath) return NewFromFilesystem(afs, options) } func NewFromFilesystem(fs afero.Fs, options *ManifestScanOptions) (*Manifest, error) { m := &Manifest{ SourceFS: fs, ScanOptions: options, } m.Scan() return m, nil } func (m *Manifest) Scan() { afero.Walk(m.SourceFS, "", func(path string, info fs.FileInfo, err error) error { if m.ScanOptions.IgnoreDotfiles && strings.HasPrefix(path, ".") { // FIXME make this check all path components BUG return nil } if info != nil && info.IsDir() { // manifests contain only files, directories are implied. return nil } fmt.Printf("path = %s\n", path) fileinfo, staterr := m.SourceFS.Stat(path) if staterr != nil { panic(staterr) } nf := &ManifestFile{ Path: path, FileInfo: fileinfo, } m.Files = append(m.Files, nf) m.TotalFileSize = m.TotalFileSize + info.Size() fmt.Printf("total file count now %i\n", len(m.Files)) fmt.Printf("total file size now %i\n", m.TotalFileSize) return nil }) } func (m *Manifest) Write(output io.Writer) error { return nil }