From bd7006072926a55f1bbf3d34aa9184c6c751895a Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Wed, 17 Sep 2014 09:21:56 -0400 Subject: [PATCH] notes and base work --- NOTES.md | 2 +- base/base.go | 14 +++++++++++--- base/base_test.go | 11 +++++++++++ main.go | 2 -- 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 base/base_test.go diff --git a/NOTES.md b/NOTES.md index 9c83fa8..ca97f1b 100644 --- a/NOTES.md +++ b/NOTES.md @@ -1,4 +1,4 @@ ## things to watch for -* ownership and info on shared inodes +* shared inodes share all attributes too diff --git a/base/base.go b/base/base.go index 7818aad..97f1b92 100644 --- a/base/base.go +++ b/base/base.go @@ -7,12 +7,13 @@ import ( ) func NewBase(path string, hashName string) (*Base, error) { - for _, p := range []string{"dedup/blobs" + hashName, "dedup/state"} { - if err := os.MkdirAll(filepath.Join(path, p), 0755); err != nil { + root := filepath.Join(path, "dedup") + for _, p := range []string{"blobs/" + hashName, "state"} { + if err := os.MkdirAll(filepath.Join(root, p), 0755); err != nil { return nil, err } } - return &Base{Path: path, HashName: hashName}, nil + return &Base{Path: root, HashName: hashName}, nil } type Base struct { @@ -20,6 +21,13 @@ type Base struct { HashName string } +func (b Base) blobPath(sum string) string { + if len(sum) < 3 { + return "" + } + return filepath.Join(b.Path, "blobs", b.HashName, sum[0:2], sum) +} + // GetBlob store the content from src, for the sum and hashType func (b Base) GetBlob(sum string) (io.Reader, error) { // XXX diff --git a/base/base_test.go b/base/base_test.go new file mode 100644 index 0000000..d3a7f55 --- /dev/null +++ b/base/base_test.go @@ -0,0 +1,11 @@ +package base + +import "testing" + +func TestSumPath(t *testing.T) { + expected := "/var/dedup/blobs/sha1/de/deadbeef" + b := Base{Path: "/var/dedup", HashName: "sha1"} + if bp := b.blobPath("deadbeef"); bp != expected { + t.Errorf("expected %q, got %q", expected, bp) + } +} diff --git a/main.go b/main.go index 1fe6d41..f69db06 100644 --- a/main.go +++ b/main.go @@ -38,9 +38,7 @@ func main() { var ( hash = cryptomap.DetermineHash(*flCipher) //infos = []*file.FileHashInfo{} - //mu = sync.Mutex{} //results := make(chan file.FileHashInfo, 2) - //wg := sync.WaitGroup{} ) for _, arg := range flag.Args() {