fix PublishedStorage's ReadLink to return a relative path

previously it'd return an absolute path which makes the path absolutely
useless as all other functions of PublishedStorage need relative input
and will prepend them with the rootPath, so getting an absolute ReadLink
and then trying to remove that'd would ultimately try to remove the
absolute path `$root/AbsoluteRoot/LinkTarget` instead of `$root/LinkTarget`

add a unit test to actually verify readlink
This commit is contained in:
Harald Sitter
2018-02-19 17:13:41 +01:00
parent 3c04c56639
commit 3ea803e3bb
2 changed files with 11 additions and 2 deletions

View File

@@ -267,7 +267,12 @@ func (storage *PublishedStorage) FileExists(path string) (bool, error) {
return true, nil
}
// ReadLink returns the symbolic link pointed to by path
// ReadLink returns the symbolic link pointed to by path (relative to storage
// root)
func (storage *PublishedStorage) ReadLink(path string) (string, error) {
return os.Readlink(path)
absPath, err := os.Readlink(filepath.Join(storage.rootPath, path))
if err != nil {
return absPath, err
}
return filepath.Rel(storage.rootPath, absPath)
}

View File

@@ -129,6 +129,10 @@ func (s *PublishedStorageSuite) TestSymLink(c *C) {
exists, _ := s.storage.FileExists("ppa/dists/squeeze/InRelease")
c.Check(exists, Equals, true)
linkTarget, err := s.storage.ReadLink("ppa/dists/squeeze/InRelease")
c.Assert(err, IsNil)
c.Assert(linkTarget, Equals, "ppa/dists/squeeze/Release")
}
func (s *PublishedStorageSuite) TestHardLink(c *C) {