diff options
-rw-r--r-- | const.go | 12 | ||||
-rw-r--r-- | repo.go | 52 | ||||
-rw-r--r-- | repo_test.go | 18 | ||||
-rw-r--r-- | testdata/repo_8k/00000/fingerprints | bin | 0 -> 208 bytes | |||
-rw-r--r-- | testdata/repo_8k/00000/sketches | bin | 0 -> 538 bytes | |||
-rw-r--r-- | testdata/repo_8k_zlib/00000/fingerprints | bin | 0 -> 208 bytes | |||
-rw-r--r-- | testdata/repo_8k_zlib/00000/sketches | bin | 0 -> 538 bytes |
7 files changed, 68 insertions, 14 deletions
@@ -1,9 +1,11 @@ package main const ( - chunksName = "chunks" - chunkIdFmt = "%015d" - versionFmt = "%05d" - filesName = "files" - recipeName = "recipe" + chunksName = "chunks" + chunkIdFmt = "%015d" + versionFmt = "%05d" + filesName = "files" + fingerprintsName = "fingerprints" + recipeName = "recipe" + sketchesName = "sketches" ) @@ -12,13 +12,17 @@ repo/ │ │ ├── 000000000000002 │ │ ├── 000000000000003 │ ├── files -│ └── recipe +│ ├── fingerprints +│ ├── recipe +│ └── sketches └── 00001/ ├── chunks/ │ ├── 000000000000000 │ ├── 000000000000001 ├── files - └── recipe +│ ├── fingerprints +│ ├── recipe +│ └── sketches ``` */ @@ -110,7 +114,9 @@ func (r *Repo) Commit(source string) { newPath := filepath.Join(r.path, fmt.Sprintf(versionFmt, newVersion)) newChunkPath := filepath.Join(newPath, chunksName) newFilesPath := filepath.Join(newPath, filesName) + newFingerprintsPath := filepath.Join(newPath, fingerprintsName) newRecipePath := filepath.Join(newPath, recipeName) + newSketchesPath := filepath.Join(newPath, sketchesName) os.Mkdir(newPath, 0775) // TODO: handle errors os.Mkdir(newChunkPath, 0775) // TODO: handle errors reader, writer := io.Pipe() @@ -120,8 +126,10 @@ func (r *Repo) Commit(source string) { go concatFiles(files, writer) r.hashChunks(oldChunks) recipe := r.matchStream(reader, newVersion) - storeRecipe(newRecipePath, recipe) storeFileList(newFilesPath, unprefixFiles(files, source)) + storeFingerprints(newFingerprintsPath, r.fingerprints) + storeRecipe(newRecipePath, recipe) + storeSketches(newSketchesPath, r.sketches) logger.Info(files) } @@ -211,11 +219,11 @@ func concatFiles(files []File, stream io.WriteCloser) { stream.Close() } -func storeFileList(dest string, files []File) { +func storeBasicStruct(dest string, obj interface{}) { file, err := os.Create(dest) if err == nil { encoder := gob.NewEncoder(file) - err = encoder.Encode(files) + err = encoder.Encode(obj) } if err != nil { logger.Panic(err) @@ -225,12 +233,11 @@ func storeFileList(dest string, files []File) { } } -func loadFileList(path string) []File { - var files []File +func loadBasicStruct(path string, obj interface{}) { file, err := os.Open(path) if err == nil { decoder := gob.NewDecoder(file) - err = decoder.Decode(&files) + err = decoder.Decode(obj) } if err != nil { logger.Panic(err) @@ -238,6 +245,15 @@ func loadFileList(path string) []File { if err = file.Close(); err != nil { logger.Panic(err) } +} + +func storeFileList(dest string, files []File) { + storeBasicStruct(dest, files) +} + +func loadFileList(path string) []File { + var files []File + loadBasicStruct(path, &files) return files } @@ -574,6 +590,26 @@ func loadRecipe(path string) []Chunk { return recipe } +func storeFingerprints(dest string, fingerprints FingerprintMap) { + storeBasicStruct(dest, fingerprints) +} + +func loadFingerprints(path string) FingerprintMap { + var fingerprints FingerprintMap + loadBasicStruct(path, &fingerprints) + return fingerprints +} + +func storeSketches(dest string, sketches SketchMap) { + storeBasicStruct(dest, sketches) +} + +func loadSketches(path string) SketchMap { + var sketches SketchMap + loadBasicStruct(path, &sketches) + return sketches +} + func extractDeltaChunks(chunks []Chunk) (ret []*DeltaChunk) { for _, c := range chunks { tmp, isDelta := c.(*DeltaChunk) diff --git a/repo_test.go b/repo_test.go index b16ddc6..f6f6edd 100644 --- a/repo_test.go +++ b/repo_test.go @@ -319,6 +319,7 @@ func assertSameTree(t *testing.T, apply func(t *testing.T, expected string, actu func assertCompatibleRepoFile(t *testing.T, expected string, actual string, prefix string) { if filepath.Base(expected) == filesName { + // Filelist file eFiles := loadFileList(expected) aFiles := loadFileList(actual) assertLen(t, len(eFiles), aFiles, prefix) @@ -329,8 +330,23 @@ func assertCompatibleRepoFile(t *testing.T, expected string, actual string, pref } } } else if filepath.Base(expected) == recipeName { - // TODO: check recipies equality + // Recipe file + eRecipe := loadRecipe(expected) + aRecipe := loadRecipe(actual) + assertLen(t, len(eRecipe), aRecipe, prefix) + for i, eChunk := range eRecipe { + if reflect.DeepEqual(eChunk, aRecipe[i]) { + continue + } else { + t.Fatal(prefix, "chunk do not match:", aRecipe[i], ", expected", eChunk) + } + } + } else if filepath.Base(expected) == sketchesName { + // TODO: check Sketches file + } else if filepath.Base(expected) == fingerprintsName { + // TODO: check Fingerprints file } else { + // Chunk content file assertSameFile(t, expected, actual, prefix) } } diff --git a/testdata/repo_8k/00000/fingerprints b/testdata/repo_8k/00000/fingerprints Binary files differnew file mode 100644 index 0000000..d015949 --- /dev/null +++ b/testdata/repo_8k/00000/fingerprints diff --git a/testdata/repo_8k/00000/sketches b/testdata/repo_8k/00000/sketches Binary files differnew file mode 100644 index 0000000..83572df --- /dev/null +++ b/testdata/repo_8k/00000/sketches diff --git a/testdata/repo_8k_zlib/00000/fingerprints b/testdata/repo_8k_zlib/00000/fingerprints Binary files differnew file mode 100644 index 0000000..d015949 --- /dev/null +++ b/testdata/repo_8k_zlib/00000/fingerprints diff --git a/testdata/repo_8k_zlib/00000/sketches b/testdata/repo_8k_zlib/00000/sketches Binary files differnew file mode 100644 index 0000000..83572df --- /dev/null +++ b/testdata/repo_8k_zlib/00000/sketches |