[squeak-dev] UnixFileDirectory default directoryExists: UnixFileDirectory default asString, '/.'

David T. Lewis lewis at mail.msen.com
Fri Dec 16 02:18:35 UTC 2011


On Thu, Dec 15, 2011 at 02:19:04PM -0800, Eliot Miranda wrote:
> Hi All,
> 
>     just noticed that
> 
>         UnixFileDirectory default directoryExists: UnixFileDirectory
> default asString, '/.'
> 
> answers false, since directoryNames excludes '.' and '..' (justifiable, and
> changing this might break all manner of things). i.e.
> 
> FileDirectory>directoryExists: filenameOrPath
> "Answer true if a directory of the given name exists. The given name may be
> either a full path name or a local directory within this directory."
> "FileDirectory default directoryExists: FileDirectory default pathName"
> 
> | fName dir |
> DirectoryClass splitName: filenameOrPath to:
> [:filePath :name |
> fName := name.
> filePath isEmpty
> ifTrue: [dir := self]
> ifFalse: [dir := self directoryNamed: filePath]].
> 
> ^dir exists and: [
> self isCaseSensitive
> ifTrue:[dir directoryNames includes: fName]
> ifFalse:[dir directoryNames anySatisfy: [:name| name sameAs: fName]]].
> 
> 
> So how about
> 
> FileDirectory class methods for accessing
> currentDirectoryNickname
>     ^'.'
> 
> FileDirectory>directoryExists: filenameOrPath
> "Answer true if a directory of the given name exists. The given name may be
> either a full path name or a local directory within this directory."
> "FileDirectory default directoryExists: FileDirectory default pathName"
> 
> | fName dir |
> DirectoryClass splitName: filenameOrPath to:
> [:filePath :name |
> fName := name.
> filePath isEmpty
> ifTrue: [dir := self]
> ifFalse: [dir := self directoryNamed: filePath]].
> 
> ^dir exists
> and: [fName = self class currentDirectoryNickname
>  or: [self isCaseSensitive
> ifTrue:[dir directoryNames includes: fName]
> ifFalse:[dir directoryNames anySatisfy: [:name| name sameAs: fName]]]]


Then how would we handle this:

  UnixFileDirectory default directoryExists: UnixFileDirectory default fullName, '/../../.'

Or this:

  UnixFileDirectory default directoryExists: '/usr/b?n'

There is a reasonable approximation of unix path handling in the
CommandShell package (see class ShellSyntax), but IMO this is too
complex and platform-specific for general use. Furthermore, the method
comment for #directoryExists: says that the path should specify either
a full path name or a local directory within the directory, and '/.'
does not meet these criteria. So in my opinion, the current behavior
is unexpected for a unix user but it is not incorrect, and changing it
to work correctly in a unix-like way is not worth the added complexity.

Dave




More information about the Squeak-dev mailing list