diff options
-rw-r--r-- | dna/drive.go | 2 | ||||
-rw-r--r-- | repo/export.go | 34 |
2 files changed, 22 insertions, 14 deletions
diff --git a/dna/drive.go b/dna/drive.go index 0fc5b03..fd9ac06 100644 --- a/dna/drive.go +++ b/dna/drive.go @@ -64,7 +64,7 @@ func New( os.MkdirAll(destination, 0755) for i := range pools { path := filepath.Join(destination, fmt.Sprintf("%02d", i)) - file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644) + file, err := os.OpenFile(path, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0644) if err != nil { logger.Panic(err) } diff --git a/repo/export.go b/repo/export.go index 7597ce4..2e23a93 100644 --- a/repo/export.go +++ b/repo/export.go @@ -32,31 +32,39 @@ func (r *Repo) Export(exporter export.Exporter) { var err error end := make(chan bool) input := exporter.ExportVersion(end) - if len(chunks[i]) > 0 { - compressed := r.chunkWriteWrapper(input.Chunks) - for _, c := range chunks[i] { - _, err := io.Copy(compressed, c.Reader()) - if err != nil { - logger.Error(err) - } - } - compressed.Close() - } - input.Chunks.Close() + go exportChunks(chunks[i], r.chunkWriteWrapper, input.Chunks) readDelta(r.versions[i], recipeName, utils.NopReadWrapper, func(rc io.ReadCloser) { _, err = io.Copy(input.Recipe, rc) if err != nil { logger.Error("load recipe ", err) } - input.Recipe.Close() + if err = input.Recipe.Close(); err != nil { + logger.Error("export recipe ", err) + } }) readDelta(r.versions[i], filesName, utils.NopReadWrapper, func(rc io.ReadCloser) { _, err = io.Copy(input.Files, rc) if err != nil { logger.Error("load files ", err) } - input.Files.Close() + if err = input.Files.Close(); err != nil { + logger.Error("export files ", err) + } }) <-end } } + +func exportChunks(chunks []IdentifiedChunk, wrapper utils.WriteWrapper, input io.WriteCloser) { + if len(chunks) > 0 { + compressed := wrapper(input) + for _, c := range chunks { + _, err := io.Copy(compressed, c.Reader()) + if err != nil { + logger.Error(err) + } + } + compressed.Close() + } + input.Close() +} |