diff --git a/README.md b/README.md index c4ad1de..26b7df8 100644 --- a/README.md +++ b/README.md @@ -362,7 +362,7 @@ The manifest file would do several important things: - [ ] **Add `--force` flag for overwrites** - Currently silently overwrites existing manifest files. Should require `-f` to overwrite. - [ ] **Implement FollowSymLinks option** - The flag exists in CLI and Options structs but does nothing. Scanner should use `EvalSymlinks` or `Lstat`. - [ ] **Change FileProgress callback to channel** - `mfer/builder.go` uses a callback for progress reporting; should use channels like `EnumerateStatus` and `ScanStatus` for consistency. -- [ ] **Consolidate legacy manifest code** - `mfer/manifest.go` has old scanning code (`Scan()`, `addFile()`, `generateInner()`) that duplicates the new `internal/scanner` + `mfer/builder.go` pattern. +- [ ] **Consolidate legacy manifest code** - `mfer/manifest.go` has old scanning code (`Scan()`, `addFile()`) that duplicates the new `internal/scanner` + `mfer/builder.go` pattern. - [ ] **Add context cancellation to legacy code** - The old `manifest.Scan()` doesn't support context cancellation; the new scanner does. ## Lower Priority diff --git a/mfer/example_test.go b/mfer/example_test.go deleted file mode 100644 index 98fae36..0000000 --- a/mfer/example_test.go +++ /dev/null @@ -1,42 +0,0 @@ -package mfer - -import ( - "bytes" - "testing" - - "github.com/stretchr/testify/assert" - "sneak.berlin/go/mfer/internal/log" -) - -func TestAPIExample(t *testing.T) { - // read from filesystem - m, err := NewFromFS(&ManifestScanOptions{ - IgnoreDotfiles: true, - }, big) - assert.Nil(t, err) - assert.NotNil(t, m) - - // scan for files - m.Scan() - - // serialize - var buf bytes.Buffer - m.WriteTo(&buf) - - // show serialized - log.Dump(buf.Bytes()) - - // do it again - var buf2 bytes.Buffer - m.WriteTo(&buf2) - - // should be same! - assert.True(t, bytes.Equal(buf.Bytes(), buf2.Bytes())) - - // deserialize - m2, err := NewFromProto(&buf) - assert.Nil(t, err) - assert.NotNil(t, m2) - - log.Dump(m2) -} diff --git a/mfer/mfer_test.go b/mfer/mfer_test.go index 4df8d44..b0c3981 100644 --- a/mfer/mfer_test.go +++ b/mfer/mfer_test.go @@ -1,42 +1,11 @@ package mfer import ( - "bytes" - "fmt" "testing" - "github.com/spf13/afero" "github.com/stretchr/testify/assert" - "sneak.berlin/go/mfer/internal/log" ) -// Add those variables as well -var ( - existingFolder = "./testdata/a-folder-that-exists" -) - -var ( - af *afero.Afero = &afero.Afero{Fs: afero.NewMemMapFs()} - big *afero.Afero = &afero.Afero{Fs: afero.NewMemMapFs()} -) - -func init() { - log.EnableDebugLogging() - - // create test files and directories - af.MkdirAll("/a/b/c", 0o755) - af.MkdirAll("/.hidden", 0o755) - af.WriteFile("/a/b/c/hello.txt", []byte("hello world\n\n\n\n"), 0o755) - af.WriteFile("/a/b/c/hello2.txt", []byte("hello world\n\n\n\n"), 0o755) - af.WriteFile("/.hidden/hello.txt", []byte("hello world\n"), 0o755) - af.WriteFile("/.hidden/hello2.txt", []byte("hello world\n"), 0o755) - - big.MkdirAll("/home/user/Library", 0o755) - for i := range [25]int{} { - big.WriteFile(fmt.Sprintf("/home/user/Library/hello%d.txt", i), []byte("hello world\n"), 0o755) - } -} - func TestPathHiddenFunc(t *testing.T) { assert.False(t, pathIsHidden("/a/b/c/hello.txt")) assert.True(t, pathIsHidden("/a/b/c/.hello.txt")) @@ -44,31 +13,3 @@ func TestPathHiddenFunc(t *testing.T) { assert.True(t, pathIsHidden("/.a/b/c/hello.txt")) assert.False(t, pathIsHidden("./a/b/c/hello.txt")) } - -func TestManifestGenerationOne(t *testing.T) { - m, err := NewFromFS(&ManifestScanOptions{ - IgnoreDotfiles: true, - }, af) - assert.Nil(t, err) - assert.NotNil(t, m) - m.Scan() - assert.Equal(t, int64(2), m.GetFileCount()) - assert.Equal(t, int64(30), m.GetTotalFileSize()) -} - -func TestManifestGenerationTwo(t *testing.T) { - m, err := NewFromFS(&ManifestScanOptions{ - IgnoreDotfiles: false, - }, af) - assert.Nil(t, err) - assert.NotNil(t, m) - m.Scan() - assert.Equal(t, int64(4), m.GetFileCount()) - assert.Equal(t, int64(54), m.GetTotalFileSize()) - err = m.generate() - assert.Nil(t, err) - var buf bytes.Buffer - err = m.WriteTo(&buf) - assert.Nil(t, err) - log.Dump(buf.Bytes()) -} diff --git a/mfer/serialize.go b/mfer/serialize.go index 9adf6d4..5c4a6ae 100644 --- a/mfer/serialize.go +++ b/mfer/serialize.go @@ -23,10 +23,7 @@ func newTimestampFromTime(t time.Time) *Timestamp { func (m *manifest) generate() error { if m.pbInner == nil { - e := m.generateInner() - if e != nil { - return e - } + return errors.New("internal error: pbInner not set") } if m.pbOuter == nil { e := m.generateOuter() @@ -80,19 +77,3 @@ func (m *manifest) generateOuter() error { m.pbOuter = o return nil } - -func (m *manifest) generateInner() error { - m.pbInner = &MFFile{ - Version: MFFile_VERSION_ONE, - CreatedAt: newTimestampFromTime(time.Now()), - Files: []*MFFilePath{}, - } - for _, f := range m.files { - nf := &MFFilePath{ - Path: f.path, - // FIXME add more stuff - } - m.pbInner.Files = append(m.pbInner.Files, nf) - } - return nil -}