corrected the directory layout

This commit is contained in:
Chapuis Bertil
2015-09-17 09:17:42 +02:00
parent 016bbf619a
commit 265814c7a5
3 changed files with 17 additions and 20 deletions

View File

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

View File

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

View File

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