[Jslib] Re: file.js and invalid windows paths

Eric Plaster plaster@talkware.net
Tue, 08 May 2001 14:28:40 -0500


--------------EF428406CCFD49DE9A5AC1EC
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

"Martin T. Kutschker" wrote:

>     > Possible convenience constructors:
>     >
>     > MozUserHomeDir()
>     > MozHomeDir()
>     > ChromeDir()
>     > PrefsDir()
>
>      Call me old school, but I would prefer something like:
>
>         * dir.resetToHomeDir();
>         * dir.resetChromeDir();
>         * dir.resetPrefsDir();
>
> If you like. Or have another syntaxvar d = Dir("",
> JSLIB_DIR_MOZ_USER_HOME) or Dir(null, JSLIB_DIR_MOZ_USER_HOME)etc. :-)

One thing that I don't like is making the user type a lot of parameters
that you may not care about.  How about if we move the special dirs to
DirUtils like this:

var dirutils = new DirUtils();
var dir = dirutils.getChromeDir();

>
>
>     > Methods:
>     >
>     > exists();
>
> What should it return when a file system object with that path exists,
> but it is not a directory?

I think that we should throw an exception if we try to open a dir that
is not a dir

>
>
>     > create(aPermissions) or make(aPermissions)
>     > read()     [ returns an array of File objects, dirs and
>     > special files are
>     > omitted ]
>     > list()       [ same as read() but returns array of content
>     > names: files,
>     > dirs and special files ]
>     > permissions()
>     > dateModified()
>     > child(aString)  [ appends the string to form a new path ]
>     > help()
>
>
>      Instead of read and list, how about these:
>
> list() may still make sense to gather all objects in the dir (via
> name).

Sure.

>
>
>         * dirs()  // returns a list of directories in that
>           directory
>         * files()  // returns a list of files
>
> They return an array of Dir() and File() objects?

Yep.

>         * specialFiles()  // returns a list of special files.
>
> What can be done to or be known of special files in JS (or via XPCOM)?
> I listed them as patr of the result set of list() for the sake of
> completeness. Must we define a general class for a file system object
> then, a base class for File, Die and a possible SpecialFile?

I think we should skip this part untill we have a dir class first.  I
don't know how mozilla handles the special files (in linux, files
begining with a ".") off hand.

>         * mkdir(name, perms) // creates a directory in the
>           current directory
>
> Ok, but create(perms) must stay:var d = new Dir(aPath)if
> (!d.exists())  d.create() But see not above. Plus the method Pete
> asked for:

Yep, what I was thinking was this members:

   * create(perms)  --> creates "this" directory.  Throws if already
     exists.
   * mkdir(name, perms)  --> creates a directory inside "this"
     directory.  Throw if already exists or if there is a file with the
     same name.

>
>
>    * nsIFile()
>
> If it may also be a dir, that is.Masi

--
----
Eric Plaster                    Universal Talkware Corp
Senior Software Engineer        (612)843-6711
plaster@talkware.net            http://www.talkware.net



--------------EF428406CCFD49DE9A5AC1EC
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<body bgcolor="#FFFFFF">
"Martin T. Kutschker" wrote:
<blockquote TYPE=CITE><style></style>

<blockquote 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<blockquote TYPE="CITE">Possible convenience constructors:
<p>MozUserHomeDir()
<br>MozHomeDir()
<br>ChromeDir()
<br>PrefsDir()</blockquote>
Call me old school, but I would prefer something like:
<ul>
<li>
dir.resetToHomeDir();</li>

<li>
dir.resetChromeDir();</li>

<li>
dir.resetPrefsDir();</li>
</ul>
</blockquote>
<font face="Andale Mono"><font size=-1>If you like. Or have another syntaxvar
d = Dir("", JSLIB_DIR_MOZ_USER_HOME) or Dir(null, JSLIB_DIR_MOZ_USER_HOME)etc.
:-)</font></font></blockquote>
One thing that I don't like is making the user type a lot of parameters
that you may not care about.&nbsp; How about if we move the special dirs
to DirUtils like this:
<p><tt>var dirutils = new DirUtils();</tt>
<br><tt>var dir = dirutils.getChromeDir();</tt>
<blockquote TYPE=CITE>&nbsp;
<blockquote 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<blockquote TYPE="CITE">Methods:
<p>exists();</blockquote>
</blockquote>
<font face="Andale Mono"><font size=-1>What should it return when a file
system object with that path exists, but it is not a directory?</font></font></blockquote>
I think that we should throw an exception if we try to open a dir that
is not a dir
<blockquote TYPE=CITE>&nbsp;
<blockquote 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<blockquote TYPE="CITE">create(aPermissions) or make(aPermissions)
<br>read()&nbsp;&nbsp;&nbsp;&nbsp; [ returns an array of File objects,
dirs and special files are
<br>omitted ]
<br>list()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ same as read() but returns
array of content names: files,
<br>dirs and special files ]
<br>permissions()
<br>dateModified()
<br>child(aString)&nbsp; [ appends the string to form a new path ]
<br>help()</blockquote>

<p><br>Instead of read and list, how about these:</blockquote>
<font face="Andale Mono"><font size=-1>list() may still make sense to gather
all objects in the dir (via name).</font></font></blockquote>
Sure.
<blockquote TYPE=CITE>&nbsp;
<blockquote 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<ul>
<li>
dirs()&nbsp; // returns a list of directories in that directory</li>

<li>
files()&nbsp; // returns a list of files</li>
</ul>
</blockquote>
<font face="Andale Mono"><font size=-1>They return an array of Dir() and
File() objects?</font></font></blockquote>
Yep.
<blockquote TYPE=CITE>
<blockquote 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<ul>
<li>
specialFiles()&nbsp; // returns a list of special files.</li>
</ul>
</blockquote>
<font face="Andale Mono"><font size=-1>What can be done to or be known
of special files in JS (or via XPCOM)? I listed them as patr of the result
set of list() for the sake of completeness.</font></font> <font face="Andale Mono"><font size=-1>Must
we define a general class for a file system object then, a base class for
File, Die and a possible SpecialFile?</font></font></blockquote>
I think we should skip this part untill we have a dir class first.&nbsp;
I don't know how mozilla handles the special files (in linux, files begining
with a ".") off hand.
<blockquote TYPE=CITE>
<blockquote 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<ul>
<li>
mkdir(name, perms) // creates a directory in the current directory</li>
</ul>
</blockquote>
<font face="Andale Mono"><font size=-1>Ok, but create(perms) must stay:var
d = new Dir(aPath)if (!d.exists())&nbsp; d.create()</font></font> <font face="Andale Mono"><font size=-1>But
see not above.</font></font> <font face="Andale Mono"><font size=-1>Plus
the method Pete asked for:</font></font></blockquote>
Yep, what I was thinking was this members:
<ul>
<li>
create(perms)&nbsp; --> creates "this" directory.&nbsp; Throws if already
exists.</li>

<li>
mkdir(name, perms)&nbsp; --> creates a directory inside "this" directory.&nbsp;
Throw if already exists or if there is a file with the same name.</li>
</ul>

<blockquote TYPE=CITE>&nbsp;
<ul>
<li>
<font face="Andale Mono"><font size=-1>nsIFile()</font></font></li>
</ul>
<font face="Andale Mono"><font size=-1>If it may also be a dir, that is.Masi</font></font></blockquote>

<pre>--&nbsp;
----
Eric Plaster&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Universal Talkware Corp
Senior Software Engineer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (612)843-6711
plaster@talkware.net&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="http://www.talkware.net">http://www.talkware.net</A></pre>
&nbsp;
</body>
</html>

--------------EF428406CCFD49DE9A5AC1EC--