Filename.st
changeset 17143 5b1217eaafa7
parent 17113 a521179b677c
child 17227 c75e790d86f1
--- a/Filename.st	Thu Nov 27 11:11:01 2014 +0100
+++ b/Filename.st	Thu Nov 27 17:48:48 2014 +0100
@@ -2486,7 +2486,7 @@
     ^ FileStream readonlyFileNamed:(self osNameForAccess)
 
     "
-     '/tmp/foo' asFilename readStream 
+      '/tmp/foo' asFilename readStream.
     "
 !
 
@@ -2881,6 +2881,13 @@
     newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ].
 
     inStream := self readStream.
+    inStream isNil ifTrue:[
+        "open failed, but somenone did a proceed for the OpenError.
+         Ignore this file but continue in order to copy the rest when
+         doing a recursive copy"
+        ^ self.
+    ].
+
     [
         newNameAlreadyExists := newName exists.
         outStream := newName writeStream.
@@ -2897,7 +2904,7 @@
         inStream copyToEndInto:outStream.
     ] ensure:[
         inStream close.
-        outStream notNil ifTrue:[outStream syncData; close].
+        outStream notNil ifTrue:[outStream close].
     ].
 
     "
@@ -2969,6 +2976,17 @@
     writeStream close.
 !
 
+createAsSymbolicLinkTo:linkFilenameString
+    "create a directory with the receivers name.
+     Raises an exception if not successful"
+
+    OperatingSystem createSymbolicLinkFrom:linkFilenameString to:self pathName.
+
+    "
+        '/tmp/link' asFilename makeSymbolicLinkTo:'bla'
+    "
+!
+
 delete
     "remove the file - same as remove, for ST-80 compatibility"
 
@@ -3076,16 +3094,20 @@
     "if I represent a regular file, copy it.
      Otherwise, copy the directory and recursively
      all of its subfiles/subdirectories.
-     Raises an exception if not successful."
-
-    |ok d|
-
+
+     Raises an exception if not successful.
+     Do not resolve symbolic links.
+     If a whole directory is to be copied and the destination directory 
+     does not exist, it will be created."
+
+    |ok destinationFilename|
+
+    destinationFilename := destination asFilename.
     self isDirectory ifFalse:[
-        d := destination asFilename.
-        d isDirectory ifTrue:[
-            d := d construct:self baseName.
+        destinationFilename isDirectory ifTrue:[
+            destinationFilename := destinationFilename construct:self baseName.
         ].
-        self copyTo:d.
+        self copyTo:destinationFilename.
         ^ self.
     ].
 
@@ -3095,12 +3117,16 @@
 
     ok := OperatingSystem 
             recursiveCopyDirectory:(self osNameForDirectory)
-            to:(destination asFilename osNameForDirectory).
+            to:(destinationFilename osNameForDirectory).
 
     ok ifFalse:[
-        self recursiveCopyWithoutOSCommandTo:destination
+        self recursiveCopyWithoutOSCommandTo:destinationFilename
     ].
 
+    "
+        '.' asFilename recursiveCopyTo:'/tmp/xxx'.
+    "
+
     "Created: / 05-05-1999 / 13:35:01 / cg"
     "Modified: / 31-05-1999 / 13:11:34 / cg"
     "Modified: / 29-07-2010 / 12:41:06 / sr"
@@ -3110,17 +3136,18 @@
     "if I represent a regular file, copy it.
      Otherwise, copy the directory and all of its subfiles/subdirectories.
      This one walks down the directory hierarchy, not using any OS command to do the copy.
-     Raises an exception if not successful."
+     Raises an exception if not successful.
+
+     Do not resolve symbolic links.
+     If a whole directory is to be copied and the destination directory 
+     does not exist, it will be created."
 
     |destinationFilename|
 
     destinationFilename := destination asFilename.
 
     self isDirectory ifTrue:[
-        destinationFilename exists ifTrue:[
-            destinationFilename := destinationFilename construct:self baseName.
-            destinationFilename makeDirectory.
-        ] ifFalse:[
+        destinationFilename exists ifFalse:[
             destinationFilename makeDirectory.
             destinationFilename accessRights:self accessRights.
         ].
@@ -3129,14 +3156,23 @@
             |src dst|
 
             src := self construct:aFilenameString.
+            dst := destinationFilename construct:aFilenameString.
+
             src isDirectory ifTrue:[
-                src recursiveCopyWithoutOSCommandTo:destinationFilename
+                src recursiveCopyWithoutOSCommandTo:dst
+            ] ifFalse:[src isSymbolicLink ifTrue:[                    
+                dst
+                    remove;
+                    createAsSymbolicLinkTo:src linkInfo path.
             ] ifFalse:[
-                src copyTo:(destinationFilename construct:aFilenameString)
-            ].
-        ]
+                src copyTo:dst.
+            ]].
+        ].
     ] ifFalse:[
-        self copyTo:destinationFilename
+        destinationFilename isDirectory ifTrue:[
+            destinationFilename := destinationFilename construct:self baseName.
+        ].
+        self copyTo:destinationFilename.
     ]
 
     "
@@ -6060,11 +6096,11 @@
 !Filename class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.431 2014-11-23 16:51:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.432 2014-11-27 16:48:48 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.431 2014-11-23 16:51:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.432 2014-11-27 16:48:48 stefan Exp $'
 ! !