Closed Bug 924874 Opened 11 years ago Closed 11 years ago

[OS.File] Provide alternative to nsIFile.diskSpaceAvailable

Categories

(Toolkit Graveyard :: OS.File, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla30

People

(Reporter: nmaier, Assigned: Dexter)

References

Details

(Keywords: dev-doc-needed, Whiteboard: [Async:ready][mentor=Yoric][lang=js][lang=c++][mentored but not an easy bug])

Attachments

(1 file, 6 obsolete files)

http://mxr.mozilla.org/mozilla-central/source/xpcom/io/nsIFile.idl#398 Right now, there does not seem to be any way to query the free diskspace with OS.File.
Indeed, there is no way at the moment. I don't have time to add this right now, but if you are interested in working on that bug, I'm quite willing to mentor/review.
Whiteboard: [Async][mentor=Yoric][lang=js][lang=c++][mentored but not an easy bug]
Assignee: nobody → alessio.placitelli
Attached patch OSFile_FreeSpace.patch (obsolete) — Splinter Review
I've added the OS.File.getAvailableFreeSpace function which allows to query the amount of free space, in bytes, for the current user. It works on Windows, but I'm not sure about the Linux/Unix part, since I don't have access to a Linux machine at the moment.
Attachment #8360302 - Flags: review?(dteller)
Thanks. I'll try and look at it this week, but I'm currently quite busy, so I make no promise. You'll find the results of the tests here: https://tbpl.mozilla.org/?tree=Try&rev=f9854b1a3697
Whiteboard: [Async][mentor=Yoric][lang=js][lang=c++][mentored but not an easy bug] → [Async:ready][mentor=Yoric][lang=js][lang=c++][mentored but not an easy bug]
Attached patch OSFile_FreeSpace.patch (obsolete) — Splinter Review
Thank you for uploading to the try server. Based on the results I was able to fix the Linux part. It should be correctly working with this patch.
Attachment #8360302 - Attachment is obsolete: true
Attachment #8360302 - Flags: review?(dteller)
Attachment #8361075 - Flags: review?(dteller)
Comment on attachment 8361075 [details] [diff] [review] OSFile_FreeSpace.patch Review of attachment 8361075 [details] [diff] [review]: ----------------------------------------------------------------- Looks good. I'm not adding r+ yet, because I want tests. ::: toolkit/components/osfile/modules/osfile_async_front.jsm @@ +723,5 @@ > + * @return {number} The number of bytes available for the current user. > + * @throws {OS.File.Error} In case of any error. > + */ > +File.getAvailableFreeSpace = function getAvailableFreeSpace(sourcePath) { > + return Scheduler.post("getAvailableFreeSpace", Nit: Please remove that trailing whitespace. ::: toolkit/components/osfile/modules/osfile_unix_back.jsm @@ +217,5 @@ > Type.timevals = new SharedAll.Type("two timevals", > ctypes.ArrayType(Type.timeval.implementation, 2)); > } > > + Nit: Unnecessary whitespace. @@ +220,5 @@ > > + > + // Type fsblkcnt_t, used by structure |STATVFS| > + Type.fsblkcnt_t = > + Type.unsigned_long.withName("fsblkcnt_t"); Are you sure it's an unsigned long on all platforms? @@ +221,5 @@ > + > + // Type fsblkcnt_t, used by structure |STATVFS| > + Type.fsblkcnt_t = > + Type.unsigned_long.withName("fsblkcnt_t"); > + Nit: Unncessary whitespace. @@ +223,5 @@ > + Type.fsblkcnt_t = > + Type.unsigned_long.withName("fsblkcnt_t"); > + > + // Structure |STATVFS| > + Type.STATVFS = Why uppercase? It's lowercase in Posix, so let's keep it lowercase here. @@ +238,5 @@ > + { f_fsid: Type.unsigned_long.implementation }, > + { f_flag: Type.unsigned_long.implementation }, > + { f_namemax: Type.unsigned_long.implementation } > + ])); > + Nit: Whitespace. @@ +495,5 @@ > > + declareLazyFFI(SysFile, "statvfs", libc, "statvfs", ctypes.default_abi, > + /*return*/ Type.negativeone_or_nothing, > + /*path*/ Type.path, > + /*off_in*/ Type.STATVFS.out_ptr); According to the manpage, this shouldn't be called off_in but buf. Nit: Whitespace. ::: toolkit/components/osfile/modules/osfile_unix_front.jsm @@ +362,5 @@ > + */ > + File.getAvailableFreeSpace = function Unix_getAvailableFreeSpace(sourcePath) { > + let fileSystemInfo = new Type.STATVFS.implementation(); > + let fileSystemInfoPtr = fileSystemInfo.address(); > + Nit: whitespace (hint: look at the review link, they'll be clearly visible). ::: toolkit/components/osfile/modules/osfile_win_back.jsm @@ +280,5 @@ > + /*directoryName*/ Type.path, > + /*freeBytesForUser*/ Type.uint64_t.out_ptr, > + /*totalBytesForUser*/ Type.uint64_t.out_ptr, > + /*freeTotalBytesOnDrive*/ Type.uint64_t.out_ptr); > + Nit: whitespace.
Attachment #8361075 - Flags: review?(dteller) → feedback+
Thank you for the time you spend reviewing my submission! I'll submit an updated patch with proper tests later this evening. I just have one (probably naive) question: how can I check if fsblkcnt_t is not unsigned long on other platforms?
Flags: needinfo?(dteller)
(In reply to Alessio Placitelli from comment #6) > Thank you for the time you spend reviewing my submission! I'll submit an > updated patch with proper tests later this evening. > > I just have one (probably naive) question: how can I check if fsblkcnt_t is > not unsigned long on other platforms? Good question. We don't have a good mechanism for this, so I'd just check the documentation of Linux and MacOS X, and some other BSD.
Flags: needinfo?(dteller)
(In reply to David Rajchenbach Teller [:Yoric] (please use "needinfo?") from comment #7) > (In reply to Alessio Placitelli from comment #6) > > I just have one (probably naive) question: how can I check if fsblkcnt_t is > > not unsigned long on other platforms? > > Good question. We don't have a good mechanism for this, so I'd just check > the documentation of Linux and MacOS X, and some other BSD. Actually, I am misleading you. You should look at how we define mode_t in OS.File: - native code is here: http://dxr.mozilla.org/mozilla-central/source/dom/system/OSFileConstants.cpp?from=OSFileConstants.cpp#517 - JS code is here: http://dxr.mozilla.org/mozilla-central/source/toolkit/components/osfile/modules/osfile_unix_back.jsm?from=osfile_unix_back.jsm#88
(In reply to David Rajchenbach Teller [:Yoric] (please use "needinfo?") from comment #8) > (In reply to David Rajchenbach Teller [:Yoric] (please use "needinfo?") from > comment #7) > > (In reply to Alessio Placitelli from comment #6) > > > I just have one (probably naive) question: how can I check if fsblkcnt_t is > > > not unsigned long on other platforms? > > > > Good question. We don't have a good mechanism for this, so I'd just check > > the documentation of Linux and MacOS X, and some other BSD. > > Actually, I am misleading you. You should look at how we define mode_t in > OS.File: > - native code is here: > http://dxr.mozilla.org/mozilla-central/source/dom/system/OSFileConstants. > cpp?from=OSFileConstants.cpp#517 > - JS code is here: > http://dxr.mozilla.org/mozilla-central/source/toolkit/components/osfile/ > modules/osfile_unix_back.jsm?from=osfile_unix_back.jsm#88 Thanks, this comment saved the day! I'll complete the patch and send it back ASAP.
Attached patch OSFile_FreeSpace.patch (obsolete) — Splinter Review
I've also provided an xpcshell test which checks for the available space function to return a value greater than 0.
Attachment #8361075 - Attachment is obsolete: true
Attachment #8365548 - Flags: review?(dteller)
Attached patch OSFile_FreeSpace.patch (obsolete) — Splinter Review
Attachment #8365548 - Attachment is obsolete: true
Attachment #8365548 - Flags: review?(dteller)
Attachment #8365550 - Flags: review?(dteller)
Comment on attachment 8365550 [details] [diff] [review] OSFile_FreeSpace.patch Review of attachment 8365550 [details] [diff] [review]: ----------------------------------------------------------------- Looks good to me, thanks for the patch. Try: https://tbpl.mozilla.org/?tree=Try&rev=70231f3e9925 ::: toolkit/components/osfile/tests/xpcshell/test_available_free_space.js @@ +33,5 @@ > + // Query for available bytes for user > + let availableBytes = yield OS.File.getAvailableFreeSpace(dir); > + > + do_check_true(!!availableBytes); > + do_check_true(availableBytes > 0); Given that tests are executed currently, we probably can't do better. It's sad.
Attachment #8365550 - Flags: review?(dteller) → review+
Thank you for your time reviewing the patch: I've just noticed that on the Tryserver tests fail on Linux Debug and Linux x64 Debug. Also the build is busted on some B2G builds, but I can't seem to get a hang on what's wrong. Any clue?
Flags: needinfo?(dteller)
For the B2G build, I suspect that it's not your fault. For the other builds, I assume that some value doesn't have the right size. Here are a few suggestions: - since you're really using only f_bfree and f_bsize, let's make the struct a HollowStruct (see |struct dirent|, for example); - we actually have a reference implementation of checking out free disk space with nsIFile.diskSpaceAvailable, you should use both of them and check that they have approximately the same result (I say approximately because stuff may happen while we're running the tests).
Flags: needinfo?(dteller)
That's weird. I've compiled a Linux debug build locally and everything went smoothly.
Flags: needinfo?(dteller)
(In reply to Alessio Placitelli from comment #15) > That's weird. I've compiled a Linux debug build locally and everything went > smoothly. No better idea, sorry.
Flags: needinfo?(dteller)
Any progress?
Flags: needinfo?(alessio.placitelli)
Attached patch OSFile_FreeSpace.patch (obsolete) — Splinter Review
This patch uses hollow structures and fixes the tests problems I had with the previous patch. It took me a little bit to figure out how to fix the B2G and Android builds, sorry for the delay! I've uploaded it to the tryserv and the results are available here: https://tbpl.mozilla.org/?tree=Try&rev=d191223db9f6
Attachment #8365550 - Attachment is obsolete: true
Attachment #8372982 - Flags: review?(dteller)
Flags: needinfo?(alessio.placitelli)
Attached patch OSFile_FreeSpace.patch (obsolete) — Splinter Review
Attachment #8372982 - Attachment is obsolete: true
Attachment #8372982 - Flags: review?(dteller)
Attachment #8372984 - Flags: review?(dteller)
Comment on attachment 8372984 [details] [diff] [review] OSFile_FreeSpace.patch Review of attachment 8372984 [details] [diff] [review]: ----------------------------------------------------------------- Looks good, thank you for the patch. ::: toolkit/components/osfile/modules/osfile_async_front.jsm @@ +786,5 @@ > > /** > + * Gets the number of bytes available on disk to the current user. > + * > + * @param {string} sourcePath The platform-specific path on the disk to query « Platform-specific path to a directory on the disk to query for free available bytes. »
Attachment #8372984 - Flags: review?(dteller) → review+
Awesome, thank you for your time reviewing!
Attachment #8372984 - Attachment is obsolete: true
Keywords: checkin-needed
Flags: in-testsuite+
Keywords: checkin-needed
Whiteboard: [Async:ready][mentor=Yoric][lang=js][lang=c++][mentored but not an easy bug] → [Async:ready][mentor=Yoric][lang=js][lang=c++][mentored but not an easy bug][fixed-in-fx-team]
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Whiteboard: [Async:ready][mentor=Yoric][lang=js][lang=c++][mentored but not an easy bug][fixed-in-fx-team] → [Async:ready][mentor=Yoric][lang=js][lang=c++][mentored but not an easy bug]
Target Milestone: --- → mozilla30
Depends on: 981348
Product: Toolkit → Toolkit Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: