mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-30 04:20:53 +00:00
Refactoring: build pool path in Package. #8
This commit is contained in:
+6
-4
@@ -388,16 +388,18 @@ func (p *Package) LinkFromPool(publishedStorage aptly.PublishedStorage, packageP
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
relPath, err := publishedStorage.LinkFromPool(prefix, component, poolDir, packagePool, sourcePath)
|
relPath := filepath.Join("pool", component, poolDir)
|
||||||
|
publishedDirectory := filepath.Join(prefix, relPath)
|
||||||
|
|
||||||
|
err = publishedStorage.LinkFromPool(publishedDirectory, packagePool, sourcePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := filepath.Dir(relPath)
|
|
||||||
if p.IsSource {
|
if p.IsSource {
|
||||||
p.Extra()["Directory"] = dir
|
p.Extra()["Directory"] = relPath
|
||||||
} else {
|
} else {
|
||||||
p.Files()[i].downloadPath = dir
|
p.Files()[i].downloadPath = relPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-11
@@ -47,34 +47,29 @@ func (storage *PublishedStorage) RemoveDirs(path string) error {
|
|||||||
|
|
||||||
// LinkFromPool links package file from pool to dist's pool location
|
// LinkFromPool links package file from pool to dist's pool location
|
||||||
//
|
//
|
||||||
// prefix is publishing prefix for this repo (e.g. empty or "ppa/")
|
// publishedDirectory is desired location in pool (like prefix/pool/component/liba/libav/)
|
||||||
// component is component name when publishing (e.g. main)
|
|
||||||
// poolDirectory is desired location in pool (like liba/libav/)
|
|
||||||
// sourcePool is instance of aptly.PackagePool
|
// sourcePool is instance of aptly.PackagePool
|
||||||
// sourcePath is filepath to package file in package pool
|
// sourcePath is filepath to package file in package pool
|
||||||
//
|
//
|
||||||
// LinkFromPool returns relative path for the published file to be included in package index
|
// LinkFromPool returns relative path for the published file to be included in package index
|
||||||
func (storage *PublishedStorage) LinkFromPool(prefix string, component string, poolDirectory string, sourcePool aptly.PackagePool, sourcePath string) (string, error) {
|
func (storage *PublishedStorage) LinkFromPool(publishedDirectory string, sourcePool aptly.PackagePool, sourcePath string) error {
|
||||||
// verify that package pool is local pool is filesystem pool
|
// verify that package pool is local pool is filesystem pool
|
||||||
_ = sourcePool.(*PackagePool)
|
_ = sourcePool.(*PackagePool)
|
||||||
|
|
||||||
baseName := filepath.Base(sourcePath)
|
baseName := filepath.Base(sourcePath)
|
||||||
|
poolPath := filepath.Join(storage.rootPath, publishedDirectory)
|
||||||
relPath := filepath.Join("pool", component, poolDirectory, baseName)
|
|
||||||
poolPath := filepath.Join(storage.rootPath, prefix, "pool", component, poolDirectory)
|
|
||||||
|
|
||||||
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))
|
_, err = os.Stat(filepath.Join(poolPath, baseName))
|
||||||
if err == nil { // already exists, skip
|
if err == nil { // already exists, skip
|
||||||
return relPath, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Link(sourcePath, filepath.Join(poolPath, baseName))
|
return os.Link(sourcePath, filepath.Join(poolPath, baseName))
|
||||||
return relPath, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChecksumsForFile proxies requests to utils.ChecksumsForFile, joining public path
|
// ChecksumsForFile proxies requests to utils.ChecksumsForFile, joining public path
|
||||||
|
|||||||
@@ -123,9 +123,8 @@ func (s *PublishedStorageSuite) TestLinkFromPool(c *C) {
|
|||||||
err = ioutil.WriteFile(t.sourcePath, []byte("Contents"), 0644)
|
err = ioutil.WriteFile(t.sourcePath, []byte("Contents"), 0644)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
path, err := s.storage.LinkFromPool(t.prefix, t.component, t.poolDirectory, pool, t.sourcePath)
|
err = s.storage.LinkFromPool(filepath.Join(t.prefix, "pool", t.component, t.poolDirectory), pool, t.sourcePath)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(path, Equals, t.expectedFilename)
|
|
||||||
|
|
||||||
st, err := os.Stat(filepath.Join(s.storage.rootPath, t.prefix, t.expectedFilename))
|
st, err := os.Stat(filepath.Join(s.storage.rootPath, t.prefix, t.expectedFilename))
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|||||||
Reference in New Issue
Block a user