<br><br><div class="gmail_quote">On Thu, Dec 15, 2011 at 6:18 PM, David T. Lewis <span dir="ltr">&lt;<a href="mailto:lewis@mail.msen.com">lewis@mail.msen.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div class="h5">On Thu, Dec 15, 2011 at 02:19:04PM -0800, Eliot Miranda wrote:<br>
&gt; Hi All,<br>
&gt;<br>
&gt;     just noticed that<br>
&gt;<br>
&gt;         UnixFileDirectory default directoryExists: UnixFileDirectory default asString, &#39;/.&#39;<br>
&gt;<br>
&gt; answers false, since directoryNames excludes &#39;.&#39; and &#39;..&#39; (justifiable, and<br>
&gt; changing this might break all manner of things). i.e.<br>
&gt;<br>
&gt; FileDirectory&gt;directoryExists: filenameOrPath<br>
&gt; &quot;Answer true if a directory of the given name exists. The given name may be<br>
&gt; either a full path name or a local directory within this directory.&quot;<br>
&gt; &quot;FileDirectory default directoryExists: FileDirectory default pathName&quot;<br>
&gt;<br>
&gt; | fName dir |<br>
&gt; DirectoryClass splitName: filenameOrPath to:<br>
&gt; [:filePath :name |<br>
&gt; fName := name.<br>
&gt; filePath isEmpty<br>
&gt; ifTrue: [dir := self]<br>
&gt; ifFalse: [dir := self directoryNamed: filePath]].<br>
&gt;<br>
&gt; ^dir exists and: [<br>
&gt; self isCaseSensitive<br>
&gt; ifTrue:[dir directoryNames includes: fName]<br>
&gt; ifFalse:[dir directoryNames anySatisfy: [:name| name sameAs: fName]]].<br>
&gt;<br>
&gt;<br>
&gt; So how about<br>
&gt;<br>
&gt; FileDirectory class methods for accessing<br>
&gt; currentDirectoryNickname<br>
&gt;     ^&#39;.&#39;<br>
&gt;<br>
&gt; FileDirectory&gt;directoryExists: filenameOrPath<br>
&gt; &quot;Answer true if a directory of the given name exists. The given name may be<br>
&gt; either a full path name or a local directory within this directory.&quot;<br>
&gt; &quot;FileDirectory default directoryExists: FileDirectory default pathName&quot;<br>
&gt;<br>
&gt; | fName dir |<br>
&gt; DirectoryClass splitName: filenameOrPath to:<br>
&gt; [:filePath :name |<br>
&gt; fName := name.<br>
&gt; filePath isEmpty<br>
&gt; ifTrue: [dir := self]<br>
&gt; ifFalse: [dir := self directoryNamed: filePath]].<br>
&gt;<br>
&gt; ^dir exists<br>
&gt; and: [fName = self class currentDirectoryNickname<br>
&gt;  or: [self isCaseSensitive<br>
&gt; ifTrue:[dir directoryNames includes: fName]<br>
&gt; ifFalse:[dir directoryNames anySatisfy: [:name| name sameAs: fName]]]]<br>
<br>
<br>
</div></div>Then how would we handle this:<br>
<br>
  UnixFileDirectory default directoryExists: UnixFileDirectory default fullName, &#39;/../../.&#39;<br></blockquote><div><br></div><div>It works fine.  splitPath:... splits it to e.g. &#39;/Users/eliot/Squeak/Squeak4.2/../..&#39; and &#39;.&#39; and so the result its true.  Note that /.. = / on Unix, so one can&#39;t have too many &#39;..&#39; or &#39;.&#39; components.   The issue is what is the last component, and if that is &#39;.&#39; or &#39;..&#39; then the code I supplied works.</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Or this:<br>
<br>
  UnixFileDirectory default directoryExists: &#39;/usr/b?n&#39;<br></blockquote><div><br></div><div>That works if there is a file called b?n.  Using ? as a wild-card is a shell facility, nothing to do with the file system.  So this is a non-sequitur.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
There is a reasonable approximation of unix path handling in the<br>
CommandShell package (see class ShellSyntax), but IMO this is too<br>
complex and platform-specific for general use. Furthermore, the method<br>
comment for #directoryExists: says that the path should specify either<br>
a full path name or a local directory within the directory, and &#39;/.&#39;<br>
does not meet these criteria. So in my opinion, the current behavior<br>
is unexpected for a unix user but it is not incorrect, and changing it<br>
to work correctly in a unix-like way is not worth the added complexity.<br></blockquote><div><br></div><div>But you&#39;re forcing user code to handle the unexpected, and that&#39;s really bad.  Peppering code with Smalltalk platformName = &#39;unix&#39; or: [Smalltalk platformName = &#39;Mac OS&#39;] is an awful approach.  The file system classes should be robust, and the issue above affects Windows as well as unix.  Given that the new code handles your objections rationally I respectfully disagree,  It *is* worth the minimal added complexity.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Dave<br>
<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>