mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-08 05:50:47 +00:00
Fix bug with PoolPath field being overwritten on mirror update
While updating mirror, if package file is already in pool path, field `PoolPath` was left as empty which results in package file being unavailable later on while publishing.
This commit is contained in:
@@ -162,7 +162,7 @@ func (pool *PackagePool) ensureChecksums(poolPath, fullPoolPath string, checksum
|
||||
//
|
||||
// if poolPath is empty, poolPath is generated automatically based on checksum info (if available)
|
||||
// in any case, if function returns true, it also fills back checksums with complete information about the file in the pool
|
||||
func (pool *PackagePool) Verify(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage aptly.ChecksumStorage) (bool, error) {
|
||||
func (pool *PackagePool) Verify(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage aptly.ChecksumStorage) (string, bool, error) {
|
||||
possiblePoolPaths := []string{}
|
||||
|
||||
if poolPath != "" {
|
||||
@@ -172,7 +172,7 @@ func (pool *PackagePool) Verify(poolPath, basename string, checksums *utils.Chec
|
||||
if checksums.SHA256 != "" {
|
||||
modernPath, err := pool.buildPoolPath(basename, checksums)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return "", false, err
|
||||
}
|
||||
possiblePoolPaths = append(possiblePoolPaths, modernPath)
|
||||
}
|
||||
@@ -180,7 +180,7 @@ func (pool *PackagePool) Verify(poolPath, basename string, checksums *utils.Chec
|
||||
if pool.supportLegacyPaths && checksums.MD5 != "" {
|
||||
legacyPath, err := pool.LegacyPath(basename, checksums)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return "", false, err
|
||||
}
|
||||
possiblePoolPaths = append(possiblePoolPaths, legacyPath)
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func (pool *PackagePool) Verify(poolPath, basename string, checksums *utils.Chec
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
// unable to stat target location?
|
||||
return false, err
|
||||
return "", false, err
|
||||
}
|
||||
// doesn't exist, skip it
|
||||
continue
|
||||
@@ -208,21 +208,21 @@ func (pool *PackagePool) Verify(poolPath, basename string, checksums *utils.Chec
|
||||
targetChecksums, err = pool.ensureChecksums(path, fullPoolPath, checksumStorage)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
return "", false, err
|
||||
}
|
||||
|
||||
if checksums.MD5 != "" && targetChecksums.MD5 != checksums.MD5 ||
|
||||
checksums.SHA256 != "" && targetChecksums.SHA256 != checksums.SHA256 {
|
||||
// wrong file?
|
||||
return false, nil
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
// fill back checksums
|
||||
*checksums = *targetChecksums
|
||||
return true, nil
|
||||
return path, true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
// Import copies file into package pool
|
||||
|
||||
+22
-11
@@ -155,7 +155,8 @@ func (s *PackagePoolSuite) TestImportLegacy(c *C) {
|
||||
func (s *PackagePoolSuite) TestVerifyLegacy(c *C) {
|
||||
s.checksum.Size = 2738
|
||||
// file doesn't exist yet
|
||||
exists, err := s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
path, exists, err := s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
c.Check(path, Equals, "")
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, false)
|
||||
|
||||
@@ -164,7 +165,8 @@ func (s *PackagePoolSuite) TestVerifyLegacy(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
// check existence (and fills back checksum)
|
||||
exists, err = s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
path, exists, err = s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
c.Check(path, Equals, "00/35/libboost-program-options-dev_1.49.0.1_i386.deb")
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, true)
|
||||
c.Check(s.checksum.SHA512, Equals, "d7302241373da972aa9b9e71d2fd769b31a38f71182aa71bc0d69d090d452c69bb74b8612c002ccf8a89c279ced84ac27177c8b92d20f00023b3d268e6cec69c")
|
||||
@@ -172,7 +174,8 @@ func (s *PackagePoolSuite) TestVerifyLegacy(c *C) {
|
||||
|
||||
func (s *PackagePoolSuite) TestVerify(c *C) {
|
||||
// file doesn't exist yet
|
||||
exists, err := s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
ppath, exists, err := s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
c.Check(ppath, Equals, "")
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, false)
|
||||
|
||||
@@ -182,20 +185,23 @@ func (s *PackagePoolSuite) TestVerify(c *C) {
|
||||
c.Check(path, Equals, "c7/6b/4bd12fd92e4dfe1b55b18a67a669_libboost-program-options-dev_1.49.0.1_i386.deb")
|
||||
|
||||
// check existence
|
||||
exists, err = s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
ppath, exists, err = s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
c.Check(ppath, Equals, ppath)
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, true)
|
||||
c.Check(s.checksum.SHA512, Equals, "d7302241373da972aa9b9e71d2fd769b31a38f71182aa71bc0d69d090d452c69bb74b8612c002ccf8a89c279ced84ac27177c8b92d20f00023b3d268e6cec69c")
|
||||
|
||||
// check existence with fixed path
|
||||
exists, err = s.pool.Verify(path, filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
ppath, exists, err = s.pool.Verify(path, filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
c.Check(ppath, Equals, path)
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, true)
|
||||
c.Check(s.checksum.SHA512, Equals, "d7302241373da972aa9b9e71d2fd769b31a38f71182aa71bc0d69d090d452c69bb74b8612c002ccf8a89c279ced84ac27177c8b92d20f00023b3d268e6cec69c")
|
||||
|
||||
// check existence, but with missing checksum
|
||||
s.checksum.SHA512 = ""
|
||||
exists, err = s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
ppath, exists, err = s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
c.Check(ppath, Equals, path)
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, true)
|
||||
// checksum is filled back based on checksum storage
|
||||
@@ -205,7 +211,8 @@ func (s *PackagePoolSuite) TestVerify(c *C) {
|
||||
ck := utils.ChecksumInfo{
|
||||
Size: s.checksum.Size,
|
||||
}
|
||||
exists, err = s.pool.Verify(path, filepath.Base(s.debFile), &ck, s.cs)
|
||||
ppath, exists, err = s.pool.Verify(path, filepath.Base(s.debFile), &ck, s.cs)
|
||||
c.Check(ppath, Equals, path)
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, true)
|
||||
// checksum is filled back based on checksum storage
|
||||
@@ -213,14 +220,16 @@ func (s *PackagePoolSuite) TestVerify(c *C) {
|
||||
|
||||
// check existence, with wrong checksum info but correct path and size available
|
||||
ck.SHA256 = "abc"
|
||||
exists, err = s.pool.Verify(path, filepath.Base(s.debFile), &ck, s.cs)
|
||||
ppath, exists, err = s.pool.Verify(path, filepath.Base(s.debFile), &ck, s.cs)
|
||||
c.Check(ppath, Equals, "")
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, false)
|
||||
|
||||
// check existence, with missing checksum and no info in checksum storage
|
||||
delete(s.cs.(*mockChecksumStorage).store, path)
|
||||
s.checksum.SHA512 = ""
|
||||
exists, err = s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
ppath, exists, err = s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
c.Check(ppath, Equals, path)
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, true)
|
||||
// checksum is filled back based on re-calculation
|
||||
@@ -228,12 +237,14 @@ func (s *PackagePoolSuite) TestVerify(c *C) {
|
||||
|
||||
// check existence, with wrong size
|
||||
s.checksum.Size = 13455
|
||||
exists, err = s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
ppath, exists, err = s.pool.Verify("", filepath.Base(s.debFile), &s.checksum, s.cs)
|
||||
c.Check(ppath, Equals, "")
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, false)
|
||||
|
||||
// check existence, with empty checksum info
|
||||
exists, err = s.pool.Verify("", filepath.Base(s.debFile), &utils.ChecksumInfo{}, s.cs)
|
||||
ppath, exists, err = s.pool.Verify("", filepath.Base(s.debFile), &utils.ChecksumInfo{}, s.cs)
|
||||
c.Check(ppath, Equals, "")
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user