From ec108fb708285944f5c1043f5a55a1191858cd34 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 29 Apr 2015 22:30:00 +0200 Subject: [PATCH] Remove backend.Tree --- archiver_test.go | 8 +++----- backend/backend_test.go | 2 +- backend/interface.go | 1 - backend/local/local.go | 11 ++--------- backend/paths.go | 2 -- backend/sftp/sftp.go | 11 ++--------- cache.go | 4 ---- 7 files changed, 8 insertions(+), 31 deletions(-) diff --git a/archiver_test.go b/archiver_test.go index 8cd45a8ca..c64f0d145 100644 --- a/archiver_test.go +++ b/archiver_test.go @@ -247,14 +247,12 @@ func BenchmarkLoadTree(t *testing.B) { list := make([]backend.ID, 0, 10) done := make(chan struct{}) - for name := range s.List(backend.Tree, done) { - id, err := backend.ParseID(name) - if err != nil { - t.Logf("invalid id for tree %v", name) + for blob := range s.Index().Each(done) { + if blob.Type != pack.Tree { continue } - list = append(list, id) + list = append(list, blob.ID) if len(list) == cap(list) { close(done) break diff --git a/backend/backend_test.go b/backend/backend_test.go index 49e151336..da5606551 100644 --- a/backend/backend_test.go +++ b/backend/backend_test.go @@ -15,7 +15,7 @@ import ( func testBackend(b backend.Backend, t *testing.T) { for _, tpe := range []backend.Type{ backend.Data, backend.Key, backend.Lock, - backend.Snapshot, backend.Tree, backend.Index, + backend.Snapshot, backend.Index, } { // detect non-existing files for _, test := range TestStrings { diff --git a/backend/interface.go b/backend/interface.go index 31cef66d0..a20b0e751 100644 --- a/backend/interface.go +++ b/backend/interface.go @@ -10,7 +10,6 @@ const ( Key = "key" Lock = "lock" Snapshot = "snapshot" - Tree = "tree" Index = "index" ) diff --git a/backend/local/local.go b/backend/local/local.go index 442a5ffcf..0fbd5fcf7 100644 --- a/backend/local/local.go +++ b/backend/local/local.go @@ -30,7 +30,6 @@ func Open(dir string) (*Local, error) { dir, filepath.Join(dir, backend.Paths.Data), filepath.Join(dir, backend.Paths.Snapshots), - filepath.Join(dir, backend.Paths.Trees), filepath.Join(dir, backend.Paths.Index), filepath.Join(dir, backend.Paths.Locks), filepath.Join(dir, backend.Paths.Keys), @@ -103,7 +102,6 @@ func Create(dir string) (*Local, error) { dir, filepath.Join(dir, backend.Paths.Data), filepath.Join(dir, backend.Paths.Snapshots), - filepath.Join(dir, backend.Paths.Trees), filepath.Join(dir, backend.Paths.Index), filepath.Join(dir, backend.Paths.Locks), filepath.Join(dir, backend.Paths.Keys), @@ -224,7 +222,7 @@ func (lb *localBlob) Finalize(t backend.Type, name string) error { f := filename(lb.basedir, t, name) // create directories if necessary, ignore errors - if t == backend.Data || t == backend.Tree { + if t == backend.Data { os.MkdirAll(filepath.Dir(f), backend.Modes.Dir) } @@ -281,11 +279,6 @@ func dirname(base string, t backend.Type, name string) string { } case backend.Snapshot: n = backend.Paths.Snapshots - case backend.Tree: - n = backend.Paths.Trees - if len(name) > 2 { - n = filepath.Join(n, name[:2]) - } case backend.Index: n = backend.Paths.Index case backend.Lock: @@ -346,7 +339,7 @@ func (b *Local) Remove(t backend.Type, name string) error { func (b *Local) List(t backend.Type, done <-chan struct{}) <-chan string { // TODO: use os.Open() and d.Readdirnames() instead of Glob() var pattern string - if t == backend.Data || t == backend.Tree { + if t == backend.Data { pattern = filepath.Join(dirname(b.p, t, ""), "*", "*") } else { pattern = filepath.Join(dirname(b.p, t, ""), "*") diff --git a/backend/paths.go b/backend/paths.go index 4b1246e13..d697a6cc6 100644 --- a/backend/paths.go +++ b/backend/paths.go @@ -6,7 +6,6 @@ import "os" var Paths = struct { Data string Snapshots string - Trees string Index string Locks string Keys string @@ -16,7 +15,6 @@ var Paths = struct { }{ "data", "snapshots", - "trees", "index", "locks", "keys", diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go index 115d32ef7..aa0fdd2af 100644 --- a/backend/sftp/sftp.go +++ b/backend/sftp/sftp.go @@ -78,7 +78,6 @@ func Open(dir string, program string, args ...string) (*SFTP, error) { dir, filepath.Join(dir, backend.Paths.Data), filepath.Join(dir, backend.Paths.Snapshots), - filepath.Join(dir, backend.Paths.Trees), filepath.Join(dir, backend.Paths.Index), filepath.Join(dir, backend.Paths.Locks), filepath.Join(dir, backend.Paths.Keys), @@ -153,7 +152,6 @@ func Create(dir string, program string, args ...string) (*SFTP, error) { dir, filepath.Join(dir, backend.Paths.Data), filepath.Join(dir, backend.Paths.Snapshots), - filepath.Join(dir, backend.Paths.Trees), filepath.Join(dir, backend.Paths.Index), filepath.Join(dir, backend.Paths.Locks), filepath.Join(dir, backend.Paths.Keys), @@ -305,7 +303,7 @@ func (r *SFTP) renameFile(oldname string, t backend.Type, name string) error { filename := r.filename(t, name) // create directories if necessary - if t == backend.Data || t == backend.Tree { + if t == backend.Data { err := r.mkdirAll(filepath.Dir(filename), backend.Modes.Dir) if err != nil { return err @@ -405,11 +403,6 @@ func (r *SFTP) dirname(t backend.Type, name string) string { } case backend.Snapshot: n = backend.Paths.Snapshots - case backend.Tree: - n = backend.Paths.Trees - if len(name) > 2 { - n = filepath.Join(n, name[:2]) - } case backend.Index: n = backend.Paths.Index case backend.Lock: @@ -484,7 +477,7 @@ func (r *SFTP) List(t backend.Type, done <-chan struct{}) <-chan string { go func() { defer close(ch) - if t == backend.Data || t == backend.Tree { + if t == backend.Data { // read first level basedir := r.dirname(t, "") diff --git a/cache.go b/cache.go index 81f279ea9..eb3f9bf4f 100644 --- a/cache.go +++ b/cache.go @@ -146,8 +146,6 @@ func (c *Cache) List(t backend.Type) ([]CacheEntry, error) { switch t { case backend.Snapshot: dir = filepath.Join(c.base, "snapshots") - case backend.Tree: - dir = filepath.Join(c.base, "trees") default: return nil, fmt.Errorf("cache not supported for type %v", t) } @@ -200,8 +198,6 @@ func (c *Cache) filename(t backend.Type, subtype string, id backend.ID) (string, switch t { case backend.Snapshot: return filepath.Join(c.base, "snapshots", filename), nil - case backend.Tree: - return filepath.Join(c.base, "trees", filename), nil } return "", fmt.Errorf("cache not supported for type %v", t)