mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-20 12:47:35 +00:00
Rework generation of links in repo, use Source path.
This commit is contained in:
Vendored
+17
-12
@@ -56,35 +56,40 @@ func (r *Repository) CreateFile(path string) (*os.File, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LinkFromPool links package file from pool to dist's pool location
|
// 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)
|
sourcePath, err := r.PoolPath(filename, hashMD5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
baseName := filepath.Base(filename)
|
if len(source) < 3 {
|
||||||
|
return "", fmt.Errorf("package source %s too short", source)
|
||||||
if len(baseName) < 8 {
|
|
||||||
return fmt.Errorf("package filename %s too short", baseName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var subdir string
|
var subdir string
|
||||||
if strings.HasPrefix(baseName, "lib") {
|
if strings.HasPrefix(source, "lib") {
|
||||||
subdir = baseName[:4]
|
subdir = source[:4]
|
||||||
} else {
|
} 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)
|
err = os.MkdirAll(poolPath, 0755)
|
||||||
if err != nil {
|
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))
|
err = os.Link(sourcePath, filepath.Join(poolPath, baseName))
|
||||||
return err
|
return relPath, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChecksumsForFile proxies requests to utils.ChecksumsForFile, joining public path
|
// ChecksumsForFile proxies requests to utils.ChecksumsForFile, joining public path
|
||||||
|
|||||||
Vendored
+16
-6
@@ -52,17 +52,26 @@ func (s *RepositorySuite) TestLinkFromPool(c *C) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
packageFilename string
|
packageFilename string
|
||||||
MD5 string
|
MD5 string
|
||||||
|
source string
|
||||||
expectedFilename string
|
expectedFilename string
|
||||||
}{
|
}{
|
||||||
{
|
{ // package name regular
|
||||||
packageFilename: "pool/m/mars-invaders_1.03.deb",
|
packageFilename: "pool/m/mars-invaders_1.03.deb",
|
||||||
MD5: "91b1a1480b90b9e269ca44d897b12575",
|
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",
|
packageFilename: "pool/libm/libmars-invaders_1.03.deb",
|
||||||
MD5: "12c2a1480b90b9e269ca44d897b12575",
|
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.Write([]byte("Contents"))
|
||||||
file.Close()
|
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(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)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
info := st.Sys().(*syscall.Stat_t)
|
info := st.Sys().(*syscall.Stat_t)
|
||||||
|
|||||||
Reference in New Issue
Block a user