[FIX] RE: [BUG?] UnixFileDirectory

Bert Freudenberg bert at isgnw.CS.Uni-Magdeburg.De
Wed Mar 22 17:26:18 UTC 2000


On Wed, 22 Mar 2000, Lex Spoon wrote:

> I agree that enforcing some consistency would be nice.... 

Yes. I attach a changeset. It enforces the absoluteness of pathes for
Windows. I also corrected splitName:to:, for the DOS 'C:' case (which
makes the specialized fullNameFor: method obsolete) and for the Unix
'/foo' case. Read further for some comments ...

> If nothing else, trying to open a relative path should automatically
> prepend the main part, instead of just sending it down to the OS.

Nope. I just spent an hour hacking in FileDir subclasses with relative
paths and rooted paths and what not - finally I concluded that everything
is fine like it is, but the behaviour has to be made consistent across
platforms. If you want a relative path, start with "FileDir default".

The behaviour is defined in the class comment:
"A FileDirectory represents a folder or directory in the underlying
platform's file system. It carries a fully-qualified path name for the
directory it represents, and can enumerate the files and directories
within that directory."

So it is actually a bug if some platform (Windows in this case) allows a
relative path for a file directory.

One a-ha for me was discovering how the file system root is accessed. It
just works, in the File List for example, for all systems (and it got
broken by my naive hacking). You know what? It's the empty string *by
definition*. Mac and Windows handle this in the VM, while for Unix this is
in the image. It all made sense once I accepted it ;-)

For example, to construct a path the File List just concatenates the
parts, separated by the current path-delimiter. For Windows, this always
starts with "<letter>:" so it is absolute. For Unix, it looks like
relative (no leading slash) but since it actually is absolute, the
UnixFileDir enforces this.

The attached changeset is tested (slightly) on Win and Linux, it shouldn't
break anything else ...

  -Bert-
-------------- next part --------------
'From Squeak2.8alpha of 18 January 2000 [latest update: #1919] on 22 March 2000 at 6:25:39 pm'!
"Change Set:		filedir-bf
Date:			22 March 2000
Author:			Bert Freudenberg

Enforces the absoluteness of FileDirectories for Windows. Also corrects FileDirclass>>splitName:to:, for the DOS 'C:' case (which makes the specialized fullNameFor: method obsolete) and for the Unix '/foo' case."!


!DosFileDirectory methodsFor: 'as yet unclassified' stamp: 'bf 3/21/2000 17:06'!
setPathName: pathString
	"Ensure pathString is absolute - relative directories aren't supported on all platforms."

	(pathString isEmpty
		or: [pathString first = $\
			or: [pathString size >= 2 and: [pathString second = $: and: [pathString first isLetter]]]])
				ifTrue: [^ super setPathName: pathString].

	self error: 'Fully qualified path expected'! !


!FileDirectory class methodsFor: 'name utilities' stamp: 'bf 3/22/2000 18:04'!
splitName: fullName to: pathAndNameBlock
	"Take the file name and convert it to the path name of a directory and a local file name within that directory. FileName must be of the form: <dirPath><delimiter><localName>, where <dirPath><delimiter> is optional. The <dirPath> part may contain delimiters."

	| delimiter i dirName localName |
	delimiter _ self pathNameDelimiter.
	(i _ fullName findLast: [:c | c = delimiter]) = 0
		ifTrue: [
			dirName _ String new.
			localName _ fullName]
		ifFalse: [
			dirName _ fullName copyFrom: 1 to: (i - 1 max: 1).
			localName _ fullName copyFrom: i + 1 to: fullName size].

	^ pathAndNameBlock value: dirName value: localName
! !


!DosFileDirectory class methodsFor: 'platform specific' stamp: 'bf 3/21/2000 16:40'!
splitName: fullName to: pathAndNameBlock
	(fullName size = 2 and: [fullName first isLetter and: [fullName last = $:]])
		ifTrue: [^ pathAndNameBlock value: fullName value: ''].
	^super splitName: fullName to: pathAndNameBlock
! !


!UnixFileDirectory methodsFor: 'file names' stamp: 'bf 3/22/2000 18:24'!
fullPathFor: path
	"Return the fully-qualified path name for the given file."
	path isEmpty ifTrue:[^pathName].
	path first = $/ ifTrue:[^path].
	^pathName = '/'			"Only root dir ends with a slash"
		ifTrue: ['/', path]
		ifFalse: [pathName, '/', path]! !


DosFileDirectory removeSelector: #fullNameFor:!


More information about the Squeak-dev mailing list