[MLton] Windows ports and paths
Wesley W. Terpstra
wesley@terpstra.ca
Tue, 3 May 2005 17:41:17 +0200
On Tue, May 03, 2005 at 12:06:20PM +0200, Andreas Rossberg wrote:
> While we're having so much fun with OS.Path on Windows
Right.
> I just discovered another strange thing that had escaped me before: in the
> description of validVolume it says that "" is only a valid volume under
> Windows if the path is not absolute.
Yeah, right now MLton implements validVolume as described:
fun validVolume {isAbs, vol} =
if isWindows
then isVolumeName vol orelse (not isAbs andalso vol = "")
else vol = ""
> Now, this would effectively rule out paths like "\b\c" or even "\", i.e.
> every absolute path had to contain a volume.
This is what got me thinking they meant absolute = stable under chdir.
In other words, you must have a volume name to be absolute.
The first version of my slash_is_absolute patch did:
+ (* I disagree with the standard; under windows "" is a valid volume even
+ * when the path is absolute. Proof: dir \ works
+ * Under cygwin, the special volume "/" denotes the cygwin pseudo-root
+ *)
+ fun isValidVolume v =
+ v = "" orelse (isWindows andalso size v = 2 andalso
+ Char.isAlpha (v sub 0) andalso iscolon (v sub 1))
+ orelse (volumeHack andalso v = "/")
However, since I got the impression that adherence to the standard as
written was preferred, I switched to the current version which raises
Path on toString { isAbs=true, arcs=[""], vol="" } as required.
> Anybody's got a clue what that could be about? Do they really mean it?
> It is contradicted by the example given in the last paragraph of the
> introduction.
I don't think it really does contradict it.
fromString "\" = { isAbs=true, arcs=[""], vol="" } as described.
It's just that toString will raise Path. :-P
However, I agree that it is stupid.
I really dislike that "\" is an absolute path...
If it's absolute, you should not have to worry about doing a chdir()!
I imagine people using an idiom something like:
val path = mkAbsolute (OS.FileSys.getDir ()) path
val () = OS.FileSys.chDir "e:/somewhere"
val f = TextIO.openIn path
This works for paths "foo\bar" and "c:\foo\bar", but not "\foo\bar".
Grrr. I don't think the person who wrote this ever used windows. ;-)
--
Wesley W. Terpstra