Closed Bug 1140130 Opened 9 years ago Closed 9 years ago

[mozinstall] Keyboard interrupt during installation should cause already installed files to be removed

Categories

(Testing :: Mozbase, defect)

defect
Not set
normal

Tracking

(firefox41 fixed)

RESOLVED FIXED
mozilla41
Tracking Status
firefox41 --- fixed

People

(Reporter: whimboo, Assigned: parkouss)

Details

Attachments

(1 file, 1 obsolete file)

Hit this by accident today. When a keyboard interrupt is raised by e.g. pressing ctrl-c during an installation, the exception is not handled and the already copied files remain on disk.

Given that any aborted installation will be broken, mozinstall should remove the already installed files.

Not sure how the Windows Installer is handling that. It might do the cleanup itself.
It pass the unit tests with success locally.
Assignee: nobody → j.parkouss
Status: NEW → ASSIGNED
Attachment #8576623 - Flags: review?(hskupin)
Comment on attachment 8576623 [details] [diff] [review]
Exception during installation should cause already installed files to be removed

Review of attachment 8576623 [details] [diff] [review]:
-----------------------------------------------------------------

Julian, thanks for the patch. Please see my comment what may need an update. Also I would prefer if you could add an additional person for review. I would like to have a second pair of eyes on it. Maybe you can ask Andrew.

::: testing/mozbase/mozinstall/mozinstall/mozinstall.py
@@ +127,5 @@
> +            # try to uninstall this properly
> +            uninstall(dest)
> +        except:
> +            # uninstall may fail, so let's just clean the folder in this case
> +            mozfile.remove(dest)

I think that we should better use the already existent uninstall() method, and not re-implement everything here.
Attachment #8576623 - Flags: review?(hskupin) → review-
Comment on attachment 8576623 [details] [diff] [review]
Exception during installation should cause already installed files to be removed

So as discussed on irc, the call to uninstall is done. (this is also visible in the last comment). The thing is that looking at the uninstall code, it can fail and not remove the install dir in that case.

So the logic is:

1. call uninstall
2. if that fails, call mozfile.remove

:ahal, what do you think of this patch ?
Attachment #8576623 - Flags: review- → review?(ahalberstadt)
Comment on attachment 8576623 [details] [diff] [review]
Exception during installation should cause already installed files to be removed

Review of attachment 8576623 [details] [diff] [review]:
-----------------------------------------------------------------

I see we already call mozfile.remove(dest) in the uninstall method, so this patch isn't the problem, but if dest already exists this could cause data loss! I think we should only remove dest if we created it in the first place here:
https://dxr.mozilla.org/mozilla-central/source/testing/mozbase/mozinstall/mozinstall/mozinstall.py#108

If it already existed, we should either just leave it be, or at least be semi-smart and only remove files we think we created. We could even get a list of files before and after, and only remove the difference. It's a little unfair to r-, but I think the potential for data loss is serious enough that we should fix it at the same time.
Attachment #8576623 - Flags: review?(ahalberstadt) → review-
Ok I undesrtand the point. Reading at the install dest documentation, I thought that
it was OK to remove it, because there is a warning:

:param dest: Path to install to (to ensure we do not overwrite any existent
                  files the folder should not exist yet)

And I added in this documentation:

+    Note that in case of an exception during install, *dest* will be removed.

But yes, this is quite a possible loss if the function is already used
somewhere with a non-empty dest dir (and that the files in there are important).

I like the idea of uninstalling if we had an empty dest dir, and I can adapt
the patch for it. I wonder if supporting non empty dest dir is a good thing
at all (and if that could be changed ?).
Flags: needinfo?(ahalberstadt)
Yeah, I saw that message too, but I doubt most people will read the docs until it is too late. This is just one angry "I just deleted my homedir!" away from being our top priority.

Another alternative is to create a new folder in 'dest' and put everything in there, e.g:
path/to/dest/mozinstall-<app>

Actually, probably the best solution is to create a manifest of the files and only uninstall the files found in that manifest, e.g:
path/to/dest/.mozinstall

That way we can be sure never to lose data, even if the user calls "uninstall" at a later time. I guess these solutions are getting more and more complicated. For now I'd just focus on the case where install fails, set a flag if we created 'dest' and don't delete it if we didn't.

I'll file a separate bug for the manifest idea.
Flags: needinfo?(ahalberstadt)
Filed bug 1164443 for fixing the general uninstall case.
Ok,new attempt here - the dest dir is only removed if we created it.
Attachment #8576623 - Attachment is obsolete: true
Attachment #8606393 - Flags: review?(ahalberstadt)
Comment on attachment 8606393 [details] [diff] [review]
Exception during installation should cause already installed files to be removed

Review of attachment 8606393 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks, looks great! This can potentially leave files behind, but imo that's better than potentially deleting unrelated files. I don't think this will have much of an impact on our systems.
Attachment #8606393 - Flags: review?(ahalberstadt) → review+
Seems all good. :)
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/a7a14d34d112
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla41
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: