Remove generateInner, now handled by Builder
- Remove generateInner() from serialize.go - Update generate() to error if pbInner not set - Remove legacy tests that depended on old code path - Update TODO item to reflect removal
This commit is contained in:
parent
5d7c729efb
commit
fded1a0393
@ -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.
|
- [ ] **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`.
|
- [ ] **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.
|
- [ ] **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.
|
- [ ] **Add context cancellation to legacy code** - The old `manifest.Scan()` doesn't support context cancellation; the new scanner does.
|
||||||
|
|
||||||
## Lower Priority
|
## Lower Priority
|
||||||
|
|||||||
@ -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)
|
|
||||||
}
|
|
||||||
@ -1,42 +1,11 @@
|
|||||||
package mfer
|
package mfer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/afero"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestPathHiddenFunc(t *testing.T) {
|
||||||
assert.False(t, pathIsHidden("/a/b/c/hello.txt"))
|
assert.False(t, pathIsHidden("/a/b/c/hello.txt"))
|
||||||
assert.True(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.True(t, pathIsHidden("/.a/b/c/hello.txt"))
|
||||||
assert.False(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())
|
|
||||||
}
|
|
||||||
|
|||||||
@ -23,10 +23,7 @@ func newTimestampFromTime(t time.Time) *Timestamp {
|
|||||||
|
|
||||||
func (m *manifest) generate() error {
|
func (m *manifest) generate() error {
|
||||||
if m.pbInner == nil {
|
if m.pbInner == nil {
|
||||||
e := m.generateInner()
|
return errors.New("internal error: pbInner not set")
|
||||||
if e != nil {
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if m.pbOuter == nil {
|
if m.pbOuter == nil {
|
||||||
e := m.generateOuter()
|
e := m.generateOuter()
|
||||||
@ -80,19 +77,3 @@ func (m *manifest) generateOuter() error {
|
|||||||
m.pbOuter = o
|
m.pbOuter = o
|
||||||
return nil
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user