aboutsummaryrefslogtreecommitdiff
path: root/repo.go
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-08-24 19:56:14 +0200
committern-peugnet <n.peugnet@free.fr>2021-08-24 19:56:14 +0200
commited80409f2a904e328d2fcef89296a7e53a15a664 (patch)
tree2b3bae49bfd0aa9d898f7e8f782e67b66b675b41 /repo.go
parentdf6d5f7e24a290718adf8f068649c3bc61f5eb4d (diff)
downloaddna-backup-ed80409f2a904e328d2fcef89296a7e53a15a664.tar.gz
dna-backup-ed80409f2a904e328d2fcef89296a7e53a15a664.zip
add extractNewChunks
Diffstat (limited to 'repo.go')
-rw-r--r--repo.go30
1 files changed, 25 insertions, 5 deletions
diff --git a/repo.go b/repo.go
index 3bb60b9..ef61111 100644
--- a/repo.go
+++ b/repo.go
@@ -57,7 +57,7 @@ func (r *Repo) Commit(source string) {
newVersion := len(versions)
newPath := path.Join(r.path, fmt.Sprintf(versionFmt, newVersion))
newChunkPath := path.Join(newPath, chunksName)
- newFilesPath := path.Join(newPath, filesName)
+ // newFilesPath := path.Join(newPath, filesName)
os.Mkdir(newPath, 0775)
os.Mkdir(newChunkPath, 0775)
newChunks := make(chan []byte, 16)
@@ -65,10 +65,11 @@ func (r *Repo) Commit(source string) {
files := listFiles(source)
go loadChunks(versions, oldChunks)
go readFiles(files, newChunks)
- // hashes := HashChunks(oldChunks)
- // MatchChunks(newChunks, hashes)
- storeChunks(newChunkPath, newChunks)
- storeFiles(newFilesPath, files)
+ hashes := hashChunks(oldChunks)
+ chunks := r.matchChunks(newChunks, hashes)
+ extractNewChunks(chunks)
+ // storeChunks(newChunkPath, newChunks)
+ // storeFiles(newFilesPath, files)
fmt.Println(files)
}
@@ -254,6 +255,25 @@ func (r *Repo) matchChunks(chunks <-chan []byte, hashes map[uint64]ChunkId) []Ch
return recipe
}
+func extractNewChunks(chunks []Chunk) (ret [][]Chunk) {
+ var i int
+ ret = append(ret, make([]Chunk, 0))
+ for _, c := range chunks {
+ if c.isStored() {
+ if len(ret[i]) != 0 {
+ i++
+ ret = append(ret, make([]Chunk, 0))
+ }
+ } else {
+ ret[i] = append(ret[i], c)
+ }
+ }
+ if len(ret[i]) == 0 {
+ ret = ret[:i]
+ }
+ return
+}
+
func writeFile(filePath string, object interface{}) error {
file, err := os.Create(filePath)
if err == nil {