diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-10-18 16:00:08 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-10-18 16:00:08 +0200 |
commit | 04563efa9c0dc1f6a36094dfd884ae432cf46b29 (patch) | |
tree | be5a78647bec2a6d5812fb8b61b4ac4fcd3744b7 | |
parent | 5539220a8839519becd45b63be65ed86fa9286a4 (diff) | |
download | dna-backup-04563efa9c0dc1f6a36094dfd884ae432cf46b29.tar.gz dna-backup-04563efa9c0dc1f6a36094dfd884ae432cf46b29.zip |
add intermediate export package no to make repo dependant on dna
-rw-r--r-- | dna/drive.go | 36 | ||||
-rw-r--r-- | export/exporter.go | 24 | ||||
-rw-r--r-- | main.go | 5 | ||||
-rw-r--r-- | repo/export.go (renamed from repo/export_dir.go) | 8 |
4 files changed, 45 insertions, 28 deletions
diff --git a/dna/drive.go b/dna/drive.go index 013c4b4..0f62d5e 100644 --- a/dna/drive.go +++ b/dna/drive.go @@ -25,6 +25,7 @@ import ( "os" "path/filepath" + "github.com/n-peugnet/dna-backup/export" "github.com/n-peugnet/dna-backup/logger" "github.com/n-peugnet/dna-backup/utils" ) @@ -56,23 +57,6 @@ type Header struct { Files uint64 } -type dnaVersion struct { - Input dnaInput - Output dnaOutput -} - -type dnaInput struct { - Chunks io.WriteCloser - Recipe io.WriteCloser - Files io.WriteCloser -} - -type dnaOutput struct { - Chunks io.ReadCloser - Recipe io.ReadCloser - Files io.ReadCloser -} - func New( destination string, poolCount int, @@ -105,20 +89,28 @@ func New( } } -func (d *DnaDrive) VersionInput() (dnaInput, <-chan bool) { +func (d *DnaDrive) ExportVersion() (export.Input, <-chan bool) { rChunks, wChunks := io.Pipe() rRecipe, wRecipe := io.Pipe() rFiles, wFiles := io.Pipe() - version := dnaVersion{ - Input: dnaInput{wChunks, wRecipe, wFiles}, - Output: dnaOutput{rChunks, rRecipe, rFiles}, + version := export.Version{ + Input: export.Input{ + Chunks: wChunks, + Recipe: wRecipe, + Files: wFiles, + }, + Output: export.Output{ + Chunks: rChunks, + Recipe: rRecipe, + Files: rFiles, + }, } end := make(chan bool) go d.writeVersion(version.Output, end) return version.Input, end } -func (d *DnaDrive) writeVersion(output dnaOutput, end chan<- bool) { +func (d *DnaDrive) writeVersion(output export.Output, end chan<- bool) { var err error var recipe, files, version bytes.Buffer n := d.write(output.Chunks, d.pools[1:], Forward) diff --git a/export/exporter.go b/export/exporter.go new file mode 100644 index 0000000..208fbd7 --- /dev/null +++ b/export/exporter.go @@ -0,0 +1,24 @@ +package export + +import "io" + +type Version struct { + Input + Output +} + +type Input struct { + Chunks io.WriteCloser + Recipe io.WriteCloser + Files io.WriteCloser +} + +type Output struct { + Chunks io.ReadCloser + Recipe io.ReadCloser + Files io.ReadCloser +} + +type Exporter interface { + ExportVersion() (input Input, end <-chan bool) +} @@ -22,8 +22,10 @@ import ( "fmt" "os" + "github.com/n-peugnet/dna-backup/dna" "github.com/n-peugnet/dna-backup/logger" "github.com/n-peugnet/dna-backup/repo" + "github.com/n-peugnet/dna-backup/utils" ) type command struct { @@ -137,7 +139,8 @@ func exportMain(args []string) error { r := repo.NewRepo(source, chunkSize) switch format { case "dir": - r.ExportDir(dest, trackSize) + exporter := dna.New(dest, 96, trackSize, 10000, utils.ZlibWriter, utils.ZlibReader) + r.Export(exporter) case "csv": fmt.Println("csv") default: diff --git a/repo/export_dir.go b/repo/export.go index bffa7f0..dd12077 100644 --- a/repo/export_dir.go +++ b/repo/export.go @@ -20,18 +20,16 @@ package repo import ( "io" - "github.com/n-peugnet/dna-backup/dna" + "github.com/n-peugnet/dna-backup/export" "github.com/n-peugnet/dna-backup/logger" - "github.com/n-peugnet/dna-backup/utils" ) -func (r *Repo) ExportDir(dest string, trackSize int) { +func (r *Repo) Export(exporter export.Exporter) { r.Init() - exporter := dna.New(dest, 96, trackSize, 10000, utils.ZlibWriter, utils.ZlibReader) chunks := r.loadChunks(r.versions) for i := range r.versions { var err error - input, end := exporter.VersionInput() + input, end := exporter.ExportVersion() if len(chunks[i]) > 0 { for _, c := range chunks[i] { _, err := io.Copy(input.Chunks, c.Reader()) |