Closed Bug 1601904 Opened 4 years ago Closed 3 years ago

'Clear Downloads' button deletes files being currently downloaded

Categories

(Toolkit :: Downloads API, defect, P2)

71 Branch
defect

Tracking

()

RESOLVED FIXED
90 Branch
Tracking Status
firefox-esr78 --- wontfix
firefox88 --- wontfix
firefox89 --- wontfix
firefox90 --- fixed

People

(Reporter: u652520, Assigned: ava8katushka)

References

(Blocks 1 open bug)

Details

(Keywords: dataloss)

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0

Steps to reproduce:

  1. Start downloading a file (a big one so there is a time to reproduce a defect)
  2. Let's assume the download process has been interrupted for some reason (to simulate that e.g. unplug an internet cable or turn WiFi off for a while)
  3. In Download manager the file is being listed with 'Failed' status
  4. Re-plug internet cable or turn the WiFi on
  5. Let's assume we cannot restart download for some reason (for example the server doesn't support that etc.)
  6. Try to start downloading the file again, from the beginning
  7. We get the warning the file already exists. We override it.
  8. The new instance of the same file is being downloaded
  9. In download manager we have 2 items - an old, failed one, and a new - currently being downloaded.
  10. We click 'Clear Downloads' button

Actual results:

The old download (a failed one) is removed from the list, leaving the one being currently download. That's the good thing. However, while removing a failed item form the list, the file(s) itself is being removed from the filesystem (both .part and a proper file). In this scenario it is not an interrupted/incomplete file anymore. Because we started a new download with the same filename the 'Clear Downloads' button deletes a file being currently downloaded. What is more disturbing the progress bar is still up and running giving the impression as if the file was still being downloaded (which is not).

Expected results:

The 'Clear Downloads' button should verify, before deleting any files, if there are other files with the same names currently being downloaded.

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Downloads API
Product: Firefox → Toolkit
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: dataloss
Priority: -- → P2
Assignee: nobody → ava8katushka
Status: NEW → ASSIGNED

I was able to reproduce it. I used this big audio file for the test: https://hpmorpodcast.com/wp-content/uploads/episodes/HPMoR_Full.mp3

Thanks Ava!

So it seems like the problem here is that our failed downloaded file and the new one are pointing at the same target path on the filesystem and when we clear the downloads, the code ends up cleaning up the file the failed download is associated with. I believe we're starting this process around https://searchfox.org/mozilla-central/rev/9b430bb1a11d7152cab2af4574f451ffb906b052/toolkit/components/downloads/DownloadList.jsm#195-233.

So I think what we'd like to see is to somehow track which files we currently have downloading and only clean up the ones they aren't associated with when the "Clear downloads" button is pressed. However I wasn't able to find where we're directly cleaning up downloaded files on disk yet. Gijs, perhaps you might know where this is happening?

Flags: needinfo?(gijskruitbosch+bugs)

https://searchfox.org/mozilla-central/rev/9b430bb1a11d7152cab2af4574f451ffb906b052/toolkit/components/downloads/DownloadList.jsm#209-232
download.finalize() often is where files are removed.
Using the list it should be possible to mark "duplicates" and avoid removing partial data of a non finished download when finalizing a finished download.

Flags: needinfo?(gijskruitbosch+bugs)
Pushed by mtigley@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/0cb172fb490e
Keep the downloading file while clearing the downloads. r=mtigley
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 90 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: