mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-20 19:38:39 +00:00
fix a serious file leak in the by-index publishing
the logic here was wrong.
if we managed to find the link target (the physical index file) pointed to
by our old symlink we want to remove it (this is basically "cleaning up old
index" logic).
previously we'd try to only delete it when the ReadLink came back with
error. which had two serious issues with it:
a) linkTarget was empty, so we basically called Remove("") which would
delete the storage -> root <- directory if the root is a symlink!
b) we'd leak old indexes as the cleanup logic only ran if there was en
error which would ordinarily never be
new code correctly cleans up unless there was an error.
this relates to a previous bugfix of readLink which incorrectly returned
absolute paths ultimately rendering the Remove call also broken.
This commit is contained in:
@@ -198,7 +198,10 @@ func packageIndexByHash(file *indexFile, ext string, hash string, sum string) er
|
||||
if exists, _ = file.parent.publishedStorage.FileExists(oldIndexPath); exists {
|
||||
var linkTarget string
|
||||
linkTarget, err = file.parent.publishedStorage.ReadLink(oldIndexPath)
|
||||
if err != nil {
|
||||
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(oldIndexPath)
|
||||
|
||||
Reference in New Issue
Block a user