mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
Rework generation of links in repo, use Source path.
This commit is contained in:
29
debian/repository.go
vendored
29
debian/repository.go
vendored
@@ -56,35 +56,40 @@ func (r *Repository) CreateFile(path string) (*os.File, error) {
|
||||
}
|
||||
|
||||
// LinkFromPool links package file from pool to dist's pool location
|
||||
func (r *Repository) LinkFromPool(prefix string, component string, filename string, hashMD5 string) error {
|
||||
func (r *Repository) LinkFromPool(prefix string, component string, filename string, hashMD5 string, source string) (string, error) {
|
||||
sourcePath, err := r.PoolPath(filename, hashMD5)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
baseName := filepath.Base(filename)
|
||||
|
||||
if len(baseName) < 8 {
|
||||
return fmt.Errorf("package filename %s too short", baseName)
|
||||
if len(source) < 3 {
|
||||
return "", fmt.Errorf("package source %s too short", source)
|
||||
}
|
||||
|
||||
var subdir string
|
||||
if strings.HasPrefix(baseName, "lib") {
|
||||
subdir = baseName[:4]
|
||||
if strings.HasPrefix(source, "lib") {
|
||||
subdir = source[:4]
|
||||
} else {
|
||||
subdir = baseName[:1]
|
||||
subdir = source[:1]
|
||||
|
||||
}
|
||||
|
||||
poolPath := filepath.Join(r.RootPath, "public", prefix, "pool", component, subdir)
|
||||
baseName := filepath.Base(filename)
|
||||
relPath := filepath.Join("pool", component, subdir, source, baseName)
|
||||
poolPath := filepath.Join(r.RootPath, "public", prefix, "pool", component, subdir, source)
|
||||
|
||||
err = os.MkdirAll(poolPath, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
_, err = os.Stat(filepath.Join(poolPath, baseName))
|
||||
if err == nil { // already exists, skip
|
||||
return relPath, nil
|
||||
}
|
||||
|
||||
err = os.Link(sourcePath, filepath.Join(poolPath, baseName))
|
||||
return err
|
||||
return relPath, err
|
||||
}
|
||||
|
||||
// ChecksumsForFile proxies requests to utils.ChecksumsForFile, joining public path
|
||||
|
||||
22
debian/repository_test.go
vendored
22
debian/repository_test.go
vendored
@@ -52,17 +52,26 @@ func (s *RepositorySuite) TestLinkFromPool(c *C) {
|
||||
tests := []struct {
|
||||
packageFilename string
|
||||
MD5 string
|
||||
source string
|
||||
expectedFilename string
|
||||
}{
|
||||
{
|
||||
{ // package name regular
|
||||
packageFilename: "pool/m/mars-invaders_1.03.deb",
|
||||
MD5: "91b1a1480b90b9e269ca44d897b12575",
|
||||
expectedFilename: "public/pool/main/m/mars-invaders_1.03.deb",
|
||||
source: "mars-invaders",
|
||||
expectedFilename: "pool/main/m/mars-invaders/mars-invaders_1.03.deb",
|
||||
},
|
||||
{
|
||||
{ // lib-like filename
|
||||
packageFilename: "pool/libm/libmars-invaders_1.03.deb",
|
||||
MD5: "12c2a1480b90b9e269ca44d897b12575",
|
||||
expectedFilename: "public/pool/main/libm/libmars-invaders_1.03.deb",
|
||||
source: "libmars-invaders",
|
||||
expectedFilename: "pool/main/libm/libmars-invaders/libmars-invaders_1.03.deb",
|
||||
},
|
||||
{ // duplicate link, shouldn't panic
|
||||
packageFilename: "pool/m/mars-invaders_1.03.deb",
|
||||
MD5: "91b1a1480b90b9e269ca44d897b12575",
|
||||
source: "mars-invaders",
|
||||
expectedFilename: "pool/main/m/mars-invaders/mars-invaders_1.03.deb",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -79,10 +88,11 @@ func (s *RepositorySuite) TestLinkFromPool(c *C) {
|
||||
file.Write([]byte("Contents"))
|
||||
file.Close()
|
||||
|
||||
err = s.repo.LinkFromPool("", "main", t.packageFilename, t.MD5)
|
||||
path, err := s.repo.LinkFromPool("", "main", t.packageFilename, t.MD5, t.source)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(path, Equals, t.expectedFilename)
|
||||
|
||||
st, err := os.Stat(filepath.Join(s.repo.RootPath, t.expectedFilename))
|
||||
st, err := os.Stat(filepath.Join(s.repo.RootPath, "public", t.expectedFilename))
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
info := st.Sys().(*syscall.Stat_t)
|
||||
|
||||
Reference in New Issue
Block a user