Closed Bug 1237576 Opened 5 years ago Closed 5 years ago

DownloadContentService: canWrite() and hasEnoughDiskSpace() can erroneously return false

Categories

(Firefox for Android :: General, defect)

All
Android
defect
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 46
Tracking Status
firefox46 --- fixed

People

(Reporter: sebastian, Assigned: sebastian)

References

Details

Attachments

(2 files)

On Android 6 with targetSdkVersion=23 and without storage permission canWrite() and hasEnoughDiskSpace() return false (temporaryFile and destinationFile).

Both files are stored in the application specific temporary and data directories. Those directories are writable without a permission. Nevertheless File.canWrite() and getUsableSpace() return values as if we do not have the needed permissions.
This seems to be actually independent from the permission:
* File.canWrite() returns false if the file does not exist (even though we /could/ write to this destination)
* hasEnoughDiskSpace() returns 0 for a directory that does not exist yet
No longer blocks: 1216537
Summary: DLC: Without storage permission canWrite() and hasEnoughDiskSpace() returns false → DownloadContentService: canWrite() and hasEnoughDiskSpace() can erroneously return false
Assignee: nobody → s.kaspari
Status: NEW → ASSIGNED
Duplicate of this bug: 1236907
We can't use File.canWrite() on files that do not exist yet. After all we are
going to create the file in a folder that we just created. So it is very
unlikely that writing to that folder is going to fail.

Review commit: https://reviewboard.mozilla.org/r/30357/diff/#index_header
See other reviews: https://reviewboard.mozilla.org/r/30357/
Attachment #8706495 - Flags: review?(rnewman)
> * hasEnoughDiskSpace() returns 0 for a directory that does not exist yet

If needed the directory is now created.

> * File.canWrite() returns false if the file does not exist (even though we
> /could/ write to this destination)

I removed this from the code: The only safe way to tell if the file is writable is to create it. But I do not want to create empty files or create and delete them. And as we are now creating the folder first: It's unlikely that we can't create a file in the folder we just created.
Comment on attachment 8706493 [details]
MozReview Request: Bug 1237576 - DownloadAction.getDestinationFile(): Create directory if needed. r?rnewman

https://reviewboard.mozilla.org/r/30355/#review27081
Attachment #8706493 - Flags: review?(rnewman) → review+
Comment on attachment 8706495 [details]
MozReview Request: Bug 1237576 - DownloadAction: Remove canWrite() check. r?rnewman

https://reviewboard.mozilla.org/r/30357/#review27079
Attachment #8706495 - Flags: review?(rnewman) → review+
https://hg.mozilla.org/mozilla-central/rev/c49219ebe247
https://hg.mozilla.org/mozilla-central/rev/35c1ed58949d
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 46
You need to log in before you can comment on or make changes to this bug.