Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix by by-hash index cleanup + root dir data "loss" #706

Merged
merged 3 commits into from
Feb 22, 2018

Conversation

hsitter
Copy link
Contributor

@hsitter hsitter commented Feb 19, 2018

Requirements

All new code should be covered with tests, documentation should be updated. CI should pass.

Description of the Change

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.

readlink was also entirely wrong and adjusted to work correctly within the expectations of a publishedstorage

(I presently don't have time to poke around to make the functional test assert that the cleanup works, not sure we really need to care all that much either... I'll probably not get to it this week but this bug is fairly serious as it basically blew up our aptly earlier today)

This also relates to #705 which introduces a guard against part of the underlying problem here (Remove being content with using an empty path)

Checklist

  • unit-test added (if change is algorithm)
  • functional test added/updated (if change is functional)

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
by using the power of variables!
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.
Copy link
Contributor

@smira smira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@smira smira merged commit 02ac416 into aptly-dev:master Feb 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants