Closed
Bug 707696
Opened 13 years ago
Closed 12 years ago
[OS.File] Path handling
Categories
(Core :: JavaScript Engine, enhancement)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla16
People
(Reporter: Yoric, Assigned: Yoric)
References
Details
Attachments
(4 files, 14 obsolete files)
(deleted),
patch
|
Yoric
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
Yoric
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
Yoric
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
Yoric
:
review+
|
Details | Diff | Splinter Review |
We need a module comparable to Python os.path.
Assignee | ||
Comment 1•13 years ago
|
||
The API. Implementation for Unix should be sufficient, implementation for Windows is incomplete. Also missing a number of well-known directories.
Attachment #581686 -
Flags: review?(dherman)
Comment 2•13 years ago
|
||
Comment on attachment 581686 [details] [diff] [review]
v1. The API
i'm not the right person to review; I'd ask one of the module owners of toolkit:
https://wiki.mozilla.org/Modules/Toolkit
Dave
Attachment #581686 -
Flags: review?(dherman)
Assignee | ||
Comment 3•12 years ago
|
||
Assignee | ||
Comment 4•12 years ago
|
||
Attachment #581686 -
Attachment is obsolete: true
Attachment #634416 -
Flags: review?
Assignee | ||
Comment 5•12 years ago
|
||
Assignee | ||
Comment 6•12 years ago
|
||
Comment on attachment 634416 [details] [diff] [review]
Unix back-end
Taras, I have found myself blocked a few times because we have no portable way to represent paths in OS.File, so I have put together a prototype implementation. Could you take a look?
This implements only the data structure. To make it useful, I intend to add a function |Path.to| that
The idea is that once we have this OS.Path to add a function |Path.to| that will hook to the DirectoryProvider through some native code.
Attachment #634416 -
Flags: review? → review?(taras.mozilla)
Comment 7•12 years ago
|
||
Comment on attachment 634416 [details] [diff] [review]
Unix back-end
I prefer the python way over OO here. See http://docs.python.org/library/os.path.html
Attachment #634416 -
Flags: review?(taras.mozilla) → review-
Assignee | ||
Comment 8•12 years ago
|
||
Attachment #634414 -
Attachment is obsolete: true
Assignee | ||
Comment 9•12 years ago
|
||
Can't sleep, so here is a revised version.
Taras, can you tell me what you think of this one? If it works for you, I will start working on the dreaded Windows implementation.
Attachment #634416 -
Attachment is obsolete: true
Attachment #634417 -
Attachment is obsolete: true
Attachment #634624 -
Flags: review?(taras.mozilla)
Comment 10•12 years ago
|
||
Comment on attachment 634624 [details] [diff] [review]
Unix back-end
i could if bugzilla dns wasn't busted :(
Assignee | ||
Comment 11•12 years ago
|
||
Assignee | ||
Comment 12•12 years ago
|
||
Ah well, still can't sleep. Here is a prototype of the Windows back-end.
I still believe that we should introduce a data structure for paths. In particular, this would let us ensure that we only |join| and |split| normalized paths, without performance penalty.
Assignee | ||
Comment 13•12 years ago
|
||
We can even combine both. Leave these back-ends with the rest of the back-ends for users who prefer working with strings, and add a thin front-end to wrap them in safer/more abstract OO code.
Assignee | ||
Updated•12 years ago
|
Assignee | ||
Comment 14•12 years ago
|
||
Of course, I forgot to mention, but the main reason to add a little abstraction on top of the API is to ensure that users concatenate paths with |join| and not manually, which is quite brittle.
Summary: Efficient JS File API - Path handling → [OS.File] Path handling
Updated•12 years ago
|
Attachment #634624 -
Flags: review?(taras.mozilla) → review+
Assignee | ||
Updated•12 years ago
|
Attachment #634694 -
Flags: review?(taras.mozilla)
Assignee | ||
Updated•12 years ago
|
Attachment #634696 -
Flags: review?(taras.mozilla)
Comment 15•12 years ago
|
||
Comment on attachment 634694 [details] [diff] [review]
Windows test suite
Really? OS.Unix.Path in the windows testsuite? This works?
Attachment #634694 -
Flags: review?(taras.mozilla) → review-
Comment 16•12 years ago
|
||
Comment on attachment 634696 [details] [diff] [review]
Windows back-end
exports.OS.Unix.Path <-- do not use Unix on a windows platform. If for whatever OS.Path sure, but not OS.lie.Path.
+ basename: function basename(path) {
+ return path.slice(Math.max(path.lastIndexOf("\\"), path.lastIndexOf(":")) + 1);
+ },
This and other path handling functions need to explicitly block paths(ie UNC ones) that start with '\\'(make a utility). Make a utility function that throws an exception if a UNC path is detected.
Otherwise you get weird string exceptions for paths without ':' in them. Should also check errors when looking for "\\" position in path strings and throw proper exceptions.
+ let noDrive = (options && options.winNoDrive);
what the heck is .winNoDrive? no docs for it.
Need to document what you are doing in join with regexps, general strategy, etc. I generally don't require comments in the body if the code is clear, it's not in this case.
Attachment #634696 -
Flags: review?(taras.mozilla) → review-
Comment 17•12 years ago
|
||
Comment on attachment 634624 [details] [diff] [review]
Unix back-end
+ return path.slice(path.lastIndexOf("/") + 1);
as in other patch, please check errors from string functions and throw appropriate exceptions.
Attachment #634624 -
Flags: review+ → review-
Assignee | ||
Comment 18•12 years ago
|
||
(In reply to Taras Glek (:taras) from comment #15)
> Comment on attachment 634694 [details] [diff] [review]
> Windows test suite
>
> Really? OS.Unix.Path in the windows testsuite? This works?
Sorry, that's an artifact of testing the Windows version on a Unix computer. I'll fix this.
Assignee | ||
Comment 19•12 years ago
|
||
(In reply to Taras Glek (:taras) from comment #16)
> Comment on attachment 634696 [details] [diff] [review]
> Windows back-end
>
>
> exports.OS.Unix.Path <-- do not use Unix on a windows platform. If for
> whatever OS.Path sure, but not OS.lie.Path.
Well, it is not a lie, it is an error, but yes, it is still my fault for uploading at 3am.
>
>
> + basename: function basename(path) {
> + return path.slice(Math.max(path.lastIndexOf("\\"),
> path.lastIndexOf(":")) + 1);
> + },
>
> This and other path handling functions need to explicitly block paths(ie UNC
> ones) that start with '\\'(make a utility). Make a utility function that
> throws an exception if a UNC path is detected.
>
> Otherwise you get weird string exceptions for paths without ':' in them.
> Should also check errors when looking for "\\" position in path strings and
> throw proper exceptions.
Will do. I still think that this check would be better served as part of a data structure, though. Do you mind if I open a bug for that?
>
> + let noDrive = (options && options.winNoDrive);
>
> what the heck is .winNoDrive? no docs for it.
I will document this.
> Need to document what you are doing in join with regexps, general strategy,
> etc. I generally don't require comments in the body if the code is clear,
> it's not in this case.
Ok.
Assignee | ||
Comment 20•12 years ago
|
||
(In reply to Taras Glek (:taras) from comment #17)
> Comment on attachment 634624 [details] [diff] [review]
> Unix back-end
>
> + return path.slice(path.lastIndexOf("/") + 1);
>
> as in other patch, please check errors from string functions and throw
> appropriate exceptions.
The only way these functions can fail is if |path| is |null|. Is this what you want me to check?
Assignee | ||
Comment 21•12 years ago
|
||
Attachment #634694 -
Attachment is obsolete: true
Assignee | ||
Comment 22•12 years ago
|
||
Updating the Windows back-end: more comments, more doc, and checks that we are not
Attachment #634696 -
Attachment is obsolete: true
Attachment #635308 -
Flags: review?(taras.mozilla)
Assignee | ||
Comment 23•12 years ago
|
||
Attachment #635308 -
Attachment is obsolete: true
Attachment #635308 -
Flags: review?(taras.mozilla)
Attachment #635325 -
Flags: review?(taras.mozilla)
Assignee | ||
Comment 24•12 years ago
|
||
Attachment #635302 -
Attachment is obsolete: true
Comment 25•12 years ago
|
||
(In reply to David Rajchenbach Teller [:Yoric] from comment #20)
> (In reply to Taras Glek (:taras) from comment #17)
> > Comment on attachment 634624 [details] [diff] [review]
> > Unix back-end
> >
> > + return path.slice(path.lastIndexOf("/") + 1);
> >
> > as in other patch, please check errors from string functions and throw
> > appropriate exceptions.
>
> The only way these functions can fail is if |path| is |null|. Is this what
> you want me to check?
good point, this is a false alarm. I just want to ensure we don't throw string exceptions out of os.file.
Comment 26•12 years ago
|
||
Comment on attachment 635325 [details] [diff] [review]
Windows back-end
This is getting close to landing, a few minor cleanups.
+ return (!noDrive && this.winGetDrive(path)) || ".";
This is too clever. Please use an if statement here.
+ // Ignore any occurrence of "\\: immediately before that one
typo
+ start = (this.winGetDrive(path) || "").length;
too clever. if please
+ for each(let i in arguments) {
s/i/segment, component, whatever you like/ i implies integer-like thing
+ let result = paths.join("\\");
+ if (absolute) {
+ result = "\\" + result;
+ }
I'm not a fan of prepending strings. Instead of a prepend, do an append..ie add drive letter first, result after.
Same with if(root) below.
+ winGetDrive: function winHasDrive(path) { <-- that's bad
Name indicates boolean, return is a string/null. call it winGetDrive
similar thing with winIsAbsolute -> winEnsureAbsolute
Attachment #635325 -
Flags: review?(taras.mozilla) → review-
Assignee | ||
Comment 27•12 years ago
|
||
(In reply to Taras Glek (:taras) from comment #26)
> Comment on attachment 635325 [details] [diff] [review]
> Windows back-end
>
> This is getting close to landing, a few minor cleanups.
>
> + return (!noDrive && this.winGetDrive(path)) || ".";
>
> This is too clever. Please use an if statement here.
ok
>
> + // Ignore any occurrence of "\\: immediately before that one
> typo
oops
>
> + start = (this.winGetDrive(path) || "").length;
> too clever. if please
>
> + for each(let i in arguments) {
>
> s/i/segment, component, whatever you like/ i implies integer-like thing
Good idea. Even if we are not writing in Fortran :)
>
> + let result = paths.join("\\");
> + if (absolute) {
> + result = "\\" + result;
> + }
> I'm not a fan of prepending strings. Instead of a prepend, do an append..ie
> add drive letter first, result after.
>
> Same with if(root) below.
Ok. Out of curiosity, what is wrong with prepending strings?
>
> + winGetDrive: function winHasDrive(path) { <-- that's bad
> Name indicates boolean, return is a string/null. call it winGetDrive
Sorry, typo. As you see, field name is already winGetDrive.
>
> similar thing with winIsAbsolute -> winEnsureAbsolute
This one, I don't understand. The method returns a boolean, why should I call it "ensure"?
Comment 28•12 years ago
|
||
>
> >
> > + let result = paths.join("\\");
> > + if (absolute) {
> > + result = "\\" + result;
> > + }
> > I'm not a fan of prepending strings. Instead of a prepend, do an append..ie
> > add drive letter first, result after.
> >
> > Same with if(root) below.
>
> Ok. Out of curiosity, what is wrong with prepending strings?
Nothing. It's slightly more straightforward to assemble the string in the order that it ends up.
>
> >
> > + winGetDrive: function winHasDrive(path) { <-- that's bad
> > Name indicates boolean, return is a string/null. call it winGetDrive
>
> Sorry, typo. As you see, field name is already winGetDrive.
Right :)
>
> >
> > similar thing with winIsAbsolute -> winEnsureAbsolute
>
> This one, I don't understand. The method returns a boolean, why should I
> call it "ensure"?
Sorry, misread. I seem to be suffering a bout of dyslexia today.
Assignee | ||
Updated•12 years ago
|
Attachment #634623 -
Flags: review?(taras.mozilla)
Assignee | ||
Comment 29•12 years ago
|
||
Attachment #634624 -
Attachment is obsolete: true
Attachment #635712 -
Flags: review?(taras.mozilla)
Assignee | ||
Updated•12 years ago
|
Attachment #635712 -
Flags: review?(taras.mozilla) → review+
Assignee | ||
Comment 30•12 years ago
|
||
Applied the requested back-end changes.
Attachment #635325 -
Attachment is obsolete: true
Attachment #635717 -
Flags: review?(taras.mozilla)
Assignee | ||
Updated•12 years ago
|
Attachment #635326 -
Flags: review?(taras.mozilla)
Comment 31•12 years ago
|
||
David, I likely wont be able to get to these reviews this week. Either ask someone else for review or hold tight :)
Assignee | ||
Updated•12 years ago
|
Attachment #634623 -
Flags: review?(doug.turner)
Assignee | ||
Updated•12 years ago
|
Attachment #635326 -
Flags: review?(doug.turner)
Assignee | ||
Updated•12 years ago
|
Attachment #635717 -
Flags: review?(doug.turner)
Comment 32•12 years ago
|
||
Comment on attachment 634623 [details] [diff] [review]
Unix test suite
Review of attachment 634623 [details] [diff] [review]:
-----------------------------------------------------------------
::: toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js
@@ +5,5 @@
> dump("WORKER "+text+"\n");
> }
>
> function send(message) {
> +// log("Sending " + JSON.stringify(message) + "errno: " + ctypes.errno);
just remove it, right?
@@ +208,5 @@
> +function test_path()
> +{
> + ok(true, "test_path: starting");
> + is(OS.Unix.Path.basename("a/b"), "b", "basename of a/b");
> + is(OS.Unix.Path.basename("a/b/"), "", "basename of a/b/");
is basename really "" for b/? Shouldn't it be 'b'?
Assignee | ||
Comment 33•12 years ago
|
||
(In reply to Doug Turner (:dougt) from comment #32)
> Comment on attachment 634623 [details] [diff] [review]
> Unix test suite
>
> Review of attachment 634623 [details] [diff] [review]:
> -----------------------------------------------------------------
>
> ::: toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js
> @@ +5,5 @@
> > dump("WORKER "+text+"\n");
> > }
> >
> > function send(message) {
> > +// log("Sending " + JSON.stringify(message) + "errno: " + ctypes.errno);
>
> just remove it, right?
>
> @@ +208,5 @@
> > +function test_path()
> > +{
> > + ok(true, "test_path: starting");
> > + is(OS.Unix.Path.basename("a/b"), "b", "basename of a/b");
> > + is(OS.Unix.Path.basename("a/b/"), "", "basename of a/b/");
>
> is basename really "" for b/? Shouldn't it be 'b'?
Interestingly, this depends on whether we follow Unix conventions ('b') or Python conventions (""). I have followed the second here, and I should probably document this.
Comment 34•12 years ago
|
||
Comment on attachment 635717 [details] [diff] [review]
Windows back-end
stripBackslashes -> trimBackslashes might be better
ensureNotUNC should probably ensure that the path has a drive: component so functions like basename do not throw string exceptions
+ /**
+ * Return |true| if the path is absolute, |false| otherwise.
+ *
+ * We consider that a path is absolute if it starts with "\\"
+ * or "driveletter:\\".
+ */
That seems wrong. paths that start with \ are relative to current drive. That's in no way absolute.
Please address above comments in a followup patch.
Attachment #635717 -
Flags: review?(taras.mozilla)
Attachment #635717 -
Flags: review?(doug.turner)
Attachment #635717 -
Flags: review+
Updated•12 years ago
|
Attachment #634623 -
Flags: review?(taras.mozilla)
Attachment #634623 -
Flags: review?(doug.turner)
Attachment #634623 -
Flags: review+
Updated•12 years ago
|
Attachment #635326 -
Flags: review?(taras.mozilla)
Attachment #635326 -
Flags: review?(doug.turner)
Attachment #635326 -
Flags: review+
Assignee | ||
Comment 35•12 years ago
|
||
(In reply to Taras Glek (:taras) from comment #34)
> Comment on attachment 635717 [details] [diff] [review]
> Windows back-end
>
> stripBackslashes -> trimBackslashes might be better
ok
> ensureNotUNC should probably ensure that the path has a drive: component so
> functions like basename do not throw string exceptions
Well, none of the functions throws if there is no drive component, so this does not really seem useful. Do you really want that? I believe that this will only make |basename| and |dirname| less useful.
>
>
> + /**
> + * Return |true| if the path is absolute, |false| otherwise.
> + *
> + * We consider that a path is absolute if it starts with "\\"
> + * or "driveletter:\\".
> + */
>
> That seems wrong. paths that start with \ are relative to current drive.
> That's in no way absolute.
Well, I am sticking with the definition of MSDN:
« A file name is relative to the current directory if it does not begin with one of the following: [...] A single backslash, for example, "\directory" or "\file.txt". This is also referred to as an absolute path. »
Are you sure that you want me to change this?
> Please address above comments in a followup patch.
Ok.
Assignee | ||
Comment 36•12 years ago
|
||
Attachment #635717 -
Attachment is obsolete: true
Attachment #638710 -
Flags: review+
Assignee | ||
Comment 37•12 years ago
|
||
Attachment #635712 -
Attachment is obsolete: true
Attachment #638711 -
Flags: review+
Assignee | ||
Comment 38•12 years ago
|
||
Attachment #634623 -
Attachment is obsolete: true
Attachment #638712 -
Flags: review+
Assignee | ||
Comment 39•12 years ago
|
||
Attachment #635326 -
Attachment is obsolete: true
Attachment #638714 -
Flags: review+
Assignee | ||
Updated•12 years ago
|
Keywords: checkin-needed
Comment 40•12 years ago
|
||
Assignee | ||
Updated•12 years ago
|
Keywords: checkin-needed
Assignee | ||
Updated•12 years ago
|
Keywords: checkin-needed
Comment 41•12 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/4ff738074a6d
https://hg.mozilla.org/mozilla-central/rev/12964e66b3b3
https://hg.mozilla.org/mozilla-central/rev/992ba16d7d5e
https://hg.mozilla.org/mozilla-central/rev/82e16d73fe09
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•