diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-10-18 15:51:55 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-10-18 15:51:55 +0200 |
commit | 5539220a8839519becd45b63be65ed86fa9286a4 (patch) | |
tree | 426b532b525de92604be9602ec88edb47a2ad024 /repo | |
parent | 89fb0a85f78a415477e450b0091d8c2b994b687d (diff) | |
download | dna-backup-5539220a8839519becd45b63be65ed86fa9286a4.tar.gz dna-backup-5539220a8839519becd45b63be65ed86fa9286a4.zip |
do the real export in a dir containing multiple pool files
Diffstat (limited to 'repo')
-rw-r--r-- | repo/export_dir.go | 62 |
1 files changed, 17 insertions, 45 deletions
diff --git a/repo/export_dir.go b/repo/export_dir.go index 8c63fdb..bffa7f0 100644 --- a/repo/export_dir.go +++ b/repo/export_dir.go @@ -18,9 +18,6 @@ package repo import ( - "bytes" - "compress/zlib" - "encoding/binary" "io" "github.com/n-peugnet/dna-backup/dna" @@ -28,61 +25,36 @@ import ( "github.com/n-peugnet/dna-backup/utils" ) -type Version struct { - Chunks uint64 - Recipe uint64 - Files uint64 -} - func (r *Repo) ExportDir(dest string, trackSize int) { r.Init() - versions := make([]Version, len(r.versions)) + exporter := dna.New(dest, 96, trackSize, 10000, utils.ZlibWriter, utils.ZlibReader) chunks := r.loadChunks(r.versions) - for i := range versions { - var count int64 - var content bytes.Buffer // replace with a reader capable of switching files - var recipe, fileList []byte + for i := range r.versions { var err error - tracker := dna.NewWriter(&content, trackSize) - counter := utils.NewWriteCounter(tracker) - compressor := zlib.NewWriter(counter) - for _, c := range chunks[i] { - n, err := io.Copy(compressor, c.Reader()) - if err != nil { - logger.Error(err) + input, end := exporter.VersionInput() + if len(chunks[i]) > 0 { + for _, c := range chunks[i] { + _, err := io.Copy(input.Chunks, c.Reader()) + if err != nil { + logger.Error(err) + } } - count += n + input.Chunks.Close() } - compressor.Close() - tracker.Close() - readDelta(r.versions[i], recipeName, utils.NopReadWrapper, func(rc io.ReadCloser) { - recipe, err = io.ReadAll(rc) + readDelta(r.versions[i], recipeName, r.chunkReadWrapper, func(rc io.ReadCloser) { + _, err = io.Copy(input.Recipe, rc) if err != nil { logger.Error("load recipe ", err) } + input.Recipe.Close() }) - readDelta(r.versions[i], filesName, utils.NopReadWrapper, func(rc io.ReadCloser) { - fileList, err = io.ReadAll(rc) + readDelta(r.versions[i], filesName, r.chunkReadWrapper, func(rc io.ReadCloser) { + _, err = io.Copy(input.Files, rc) if err != nil { logger.Error("load files ", err) } + input.Files.Close() }) - versions[i] = Version{ - uint64(counter.Count()), - uint64(len(recipe)), - uint64(len(fileList)), - } - header := versions[i].createHeader() - logger.Info(header) - } -} - -func (v Version) createHeader() []byte { - buf := make([]byte, binary.MaxVarintLen64*3) - i := 0 - for _, x := range []uint64{v.Chunks, v.Recipe, v.Files} { - n := binary.PutUvarint(buf[i:], x) - i += n + <-end } - return buf[:i] } |