mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Merge pull request #706 from apachelogger/fix-by-index-cleanup
Fix by by-hash index cleanup + root dir data "loss"
This commit is contained in:
+13
-9
@@ -191,18 +191,22 @@ func packageIndexByHash(file *indexFile, ext string, hash string, sum string) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if a previous index file already exists exists, backup symlink
|
// if a previous index file already exists exists, backup symlink
|
||||||
if exists, _ = file.parent.publishedStorage.FileExists(filepath.Join(dst, indexfile)); exists {
|
indexPath := filepath.Join(dst, indexfile)
|
||||||
|
oldIndexPath := filepath.Join(dst, indexfile+".old")
|
||||||
|
if exists, _ = file.parent.publishedStorage.FileExists(indexPath); exists {
|
||||||
// if exists, remove old symlink
|
// if exists, remove old symlink
|
||||||
if exists, _ = file.parent.publishedStorage.FileExists(filepath.Join(dst, indexfile+".old")); exists {
|
if exists, _ = file.parent.publishedStorage.FileExists(oldIndexPath); exists {
|
||||||
var link string
|
var linkTarget string
|
||||||
link, err = file.parent.publishedStorage.ReadLink(filepath.Join(dst, indexfile+".old"))
|
linkTarget, err = file.parent.publishedStorage.ReadLink(oldIndexPath)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
file.parent.publishedStorage.Remove(link)
|
// If we managed to resolve the link target: delete it. This is the
|
||||||
|
// oldest physical index file we no longer need. Once we drop our
|
||||||
|
// old symlink we'll essentially forget about it existing at all.
|
||||||
|
file.parent.publishedStorage.Remove(linkTarget)
|
||||||
}
|
}
|
||||||
file.parent.publishedStorage.Remove(filepath.Join(dst, indexfile+".old"))
|
file.parent.publishedStorage.Remove(oldIndexPath)
|
||||||
}
|
}
|
||||||
file.parent.publishedStorage.RenameFile(filepath.Join(dst, indexfile),
|
file.parent.publishedStorage.RenameFile(indexPath, oldIndexPath)
|
||||||
filepath.Join(dst, indexfile+".old"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create symlink
|
// create symlink
|
||||||
|
|||||||
+7
-2
@@ -267,7 +267,12 @@ func (storage *PublishedStorage) FileExists(path string) (bool, error) {
|
|||||||
return true, nil
|
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) {
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,10 @@ func (s *PublishedStorageSuite) TestSymLink(c *C) {
|
|||||||
|
|
||||||
exists, _ := s.storage.FileExists("ppa/dists/squeeze/InRelease")
|
exists, _ := s.storage.FileExists("ppa/dists/squeeze/InRelease")
|
||||||
c.Check(exists, Equals, true)
|
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) {
|
func (s *PublishedStorageSuite) TestHardLink(c *C) {
|
||||||
|
|||||||
Reference in New Issue
Block a user