New layout for pool files, public subdir & operations.

This commit is contained in:
Andrey Smirnov
2013-12-24 11:53:22 +04:00
parent 2778d4891c
commit 634bfa7b94
3 changed files with 62 additions and 36 deletions
+34 -17
View File
@@ -2,10 +2,27 @@ package debian
import (
"fmt"
"os"
"path/filepath"
"strings"
)
// Repository directory structure:
// <root>
// \- pool
// \- ab
// \- ae
// \- package.deb
// \- public
// \- dists
// \- squeeze
// \- Release
// \- main
// \- binary-i386
// \- Packages.bz2
// references packages from pool
// \- pool
// contains symlinks to main pool
// Repository abstract file system with package pool and published package repos
type Repository struct {
RootPath string
@@ -16,22 +33,22 @@ func NewRepository(root string) *Repository {
return &Repository{RootPath: root}
}
// PoolPath returns full path to package file in pool
//
// PoolPath checks that final path doesn't go out of repository root path
func (r *Repository) PoolPath(filename string) (string, error) {
filename = filepath.Clean(filename)
if strings.HasPrefix(filename, ".") {
return "", fmt.Errorf("filename %s starts with dot", filename)
// PoolPath returns full path to package file in pool givan any name and hash of file contents
func (r *Repository) PoolPath(filename string, hashMD5 string) (string, error) {
filename = filepath.Base(filename)
if filename == "." || filename == "/" {
return "", fmt.Errorf("filename %s is invalid", filename)
}
if filepath.IsAbs(filename) {
return "", fmt.Errorf("absolute filename %s not supported", filename)
}
if strings.HasPrefix(filename, "pool/") {
filename = filename[5:]
}
return filepath.Join(r.RootPath, "pool", filename), nil
return filepath.Join(r.RootPath, "pool", hashMD5[0:2], hashMD5[2:4], filename), nil
}
// MkDir creates directory recursively under public path
func (r *Repository) MkDir(path string) error {
return os.MkdirAll(filepath.Join(r.RootPath, "public", path), 0755)
}
// CreateFile creates file for writing under public path
func (r *Repository) CreateFile(path string) (*os.File, error) {
return os.Create(filepath.Join(r.RootPath, "public", path))
}