mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +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:
@@ -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 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, _ = file.parent.publishedStorage.FileExists(filepath.Join(dst, indexfile+".old")); exists {
|
||||
var link string
|
||||
link, err = file.parent.publishedStorage.ReadLink(filepath.Join(dst, indexfile+".old"))
|
||||
if err != nil {
|
||||
file.parent.publishedStorage.Remove(link)
|
||||
if exists, _ = file.parent.publishedStorage.FileExists(oldIndexPath); exists {
|
||||
var linkTarget string
|
||||
linkTarget, err = file.parent.publishedStorage.ReadLink(oldIndexPath)
|
||||
if err == nil {
|
||||
// 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),
|
||||
filepath.Join(dst, indexfile+".old"))
|
||||
file.parent.publishedStorage.RenameFile(indexPath, oldIndexPath)
|
||||
}
|
||||
|
||||
// create symlink
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user