parent
4ac80cfcec
commit
5c76824e14
@ -1,2 +1,2 @@ |
||||
src/*.pb.go |
||||
/mfer |
||||
mfer/*.pb.go |
||||
/mfer.cmd |
||||
|
@ -0,0 +1,51 @@ |
||||
package cli |
||||
|
||||
import ( |
||||
"git.eeqj.de/sneak/mfer/mfer" |
||||
"github.com/spf13/afero" |
||||
) |
||||
|
||||
type Job struct { |
||||
innerpb *mfer.MFFileInner |
||||
outerpb *mfer.MFFile |
||||
fileCount int64 |
||||
totalSize int64 |
||||
afs afero.Fs |
||||
} |
||||
|
||||
func (m *Job) scanForFiles() error { |
||||
|
||||
m.innerpb = &mfer.MFFileInner{} |
||||
m.innerpb.Version = mfer.MFFileInner_ONE |
||||
return nil |
||||
} |
||||
|
||||
/* |
||||
walkErr := filepath.Walk(m.sourcePath, func(itemPath string, info os.FileInfo, err error) error { |
||||
|
||||
// we do not include the manifest file in the manifest
|
||||
if itemPath == "index.mf" { |
||||
return nil |
||||
} |
||||
|
||||
fpi := mfer.MFFilePath{} |
||||
fpi.Path = itemPath |
||||
fpi.Size = info.Size() |
||||
m.innerpb.Files = append(m.innerpb.Files, &fpi) |
||||
m.fileCount++ |
||||
m.totalSize += fpi.Size |
||||
return nil |
||||
}) |
||||
|
||||
if walkErr != nil { |
||||
log.Fatal(walkErr) |
||||
return walkErr |
||||
} |
||||
|
||||
fmt.Printf("%#v\n", m.innerpb) |
||||
fmt.Printf("filecount = %#v\n", m.fileCount) |
||||
fmt.Printf("totalsize = %#v\n", m.totalSize) |
||||
return nil |
||||
} |
||||
|
||||
*/ |
@ -0,0 +1,46 @@ |
||||
package mfer |
||||
|
||||
import ( |
||||
"io" |
||||
"io/fs" |
||||
|
||||
"github.com/spf13/afero" |
||||
) |
||||
|
||||
type ManifestFile struct { |
||||
Path string |
||||
FileInfo fs.FileInfo |
||||
} |
||||
|
||||
type Manifest struct { |
||||
SourceFS afero.Fs |
||||
Files []*ManifestFile |
||||
} |
||||
|
||||
func NewFromPath(inputPath string) (*Manifest, error) { |
||||
afs := afero.NewBasePathFs(afero.NewOsFs(), inputPath) |
||||
return NewFromFilesystem(afs) |
||||
} |
||||
|
||||
func NewFromFilesystem(fs afero.Fs) (*Manifest, error) { |
||||
m := &Manifest{ |
||||
SourceFS: fs, |
||||
} |
||||
m.Scan() |
||||
return m, nil |
||||
} |
||||
|
||||
func (m *Manifest) Scan() { |
||||
afero.Walk(m.SourceFS, "", func(path string, info fs.FileInfo, err error) error { |
||||
nf := &ManifestFile{ |
||||
Path: path, |
||||
FileInfo: info, |
||||
} |
||||
m.Files = append(m.Files, nf) |
||||
return nil |
||||
}) |
||||
} |
||||
|
||||
func (m *Manifest) Write(output io.Writer) error { |
||||
return nil |
||||
} |
@ -0,0 +1,13 @@ |
||||
package mfer |
||||
|
||||
import "testing" |
||||
|
||||
// Add those variables as well
|
||||
var ( |
||||
existingFolder = "./testdata/a-folder-that-exists" |
||||
nonExistingFolder = "./testdata/a-folder-that-does-not-exists" |
||||
) |
||||
|
||||
func TestManifestGeneration(t *testing.T) { |
||||
|
||||
} |
@ -1,69 +0,0 @@ |
||||
package mfer |
||||
|
||||
import ( |
||||
"fmt" |
||||
"log" |
||||
"os" |
||||
"path/filepath" |
||||
|
||||
"github.com/spf13/afero" |
||||
) |
||||
|
||||
type MFGenerationJob struct { |
||||
sourcePath string |
||||
outputFile string |
||||
innerpb *MFFileInner |
||||
outerpb *MFFile |
||||
fileCount int64 |
||||
totalSize int64 |
||||
afs afero.Fs |
||||
} |
||||
|
||||
func NewMFGenerationJobFromFilesystem(sourcePath string) (*MFGenerationJob, error) { |
||||
afs := afero.NewOsFs() |
||||
exists, err := afero.DirExists(afs, sourcePath) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
if !exists { |
||||
return nil, fmt.Errorf("source directory does not exist") |
||||
} |
||||
|
||||
mgj := MFGenerationJob{} |
||||
mgj.afs = afs |
||||
mgj.sourcePath = sourcePath |
||||
|
||||
return &mgj, nil |
||||
} |
||||
|
||||
func (m *MFGenerationJob) scanForFiles() error { |
||||
|
||||
m.innerpb = &MFFileInner{} |
||||
m.innerpb.Version = MFFileInner_ONE |
||||
|
||||
walkErr := filepath.Walk(m.sourcePath, func(itemPath string, info os.FileInfo, err error) error { |
||||
|
||||
// we do not include the manifest file in the manifest
|
||||
if itemPath == "index.mf" { |
||||
return nil |
||||
} |
||||
|
||||
fpi := MFFilePath{} |
||||
fpi.Path = itemPath |
||||
fpi.Size = info.Size() |
||||
m.innerpb.Files = append(m.innerpb.Files, &fpi) |
||||
m.fileCount++ |
||||
m.totalSize += fpi.Size |
||||
return nil |
||||
}) |
||||
|
||||
if walkErr != nil { |
||||
log.Fatal(walkErr) |
||||
return walkErr |
||||
} |
||||
|
||||
fmt.Printf("%#v\n", m.innerpb) |
||||
fmt.Printf("filecount = %#v\n", m.fileCount) |
||||
fmt.Printf("totalsize = %#v\n", m.totalSize) |
||||
return nil |
||||
} |
Loading…
Reference in new issue