handle 'foo///' in directoryName
authorClaus Gittinger <cg@exept.de>
Tue, 22 Oct 1996 19:55:10 +0200
changeset 1799 0a2c5890f4f3
parent 1798 543f1601bbeb
child 1800 1aa32eede53a
handle 'foo///' in directoryName & pathName
Unix.st
--- a/Unix.st	Tue Oct 22 16:27:24 1996 +0200
+++ b/Unix.st	Tue Oct 22 19:55:10 1996 +0200
@@ -750,7 +750,7 @@
 %}
 ! !
 
-!OperatingSystem  class methodsFor:'documentation'!
+!OperatingSystem class methodsFor:'documentation'!
 
 copyright
 "
@@ -893,7 +893,7 @@
 "
 ! !
 
-!OperatingSystem  class methodsFor:'initialization'!
+!OperatingSystem class methodsFor:'initialization'!
 
 initialize
     "initialize the class"
@@ -932,7 +932,7 @@
     "Created: 15.6.1996 / 15:22:37 / cg"
 ! !
 
-!OperatingSystem  class methodsFor:'OS signal constants'!
+!OperatingSystem class methodsFor:'OS signal constants'!
 
 sigABRT
     "return the signal number for SIGABRT - 0 if not supported by OS
@@ -1497,7 +1497,7 @@
 %}
 ! !
 
-!OperatingSystem  class methodsFor:'Signal constants'!
+!OperatingSystem class methodsFor:'Signal constants'!
 
 accessDeniedErrorSignal
     "return the signal raised when a (file-) access is denied."
@@ -1519,7 +1519,7 @@
     ^ FileNotFoundErrorSignal
 ! !
 
-!OperatingSystem  class methodsFor:'error messages'!
+!OperatingSystem class methodsFor:'error messages'!
 
 clearLastErrorNumber
     "return the last errors number.
@@ -2634,7 +2634,7 @@
      "
 ! !
 
-!OperatingSystem  class methodsFor:'executing OS commands'!
+!OperatingSystem class methodsFor:'executing OS commands'!
 
 canExecuteCommand:aCommandString
     "return true, if the OS can execute aCommand."
@@ -3221,7 +3221,7 @@
     "Modified: 29.2.1996 / 12:49:14 / cg"
 ! !
 
-!OperatingSystem  class methodsFor:'file access'!
+!OperatingSystem class methodsFor:'file access'!
 
 closeFd:anInteger
     "low level close of a filedescriptor"
@@ -3503,7 +3503,7 @@
     ^ self primitiveFailed
 ! !
 
-!OperatingSystem  class methodsFor:'file access rights'!
+!OperatingSystem class methodsFor:'file access rights'!
 
 accessMaskFor:aSymbol
     "return the access bits mask for numbers as returned by 
@@ -3624,7 +3624,7 @@
     ^ self primitiveFailed
 ! !
 
-!OperatingSystem  class methodsFor:'file locking'!
+!OperatingSystem class methodsFor:'file locking'!
 
 lockFD:aFileDescriptor shared:isSharedReadLock blocking:blockIfLocked
    "set a lock on the file represented by aFileDescriptor.
@@ -3841,7 +3841,7 @@
     ^ false
 ! !
 
-!OperatingSystem  class methodsFor:'file queries'!
+!OperatingSystem class methodsFor:'file queries'!
 
 baseNameOf:aPathString
     "return the baseName of the argument, aPathString
@@ -3944,41 +3944,45 @@
      This method does not check if the path is valid
      (i.e. if these directories really exist & are readable)."
 
-    |last index sep sepString|
+    |last index sep sepString p|
 
     sep := self fileSeparator.
     sepString := sep asString.
     (aPathString = sepString) ifTrue:[
-	"
-	 the trivial '/' case
-	"
-	^ aPathString
+        "
+         the trivial '/' case
+        "
+        ^ aPathString
     ].
-    (aPathString startsWith:sepString) ifFalse:[
-	(aPathString endsWith:sepString) ifTrue:[
-	    ^ aPathString copyTo:(aPathString size - 1)
-	].
+
+    p := aPathString.
+    [p endsWith:sepString] whileTrue:[
+        (p = sepString) ifTrue:[
+            ^ p
+        ].
+        p := p copyWithoutLast:1
     ].
+
     last := 1.
     [true] whileTrue:[
-	index := aPathString indexOf:sep startingAt:(last + 1).
-	index == 0 ifTrue:[
-	    (last == 1) ifTrue:[
-		(aPathString startsWith:sepString) ifTrue:[
-		    ^ sepString
-		].
-		^ '.'
-	    ].
+        index := p indexOf:sep startingAt:(last + 1).
+        index == 0 ifTrue:[
+            (last == 1) ifTrue:[
+                (p startsWith:sepString) ifTrue:[
+                    ^ sepString
+                ].
+                ^ '.'
+            ].
 "
-	    (aPathString startsWith:sepString) ifFalse:[
-		(aPathString startsWith:('..' , sepString)) ifFalse:[
-		    ^ './' , (aPathString copyTo:(last - 1))
-		]
-	    ].
+            (p startsWith:sepString) ifFalse:[
+                (p startsWith:('..' , sepString)) ifFalse:[
+                    ^ './' , (p copyTo:(last - 1))
+                ]
+            ].
 "
-	    ^ aPathString copyTo:(last - 1)
-	].
-	last := index.
+            ^ p copyTo:(last - 1)
+        ].
+        last := index.
     ]
 
     "
@@ -3987,7 +3991,15 @@
      OperatingSystem directoryNameOf:'../../foo/bar'
      OperatingSystem directoryNameOf:'bar'
      OperatingSystem directoryNameOf:'/bar'
-    "
+     OperatingSystem directoryNameOf:'/tmp' 
+     OperatingSystem directoryNameOf:'/tmp///' 
+     OperatingSystem directoryNameOf:'/bar///' 
+     OperatingSystem directoryNameOf:'/bar/'  
+     OperatingSystem directoryNameOf:'./bar'  
+     OperatingSystem directoryNameOf:'/./bar'  
+    "
+
+    "Modified: 22.10.1996 / 18:53:47 / cg"
 !
 
 fileSeparator
@@ -4369,32 +4381,40 @@
     path := self primPathNameOf:pathName.
 
     path isNil ifTrue:[
-	(self isValidPath:pathName) ifFalse:[^ pathName].
-
-	(SlowFork==true or:[ForkFailed]) ifFalse:[
-	    PipeStream openErrorSignal handle:[:ex |
-		ForkFailed := true.
-		'OS: cannot fork/popen' errorPrintNL.
-		ex return.
-	    ] do:[
-		"have to fall back ..."
-		command := 'cd ' , pathName , '; pwd'.
-		p := PipeStream readingFrom:command.
-	    ].
-
-	    (p isNil or:[p atEnd]) ifTrue:[
-		('OS: PipeStream for <' , command , '> failed') errorPrintNL.
-	    ] ifFalse:[
-		path := p nextLine.
-		p close.
-	    ].
-	].
-	path isNil ifTrue:[
-	    path := pathName
-	].
-	(SlowFork==true or:[ForkFailed]) ifTrue:[
-	    path := self compressPath:path
-	]
+        (self isValidPath:pathName) ifFalse:[
+            p := pathName.
+            [(p size > 1)
+             and:[p endsWith:(self fileSeparator)]
+            ] whileTrue:[
+                p := p copyWithoutLast:1.
+            ].
+            ^ p
+        ].
+
+        (SlowFork==true or:[ForkFailed]) ifFalse:[
+            PipeStream openErrorSignal handle:[:ex |
+                ForkFailed := true.
+                'OS: cannot fork/popen' errorPrintNL.
+                ex return.
+            ] do:[
+                "have to fall back ..."
+                command := 'cd ' , pathName , '; pwd'.
+                p := PipeStream readingFrom:command.
+            ].
+
+            (p isNil or:[p atEnd]) ifTrue:[
+                ('OS: PipeStream for <' , command , '> failed') errorPrintNL.
+            ] ifFalse:[
+                path := p nextLine.
+                p close.
+            ].
+        ].
+        path isNil ifTrue:[
+            path := pathName
+        ].
+        (SlowFork==true or:[ForkFailed]) ifTrue:[
+            path := self compressPath:path
+        ]
     ].
     ^ path.
 
@@ -4403,7 +4423,13 @@
      OperatingSystem pathNameOf:'../smalltalk/../smalltalk'
      OperatingSystem pathNameOf:'../../..'
      OperatingSystem pathNameOf:'..'
-    "
+     OperatingSystem pathNameOf:'/tmp////' 
+     OperatingSystem pathNameOf:'/foo/bar' 
+     OperatingSystem pathNameOf:'/foo/bar/'
+     OperatingSystem pathNameOf:'/foo/bar//'
+    "
+
+    "Modified: 22.10.1996 / 17:59:19 / cg"
 !
 
 primPathNameOf:pathName
@@ -4574,7 +4600,7 @@
     "
 ! !
 
-!OperatingSystem  class methodsFor:'interrupts & signals'!
+!OperatingSystem class methodsFor:'interrupts & signals'!
 
 blockInterrupts
     "disable interrupt processing - if disabled, incoming
@@ -5397,7 +5423,7 @@
 %}
 ! !
 
-!OperatingSystem  class methodsFor:'misc'!
+!OperatingSystem class methodsFor:'misc'!
 
 exit
     "shutdown smalltalk immediately - this method does not return.
@@ -5448,7 +5474,7 @@
     "Modified: 22.4.1996 / 13:13:09 / cg"
 ! !
 
-!OperatingSystem  class methodsFor:'os queries'!
+!OperatingSystem class methodsFor:'os queries'!
 
 getCPUDefine
     "return a string which was used to identify this CPU type when STX was
@@ -6520,7 +6546,7 @@
     ^ true
 ! !
 
-!OperatingSystem  class methodsFor:'shared memory access'!
+!OperatingSystem class methodsFor:'shared memory access'!
 
 shmAttach:id address:addr flags:flags
     "low level entry to shmat()-system call.
@@ -6602,7 +6628,7 @@
     "Modified: 22.4.1996 / 13:14:46 / cg"
 ! !
 
-!OperatingSystem  class methodsFor:'time and date'!
+!OperatingSystem class methodsFor:'time and date'!
 
 computeDatePartsOf:osTime for:aBlock
     "compute year, month and day from the OS time, osTime
@@ -7138,7 +7164,7 @@
     "
 ! !
 
-!OperatingSystem  class methodsFor:'users & groups'!
+!OperatingSystem class methodsFor:'users & groups'!
 
 getEffectiveGroupID
     "return the current users (thats you) effective numeric group id.
@@ -7434,7 +7460,7 @@
     "
 ! !
 
-!OperatingSystem  class methodsFor:'waiting for events'!
+!OperatingSystem class methodsFor:'waiting for events'!
 
 blockingChildProcessWait
      "return true, if childProcessWait: blocks, if no childs are ready"
@@ -7869,9 +7895,9 @@
     ^ false
 ! !
 
-!OperatingSystem  class methodsFor:'documentation'!
+!OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/Unix.st,v 1.170 1996-10-08 20:58:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/Unix.st,v 1.171 1996-10-22 17:55:10 cg Exp $'
 ! !
 OperatingSystem initialize!