<br><br><div class="gmail_quote">On Thu, Dec 15, 2011 at 6:18 PM, David T. Lewis <span dir="ltr"><<a href="mailto:lewis@mail.msen.com">lewis@mail.msen.com</a>></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>
> Hi All,<br>
><br>
> just noticed that<br>
><br>
> UnixFileDirectory default directoryExists: UnixFileDirectory default asString, '/.'<br>
><br>
> answers false, since directoryNames excludes '.' and '..' (justifiable, and<br>
> changing this might break all manner of things). i.e.<br>
><br>
> FileDirectory>directoryExists: filenameOrPath<br>
> "Answer true if a directory of the given name exists. The given name may be<br>
> either a full path name or a local directory within this directory."<br>
> "FileDirectory default directoryExists: FileDirectory default pathName"<br>
><br>
> | fName dir |<br>
> DirectoryClass splitName: filenameOrPath to:<br>
> [:filePath :name |<br>
> fName := name.<br>
> filePath isEmpty<br>
> ifTrue: [dir := self]<br>
> ifFalse: [dir := self directoryNamed: filePath]].<br>
><br>
> ^dir exists and: [<br>
> self isCaseSensitive<br>
> ifTrue:[dir directoryNames includes: fName]<br>
> ifFalse:[dir directoryNames anySatisfy: [:name| name sameAs: fName]]].<br>
><br>
><br>
> So how about<br>
><br>
> FileDirectory class methods for accessing<br>
> currentDirectoryNickname<br>
> ^'.'<br>
><br>
> FileDirectory>directoryExists: filenameOrPath<br>
> "Answer true if a directory of the given name exists. The given name may be<br>
> either a full path name or a local directory within this directory."<br>
> "FileDirectory default directoryExists: FileDirectory default pathName"<br>
><br>
> | fName dir |<br>
> DirectoryClass splitName: filenameOrPath to:<br>
> [:filePath :name |<br>
> fName := name.<br>
> filePath isEmpty<br>
> ifTrue: [dir := self]<br>
> ifFalse: [dir := self directoryNamed: filePath]].<br>
><br>
> ^dir exists<br>
> and: [fName = self class currentDirectoryNickname<br>
> or: [self isCaseSensitive<br>
> ifTrue:[dir directoryNames includes: fName]<br>
> 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, '/../../.'<br></blockquote><div><br></div><div>It works fine. splitPath:... splits it to e.g. '/Users/eliot/Squeak/Squeak4.2/../..' and '.' and so the result its true. Note that /.. = / on Unix, so one can't have too many '..' or '.' components. The issue is what is the last component, and if that is '.' or '..' 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: '/usr/b?n'<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 '/.'<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're forcing user code to handle the unexpected, and that's really bad. Peppering code with Smalltalk platformName = 'unix' or: [Smalltalk platformName = 'Mac OS'] 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>