Remove backend.Tree

This commit is contained in:
Alexander Neumann 2015-04-29 22:30:00 +02:00
parent 29ead95c96
commit ec108fb708
7 changed files with 8 additions and 31 deletions

View File

@ -247,14 +247,12 @@ func BenchmarkLoadTree(t *testing.B) {
list := make([]backend.ID, 0, 10) list := make([]backend.ID, 0, 10)
done := make(chan struct{}) done := make(chan struct{})
for name := range s.List(backend.Tree, done) { for blob := range s.Index().Each(done) {
id, err := backend.ParseID(name) if blob.Type != pack.Tree {
if err != nil {
t.Logf("invalid id for tree %v", name)
continue continue
} }
list = append(list, id) list = append(list, blob.ID)
if len(list) == cap(list) { if len(list) == cap(list) {
close(done) close(done)
break break

View File

@ -15,7 +15,7 @@ import (
func testBackend(b backend.Backend, t *testing.T) { func testBackend(b backend.Backend, t *testing.T) {
for _, tpe := range []backend.Type{ for _, tpe := range []backend.Type{
backend.Data, backend.Key, backend.Lock, backend.Data, backend.Key, backend.Lock,
backend.Snapshot, backend.Tree, backend.Index, backend.Snapshot, backend.Index,
} { } {
// detect non-existing files // detect non-existing files
for _, test := range TestStrings { for _, test := range TestStrings {

View File

@ -10,7 +10,6 @@ const (
Key = "key" Key = "key"
Lock = "lock" Lock = "lock"
Snapshot = "snapshot" Snapshot = "snapshot"
Tree = "tree"
Index = "index" Index = "index"
) )

View File

@ -30,7 +30,6 @@ func Open(dir string) (*Local, error) {
dir, dir,
filepath.Join(dir, backend.Paths.Data), filepath.Join(dir, backend.Paths.Data),
filepath.Join(dir, backend.Paths.Snapshots), filepath.Join(dir, backend.Paths.Snapshots),
filepath.Join(dir, backend.Paths.Trees),
filepath.Join(dir, backend.Paths.Index), filepath.Join(dir, backend.Paths.Index),
filepath.Join(dir, backend.Paths.Locks), filepath.Join(dir, backend.Paths.Locks),
filepath.Join(dir, backend.Paths.Keys), filepath.Join(dir, backend.Paths.Keys),
@ -103,7 +102,6 @@ func Create(dir string) (*Local, error) {
dir, dir,
filepath.Join(dir, backend.Paths.Data), filepath.Join(dir, backend.Paths.Data),
filepath.Join(dir, backend.Paths.Snapshots), filepath.Join(dir, backend.Paths.Snapshots),
filepath.Join(dir, backend.Paths.Trees),
filepath.Join(dir, backend.Paths.Index), filepath.Join(dir, backend.Paths.Index),
filepath.Join(dir, backend.Paths.Locks), filepath.Join(dir, backend.Paths.Locks),
filepath.Join(dir, backend.Paths.Keys), 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) f := filename(lb.basedir, t, name)
// create directories if necessary, ignore errors // 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) 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: case backend.Snapshot:
n = backend.Paths.Snapshots n = backend.Paths.Snapshots
case backend.Tree:
n = backend.Paths.Trees
if len(name) > 2 {
n = filepath.Join(n, name[:2])
}
case backend.Index: case backend.Index:
n = backend.Paths.Index n = backend.Paths.Index
case backend.Lock: 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 { func (b *Local) List(t backend.Type, done <-chan struct{}) <-chan string {
// TODO: use os.Open() and d.Readdirnames() instead of Glob() // TODO: use os.Open() and d.Readdirnames() instead of Glob()
var pattern string var pattern string
if t == backend.Data || t == backend.Tree { if t == backend.Data {
pattern = filepath.Join(dirname(b.p, t, ""), "*", "*") pattern = filepath.Join(dirname(b.p, t, ""), "*", "*")
} else { } else {
pattern = filepath.Join(dirname(b.p, t, ""), "*") pattern = filepath.Join(dirname(b.p, t, ""), "*")

View File

@ -6,7 +6,6 @@ import "os"
var Paths = struct { var Paths = struct {
Data string Data string
Snapshots string Snapshots string
Trees string
Index string Index string
Locks string Locks string
Keys string Keys string
@ -16,7 +15,6 @@ var Paths = struct {
}{ }{
"data", "data",
"snapshots", "snapshots",
"trees",
"index", "index",
"locks", "locks",
"keys", "keys",

View File

@ -78,7 +78,6 @@ func Open(dir string, program string, args ...string) (*SFTP, error) {
dir, dir,
filepath.Join(dir, backend.Paths.Data), filepath.Join(dir, backend.Paths.Data),
filepath.Join(dir, backend.Paths.Snapshots), filepath.Join(dir, backend.Paths.Snapshots),
filepath.Join(dir, backend.Paths.Trees),
filepath.Join(dir, backend.Paths.Index), filepath.Join(dir, backend.Paths.Index),
filepath.Join(dir, backend.Paths.Locks), filepath.Join(dir, backend.Paths.Locks),
filepath.Join(dir, backend.Paths.Keys), filepath.Join(dir, backend.Paths.Keys),
@ -153,7 +152,6 @@ func Create(dir string, program string, args ...string) (*SFTP, error) {
dir, dir,
filepath.Join(dir, backend.Paths.Data), filepath.Join(dir, backend.Paths.Data),
filepath.Join(dir, backend.Paths.Snapshots), filepath.Join(dir, backend.Paths.Snapshots),
filepath.Join(dir, backend.Paths.Trees),
filepath.Join(dir, backend.Paths.Index), filepath.Join(dir, backend.Paths.Index),
filepath.Join(dir, backend.Paths.Locks), filepath.Join(dir, backend.Paths.Locks),
filepath.Join(dir, backend.Paths.Keys), 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) filename := r.filename(t, name)
// create directories if necessary // create directories if necessary
if t == backend.Data || t == backend.Tree { if t == backend.Data {
err := r.mkdirAll(filepath.Dir(filename), backend.Modes.Dir) err := r.mkdirAll(filepath.Dir(filename), backend.Modes.Dir)
if err != nil { if err != nil {
return err return err
@ -405,11 +403,6 @@ func (r *SFTP) dirname(t backend.Type, name string) string {
} }
case backend.Snapshot: case backend.Snapshot:
n = backend.Paths.Snapshots n = backend.Paths.Snapshots
case backend.Tree:
n = backend.Paths.Trees
if len(name) > 2 {
n = filepath.Join(n, name[:2])
}
case backend.Index: case backend.Index:
n = backend.Paths.Index n = backend.Paths.Index
case backend.Lock: case backend.Lock:
@ -484,7 +477,7 @@ func (r *SFTP) List(t backend.Type, done <-chan struct{}) <-chan string {
go func() { go func() {
defer close(ch) defer close(ch)
if t == backend.Data || t == backend.Tree { if t == backend.Data {
// read first level // read first level
basedir := r.dirname(t, "") basedir := r.dirname(t, "")

View File

@ -146,8 +146,6 @@ func (c *Cache) List(t backend.Type) ([]CacheEntry, error) {
switch t { switch t {
case backend.Snapshot: case backend.Snapshot:
dir = filepath.Join(c.base, "snapshots") dir = filepath.Join(c.base, "snapshots")
case backend.Tree:
dir = filepath.Join(c.base, "trees")
default: default:
return nil, fmt.Errorf("cache not supported for type %v", t) 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 { switch t {
case backend.Snapshot: case backend.Snapshot:
return filepath.Join(c.base, "snapshots", filename), nil 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) return "", fmt.Errorf("cache not supported for type %v", t)