From 265814c7a5bc2e7e6add0ddf0e241aa7e1926ea7 Mon Sep 17 00:00:00 2001 From: Chapuis Bertil Date: Thu, 17 Sep 2015 09:17:42 +0200 Subject: [PATCH] corrected the directory layout --- handlers.go | 1 + repository.go | 28 ++++++++++++++-------------- variables.go | 8 ++------ 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/handlers.go b/handlers.go index dd0788e..76ed219 100644 --- a/handlers.go +++ b/handlers.go @@ -160,6 +160,7 @@ func GetBlob(w http.ResponseWriter, r *http.Request, c *Context) { } func PostBlob(w http.ResponseWriter, r *http.Request, c *Context) { + uri := r.RequestURI name, err := RepositoryName(uri) if err != nil { diff --git a/repository.go b/repository.go index 4921672..222718e 100644 --- a/repository.go +++ b/repository.go @@ -18,11 +18,11 @@ type Repository struct { func NewRepository(path string) (*Repository, error) { dirs := []string{ path, - filepath.Join(path, string(backend.Data)), - filepath.Join(path, string(backend.Snapshot)), - filepath.Join(path, string(backend.Index)), - filepath.Join(path, string(backend.Lock)), - filepath.Join(path, string(backend.Key)), + filepath.Join(path, backend.Paths.Data), + filepath.Join(path, backend.Paths.Snapshots), + filepath.Join(path, backend.Paths.Index), + filepath.Join(path, backend.Paths.Locks), + filepath.Join(path, backend.Paths.Keys), } for _, d := range dirs { _, err := os.Stat(d) @@ -54,7 +54,7 @@ func (r *Repository) WriteConfig(data []byte) error { return ioutil.WriteFile(file, data, backend.Modes.File) } -func (r *Repository) ListBlob(t backend.Type) ([]string, error) { +func (r *Repository) ListBlob(t string) ([]string, error) { var blobs []string dir := filepath.Join(r.path, string(t)) files, err := ioutil.ReadDir(dir) @@ -68,16 +68,16 @@ func (r *Repository) ListBlob(t backend.Type) ([]string, error) { return blobs, nil } -func (r *Repository) HasBlob(bt backend.Type, id backend.ID) bool { - file := filepath.Join(r.path, string(bt), id.String()) +func (r *Repository) HasBlob(t string, id backend.ID) bool { + file := filepath.Join(r.path, string(t), id.String()) if _, err := os.Stat(file); err != nil { return false } return true } -func (r *Repository) ReadBlob(bt backend.Type, id backend.ID) (io.ReadSeeker, error) { - file := filepath.Join(r.path, string(bt), id.String()) +func (r *Repository) ReadBlob(t string, id backend.ID) (io.ReadSeeker, error) { + file := filepath.Join(r.path, string(t), id.String()) blob, err := ioutil.ReadFile(file) if err != nil { return nil, err @@ -85,12 +85,12 @@ func (r *Repository) ReadBlob(bt backend.Type, id backend.ID) (io.ReadSeeker, er return bytes.NewReader(blob), nil } -func (r *Repository) WriteBlob(bt backend.Type, id backend.ID, data []byte) error { - file := filepath.Join(r.path, string(bt), id.String()) +func (r *Repository) WriteBlob(t string, id backend.ID, data []byte) error { + file := filepath.Join(r.path, string(t), id.String()) return ioutil.WriteFile(file, data, backend.Modes.File) } -func (r *Repository) DeleteBlob(bt backend.Type, id backend.ID) error { - file := filepath.Join(r.path, string(bt), id.String()) +func (r *Repository) DeleteBlob(t string, id backend.ID) error { + file := filepath.Join(r.path, string(t), id.String()) return os.Remove(file) } diff --git a/variables.go b/variables.go index ff14252..ad4666b 100644 --- a/variables.go +++ b/variables.go @@ -29,13 +29,9 @@ func ParseRepositoryName(n string) (string, error) { } // Returns the backend type for a given path -func BackendType(u string) backend.Type { +func BackendType(u string) string { s := strings.Split(u, "/") - var bt backend.Type - if len(s) > 2 { - bt = parseBackendType(s[2]) - } - return bt + return s[2] } func parseBackendType(u string) backend.Type {