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)
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

View File

@ -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 {

View File

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

View File

@ -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, ""), "*")

View File

@ -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",

View File

@ -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, "")

View File

@ -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)