Closed
Bug 802534
Opened 12 years ago
Closed 12 years ago
[OS.File] Main thread versions of OS.File.Info and OS.File.DirectoryIterator.Entry should have nice prototypes
Categories
(Toolkit Graveyard :: OS.File, defect)
Toolkit Graveyard
OS.File
Tracking
(Not tracked)
RESOLVED
FIXED
mozilla21
People
(Reporter: Yoric, Assigned: eduardn)
References
Details
(Keywords: dev-doc-needed, Whiteboard: [mentor=Yoric][lang=js])
Attachments
(1 file, 6 obsolete files)
(deleted),
patch
|
Yoric
:
review+
|
Details | Diff | Splinter Review |
On worker threads, we can perform feature detection on OS.File.Info/OS.File.DirectoryIterator.Entry as follows:
if ("unixGroup" in OS.File.Info.prototype) {
// OS.File.Info can be used to determine the Unix group of a file
} else {
// Do something else
}
On the main thread, this is not possible yet.
We should do the following:
- in osfile_{win,unix}_allthreads.jsm: define OS.File.AbstractInfo with a prototype that declares placeholders for the fields of OS.File.Info;
- in osfile_{win,unix}_front.jsm: ensure that OS.File.Info inherits OS.File.AbstractInfo;
- in osfile_abstract_front.jsm: ensure that OS.File.Info inherits OS.File.AbstractInfo.
+ the same thing for OS.File.DirectoryIterator.Entry
Assignee | ||
Comment 1•12 years ago
|
||
I would like to work on this bug. Can it be assigned to me?
Assignee | ||
Comment 3•12 years ago
|
||
Hi! Sorry for the delay.
I made a first modification to |osfile_win_allthreads| and |osfile_win_front| but I want to know if my approach is good. Please provide feedback to know if I should continue along this path.
Thanks!
Attachment #689133 -
Flags: feedback?(dteller)
Assignee | ||
Updated•12 years ago
|
Attachment #689133 -
Attachment is patch: true
Reporter | ||
Comment 4•12 years ago
|
||
Comment on attachment 689133 [details] [diff] [review]
Rough Patch
Review of attachment 689133 [details] [diff] [review]:
-----------------------------------------------------------------
I don't think that this will work. Your constructor |AbstractInfo| and its prototype require a |stat| containing native js-ctypes data structures. Unfortunately, these data structures cannot be transmitted across threads, so |AbstractInfo| cannot be used by osfile_async_front.jsm.
I can see two ways to do this.
Solution 1:
- have |AbstractInfo| be a very dumb constructor that does nothing interesting;
- attach to |AbstractInfo.prototype| very dumb versions of |isDir|, |isSymlink| that throw if they are called;
- keep the real implementation of |isDir|, |isSymlink|, etc. with |Info|
Solution 2:
- have |AbstractInfo| be a not quite so dumb constructor that takes as arguments |isDir|, |isSymlink|, etc. and stores them as |_isDir|, |_isSymlink|, etc.;
- attach to |AbstractInfo.prototype| very dumb versions of |isDir|, |isSymlink| that simply return |this._isDir|, |this._isSymlink|, etc.
- rework constructor |Info| to compute the values of |isDir|, etc. and pass them to |AbstractInfo|.
Solution 2 is probably best.
Attachment #689133 -
Flags: feedback?(dteller)
Assignee | ||
Comment 5•12 years ago
|
||
I applied your feedback but I'm still not sure if I am doing the right thing. I still have a couple of questions.
1. in some of the |gets| there is a call to |Object.defineProperty|. Should I keep that in |AbstractInfo|
2. Where should I create a test to see if the code has the expected behavior.
With the current code (from patch) all the tests pass.
Attachment #689133 -
Attachment is obsolete: true
Attachment #689695 -
Flags: feedback?(dteller)
Reporter | ||
Comment 6•12 years ago
|
||
Comment on attachment 689695 [details] [diff] [review]
Rough Patch (v2)
Review of attachment 689695 [details] [diff] [review]:
-----------------------------------------------------------------
That looks good.
> 1. in some of the |gets| there is a call to |Object.defineProperty|. Should I keep that in |AbstractInfo|
Indeed, the calls to |Object.defineProperty| do not match this new design, you were right to remove them. They were used to perform lazy conversion of data from native to JavaScript, but this was most likely overkill. We will reintroduce them later, in another bug, if experience shows that it can optimize uses of OS.File.
> 2. Where should I create a test to see if the code has the expected behavior.
A good place for testing would be main_osfile_async.js. You can check, for instance, that under Unix, ("unixGroup" in OS.File.Info.prototype). To determine whether we are under Unix, check whether OS.Constants.Win is defined.
Attachment #689695 -
Flags: feedback?(dteller) → feedback+
Assignee | ||
Comment 7•12 years ago
|
||
I made all the necessary modifications (tested on windows). If everything is ok, could you please run the patch on the try server?
Attachment #689695 -
Attachment is obsolete: true
Attachment #690107 -
Flags: review?(dteller)
Reporter | ||
Comment 8•12 years ago
|
||
Comment on attachment 690107 [details] [diff] [review]
First patch
Review of attachment 690107 [details] [diff] [review]:
-----------------------------------------------------------------
Looks good, with the few changes detailed below. Let's test it.
::: toolkit/components/osfile/osfile_async_front.jsm
@@ +688,5 @@
> + File.Info.prototype = Object.create(OS.Shared.Win.AbstractInfo.prototype);
> +} else if (OS.Constants.libc) {
> + File.Info.prototype = Object.create(OS.Shared.Unix.AbstractInfo.prototype);
> +} else {
> + throw new Error("I am neither under Windows nor under a Posix system");
In practice |OS.Constants.libc| is always defined, since libc is available on all systems, so the second |if| doesn't add any information.
::: toolkit/components/osfile/osfile_unix_allthreads.jsm
@@ +162,5 @@
>
> + /**
> + * Code shared by implementations of File.Info on Unix
> + *
> + */
Nit: whitespace.
::: toolkit/components/osfile/osfile_unix_front.jsm
@@ +701,4 @@
> let gStatDataPtr = gStatData.address();
> let MODE_MASK = 4095 /*= 07777*/;
> File.Info = function Info(stat) {
> + let isDir = (stat.st_mode & OS.Const.libc.S_IFMT) == OS.Constants.libc.S_IFDIR;
|OS.Const|? This probably doesn't work.
@@ +707,5 @@
> +
> + let lastAccessDate = new Date(stat.st_atime * 1000);
> + let lastModificationDate = new Date(stat.st_mtime * 1000);
> + let unixLastStatusChangeDate = new Date(stat.st_ctime * 1000);
> +
Nit: Whitespace
::: toolkit/components/osfile/osfile_win_front.jsm
@@ +660,5 @@
> */
> File.Info = function Info(stat) {
> + let isDir = !!(stat.dwFileAttributes & Const.FILE_ATTRIBUTE_DIRECTORY);
> + let isSymLink = !!(stat.dwFileAttributes & Const.FILE_ATTRIBUTE_REPARSE_POINT);
> +
Nit: Whitespace.
Attachment #690107 -
Flags: review?(dteller) → review+
Reporter | ||
Comment 9•12 years ago
|
||
(In reply to David Rajchenbach Teller [:Yoric] from comment #8)
> Comment on attachment 690107 [details] [diff] [review]
> First patch
>
> Review of attachment 690107 [details] [diff] [review]:
> -----------------------------------------------------------------
>
> Looks good, with the few changes detailed below. Let's test it.
>
> ::: toolkit/components/osfile/osfile_async_front.jsm
> @@ +688,5 @@
> > + File.Info.prototype = Object.create(OS.Shared.Win.AbstractInfo.prototype);
> > +} else if (OS.Constants.libc) {
> > + File.Info.prototype = Object.create(OS.Shared.Unix.AbstractInfo.prototype);
> > +} else {
> > + throw new Error("I am neither under Windows nor under a Posix system");
>
> In practice |OS.Constants.libc| is always defined, since libc is available
> on all systems, so the second |if| doesn't add any information.
>
Let me guess. That's copied and pasted from my code, isn't it? In that case, forget about my comment on these lines :)
Reporter | ||
Comment 10•12 years ago
|
||
Try: https://tbpl.mozilla.org/?tree=Try&rev=7a3a8e440829
By the way, please don't forget to add « ;r=yoric » at the end of your commit message.
Assignee | ||
Comment 11•12 years ago
|
||
> (In reply to David Rajchenbach Teller [:Yoric] from comment #8)
> > Comment on attachment 690107 [details] [diff] [review]
> > First patch
> >
> > Review of attachment 690107 [details] [diff] [review]:
> > -----------------------------------------------------------------
> >
> > Looks good, with the few changes detailed below. Let's test it.
> >
> > ::: toolkit/components/osfile/osfile_async_front.jsm
> > @@ +688,5 @@
> > > + File.Info.prototype = Object.create(OS.Shared.Win.AbstractInfo.prototype);
> > > +} else if (OS.Constants.libc) {
> > > + File.Info.prototype = Object.create(OS.Shared.Unix.AbstractInfo.prototype);
> > > +} else {
> > > + throw new Error("I am neither under Windows nor under a Posix system");
> >
> > In practice |OS.Constants.libc| is always defined, since libc is available
> > on all systems, so the second |if| doesn't add any information.
> >
>
> Let me guess. That's copied and pasted from my code, isn't it? In that case,
> forget about my comment on these lines :)
Ummm...yes :)
(In reply to David Rajchenbach Teller [:Yoric] from comment #10)
> Try: https://tbpl.mozilla.org/?tree=Try&rev=7a3a8e440829
>
> By the way, please don't forget to add « ;r=yoric » at the end of your
> commit message.
Ok.
I will do those modifications after I investigate the problem on Unix, as the tests seem to fail. Any idea?
Reporter | ||
Comment 12•12 years ago
|
||
Let me relaunch the tests in a more verbose mode: https://tbpl.mozilla.org/?tree=Try&rev=ba4d21a9a5e7
Assignee | ||
Comment 13•12 years ago
|
||
Found the error! I was passing an undefined |creationDate| to the |AbstractInfo| constructor which, by the way, I wasn't even using. Is it ok to keep the implementation of |creationDate| and |macBirthDate| on the |File.Info| side?
Attachment #690107 -
Attachment is obsolete: true
Attachment #691732 -
Flags: review?(dteller)
Assignee | ||
Comment 14•12 years ago
|
||
Resolved all errors. Everything is green on Linux: https://tbpl.mozilla.org/?tree=Try&rev=1fd79cba8213
Attachment #691732 -
Attachment is obsolete: true
Attachment #691732 -
Flags: review?(dteller)
Attachment #692768 -
Flags: review?(dteller)
Reporter | ||
Comment 15•12 years ago
|
||
Comment on attachment 692768 [details] [diff] [review]
bug-802534-fix
Review of attachment 692768 [details] [diff] [review]:
-----------------------------------------------------------------
Looks good, with the following minor changes.
::: toolkit/components/osfile/osfile_unix_front.jsm
@@ +707,5 @@
> +
> + let lastAccessDate = new Date(stat.st_atime * 1000);
> + let lastModificationDate = new Date(stat.st_mtime * 1000);
> + let unixLastStatusChangeDate = new Date(stat.st_ctime * 1000);
> +
Nit: Please remove that tab.
@@ +716,3 @@
> // Some platforms (e.g. MacOS X, some BSDs) store a file creation date
> if ("OSFILE_OFFSETOF_STAT_ST_BIRTHTIME" in OS.Constants.libc) {
> this._st_birthtime = stat.st_birthtime;
You should rather define |this.macBirthDate = new Date(...)| here.
Attachment #692768 -
Flags: review?(dteller) → review+
Assignee | ||
Comment 17•12 years ago
|
||
Attachment #692768 -
Attachment is obsolete: true
Attachment #699900 -
Flags: review?(dteller)
Reporter | ||
Comment 18•12 years ago
|
||
Comment on attachment 699900 [details] [diff] [review]
bug-802534-fix
Review of attachment 699900 [details] [diff] [review]:
-----------------------------------------------------------------
r=me with the trivial change below, assuming that it passes tests.
::: toolkit/components/osfile/osfile_unix_front.jsm
@@ +725,5 @@
> + * information.
> + *
> + * @type {Date}
> + */
> + Object.defineProperty(this, "macBirthDate", { value: date });
You just need |this.macBirthDate = date|.
Also, I would move this after the call to |AbstractInfo|.
Attachment #699900 -
Flags: review?(dteller) → review+
Assignee | ||
Comment 19•12 years ago
|
||
Did the changes and pushed to try. Once everything is green it should be ready to land.
Try: https://tbpl.mozilla.org/?tree=Try&rev=111d9bbc22cc
Attachment #699900 -
Attachment is obsolete: true
Attachment #700257 -
Flags: review?(dteller)
Reporter | ||
Updated•12 years ago
|
Attachment #700257 -
Flags: review?(dteller) → review+
Assignee | ||
Updated•12 years ago
|
Keywords: checkin-needed,
dev-doc-needed
Comment 20•12 years ago
|
||
Try run looks good, so I pushed to inbound:
https://hg.mozilla.org/integration/mozilla-inbound/rev/fdfa7133f207
(The latest patch here had an old datestamp encoded in its headers (from mid-December), so I updated that before pushing w/ 'hg qref -D', for sanity's sake.)
Comment 21•12 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla21
Comment 22•12 years ago
|
||
Comment 23•12 years ago
|
||
Updated•2 years ago
|
Product: Toolkit → Toolkit Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•