From 1bac201687c3ea851d479b45968dccf3039cd696 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 22 Apr 2014 16:20:51 +0400 Subject: [PATCH] Refactoring: build pool path in Package. #8 --- deb/package.go | 10 ++++++---- files/public.go | 17 ++++++----------- files/public_test.go | 3 +-- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/deb/package.go b/deb/package.go index 6028f4d0..a50ce44f 100644 --- a/deb/package.go +++ b/deb/package.go @@ -388,16 +388,18 @@ func (p *Package) LinkFromPool(publishedStorage aptly.PublishedStorage, packageP 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 { return err } - dir := filepath.Dir(relPath) if p.IsSource { - p.Extra()["Directory"] = dir + p.Extra()["Directory"] = relPath } else { - p.Files()[i].downloadPath = dir + p.Files()[i].downloadPath = relPath } } diff --git a/files/public.go b/files/public.go index 72dfaad2..404aaac6 100644 --- a/files/public.go +++ b/files/public.go @@ -47,34 +47,29 @@ func (storage *PublishedStorage) RemoveDirs(path string) error { // LinkFromPool links package file from pool to dist's pool location // -// prefix is publishing prefix for this repo (e.g. empty or "ppa/") -// component is component name when publishing (e.g. main) -// poolDirectory is desired location in pool (like liba/libav/) +// publishedDirectory is desired location in pool (like prefix/pool/component/liba/libav/) // sourcePool is instance of aptly.PackagePool // sourcePath is filepath to package file in package pool // // 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 _ = sourcePool.(*PackagePool) baseName := filepath.Base(sourcePath) - - relPath := filepath.Join("pool", component, poolDirectory, baseName) - poolPath := filepath.Join(storage.rootPath, prefix, "pool", component, poolDirectory) + poolPath := filepath.Join(storage.rootPath, publishedDirectory) 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 + return nil } - err = os.Link(sourcePath, filepath.Join(poolPath, baseName)) - return relPath, err + return os.Link(sourcePath, filepath.Join(poolPath, baseName)) } // ChecksumsForFile proxies requests to utils.ChecksumsForFile, joining public path diff --git a/files/public_test.go b/files/public_test.go index f310bc40..47cd9c0c 100644 --- a/files/public_test.go +++ b/files/public_test.go @@ -123,9 +123,8 @@ func (s *PublishedStorageSuite) TestLinkFromPool(c *C) { err = ioutil.WriteFile(t.sourcePath, []byte("Contents"), 0644) 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(path, Equals, t.expectedFilename) st, err := os.Stat(filepath.Join(s.storage.rootPath, t.prefix, t.expectedFilename)) c.Assert(err, IsNil)