help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] [PATCH] mingw fix


From: Paolo Bonzini
Subject: [Help-smalltalk] [PATCH] mingw fix
Date: Wed, 13 Feb 2008 08:57:23 +0100
User-agent: Thunderbird 2.0.0.9 (Macintosh/20071031)

Here is the bug that is breaking gst-package on mingw:

st> CSymbols.PathSeparator := $\
$\
st> File computePathFrom: 'C:/a\b\c' to: 'C:\a\e\f'
'/C:/a/e/f'

with the patch, obviously, it returns '..\e\f'.

There was a similar problem in File>>#fullNameFor: but it was already fixed last June by Freddie Akeroyd.

Paolo
2008-02-13  Paolo Bonzini  <address@hidden>
    
        * kernel/File.st: Canonicalize names before finding directory
        components.

diff --git a/kernel/File.st b/kernel/File.st
index 09ba2ce..bfa4ff6 100644
--- a/kernel/File.st
+++ b/kernel/File.st
@@ -192,9 +192,18 @@ size and timestamps.'>
 
     File class >> computePathFrom: srcName to: destName [
        <category: 'private'>
-       | src dest srcComponent destComponent path |
-       src := srcName subStrings: Directory pathSeparator.
-       dest := destName subStrings: Directory pathSeparator.
+       | src dest srcCanon destCanon path |
+       "A Windows path may contain both / and \ separators. Clean it up
+        to allow easy parsing"
+       srcCanon := Directory pathSeparator = $/ 
+                   ifTrue: [srcName]
+                   ifFalse: [srcName copyReplacing: $/ withObject: Directory 
pathSeparator].
+       destCanon := Directory pathSeparator = $/ 
+                   ifTrue: [destName]
+                   ifFalse: [destName copyReplacing: $/ withObject: Directory 
pathSeparator].
+
+       src := srcCanon subStrings: Directory pathSeparator.
+       dest := destCanon subStrings: Directory pathSeparator.
        src := src asOrderedCollection.
        src removeLast.
        dest := dest asOrderedCollection.
@@ -208,7 +217,7 @@ size and timestamps.'>
                                dest removeFirst].
                        src collect: [:each | '..']].
        path addAllLast: dest.
-       ^path fold: [:a :b | a , '/' , b]
+       ^path fold: [:a :b | a , Directory pathSeparatorString , b]
     ]
 
     File class >> checkError [

reply via email to

[Prev in Thread] Current Thread [Next in Thread]