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
+1
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) { func PostBlob(w http.ResponseWriter, r *http.Request, c *Context) {
uri := r.RequestURI uri := r.RequestURI
name, err := RepositoryName(uri) name, err := RepositoryName(uri)
if err != nil { if err != nil {
+14 -14
View File
@@ -18,11 +18,11 @@ type Repository struct {
func NewRepository(path string) (*Repository, error) { func NewRepository(path string) (*Repository, error) {
dirs := []string{ dirs := []string{
path, path,
filepath.Join(path, string(backend.Data)), filepath.Join(path, backend.Paths.Data),
filepath.Join(path, string(backend.Snapshot)), filepath.Join(path, backend.Paths.Snapshots),
filepath.Join(path, string(backend.Index)), filepath.Join(path, backend.Paths.Index),
filepath.Join(path, string(backend.Lock)), filepath.Join(path, backend.Paths.Locks),
filepath.Join(path, string(backend.Key)), filepath.Join(path, backend.Paths.Keys),
} }
for _, d := range dirs { for _, d := range dirs {
_, err := os.Stat(d) _, err := os.Stat(d)
@@ -54,7 +54,7 @@ func (r *Repository) WriteConfig(data []byte) error {
return ioutil.WriteFile(file, data, backend.Modes.File) 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 var blobs []string
dir := filepath.Join(r.path, string(t)) dir := filepath.Join(r.path, string(t))
files, err := ioutil.ReadDir(dir) files, err := ioutil.ReadDir(dir)
@@ -68,16 +68,16 @@ func (r *Repository) ListBlob(t backend.Type) ([]string, error) {
return blobs, nil return blobs, nil
} }
func (r *Repository) HasBlob(bt backend.Type, id backend.ID) bool { func (r *Repository) HasBlob(t string, id backend.ID) bool {
file := filepath.Join(r.path, string(bt), id.String()) file := filepath.Join(r.path, string(t), id.String())
if _, err := os.Stat(file); err != nil { if _, err := os.Stat(file); err != nil {
return false return false
} }
return true return true
} }
func (r *Repository) ReadBlob(bt backend.Type, id backend.ID) (io.ReadSeeker, error) { func (r *Repository) ReadBlob(t string, id backend.ID) (io.ReadSeeker, error) {
file := filepath.Join(r.path, string(bt), id.String()) file := filepath.Join(r.path, string(t), id.String())
blob, err := ioutil.ReadFile(file) blob, err := ioutil.ReadFile(file)
if err != nil { if err != nil {
return nil, err 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 return bytes.NewReader(blob), nil
} }
func (r *Repository) WriteBlob(bt backend.Type, id backend.ID, data []byte) error { func (r *Repository) WriteBlob(t string, id backend.ID, data []byte) error {
file := filepath.Join(r.path, string(bt), id.String()) file := filepath.Join(r.path, string(t), id.String())
return ioutil.WriteFile(file, data, backend.Modes.File) return ioutil.WriteFile(file, data, backend.Modes.File)
} }
func (r *Repository) DeleteBlob(bt backend.Type, id backend.ID) error { func (r *Repository) DeleteBlob(t string, id backend.ID) error {
file := filepath.Join(r.path, string(bt), id.String()) file := filepath.Join(r.path, string(t), id.String())
return os.Remove(file) return os.Remove(file)
} }
+2 -6
View File
@@ -29,13 +29,9 @@ func ParseRepositoryName(n string) (string, error) {
} }
// Returns the backend type for a given path // Returns the backend type for a given path
func BackendType(u string) backend.Type { func BackendType(u string) string {
s := strings.Split(u, "/") s := strings.Split(u, "/")
var bt backend.Type return s[2]
if len(s) > 2 {
bt = parseBackendType(s[2])
}
return bt
} }
func parseBackendType(u string) backend.Type { func parseBackendType(u string) backend.Type {