latest
This commit is contained in:
@@ -4,10 +4,10 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
@@ -28,6 +28,10 @@ type Manifest struct {
|
||||
TotalFileSize int64
|
||||
}
|
||||
|
||||
func (m *Manifest) String() string {
|
||||
return fmt.Sprintf("<Manifest count=%d totalSize=%d>", len(m.Files), m.TotalFileSize)
|
||||
}
|
||||
|
||||
type ManifestScanOptions struct {
|
||||
IgnoreDotfiles bool
|
||||
FollowSymLinks bool
|
||||
@@ -39,13 +43,11 @@ func NewFromPath(inputPath string, options *ManifestScanOptions) (*Manifest, err
|
||||
return nil, err
|
||||
}
|
||||
afs := afero.NewBasePathFs(afero.NewOsFs(), abs)
|
||||
spew.Dump(afs)
|
||||
m, err := NewFromFS(afs, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.SourceFSRoot = abs
|
||||
spew.Dump(m)
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -54,13 +56,16 @@ func NewFromFS(fs afero.Fs, options *ManifestScanOptions) (*Manifest, error) {
|
||||
SourceFS: fs,
|
||||
ScanOptions: options,
|
||||
}
|
||||
m.Scan()
|
||||
err := m.Scan()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m *Manifest) Scan() {
|
||||
afero.Walk(m.SourceFS, "./", func(path string, info fs.FileInfo, err error) error {
|
||||
|
||||
func (m *Manifest) Scan() error {
|
||||
// FIXME scan and whatever function does the hashing should take ctx
|
||||
oe := 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
|
||||
@@ -71,10 +76,6 @@ func (m *Manifest) Scan() {
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("path = %s\n", path)
|
||||
spew.Dump(path)
|
||||
spew.Dump(info)
|
||||
|
||||
fileinfo, staterr := m.SourceFS.Stat(path)
|
||||
if staterr != nil {
|
||||
panic(staterr)
|
||||
@@ -86,12 +87,28 @@ func (m *Manifest) Scan() {
|
||||
}
|
||||
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
|
||||
})
|
||||
if oe != nil {
|
||||
return oe
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manifest) WriteToFile(path string) error {
|
||||
// FIXME refuse to overwrite without -f if file exists
|
||||
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return m.Write(f)
|
||||
}
|
||||
|
||||
func (m *Manifest) Write(output io.Writer) error {
|
||||
return nil
|
||||
// FIXME implement
|
||||
panic("nope")
|
||||
return nil // nolint:all
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user