Filename.st
changeset 5086 dbeb79c72b84
parent 5032 2eb84639ab45
child 5127 d35adfa010e4
--- a/Filename.st	Tue Dec 07 14:49:42 1999 +0100
+++ b/Filename.st	Tue Dec 07 15:14:56 1999 +0100
@@ -1731,6 +1731,45 @@
     "Modified: / 5.5.1999 / 13:41:21 / cg"
 !
 
+renameOrCopyTo:newName
+    "rename or copy the file - the argument must be convertable to a String.
+     Raises an exception if not successful.
+     This does basically the same as #renameTo:, with one exception:
+     if, under unix, the new fileName is on another device, a rename operation
+     fails, and #renameTo: raises an exception;
+     in contrast, this method falls back to copying the file."
+
+    |newFilename|
+
+    newFilename := newName asFilename.
+
+    (OperatingSystem 
+        renameFile:(self osNameForFile) 
+        to:(newFilename osNameForFile)
+    ) ifFalse:[
+        self exists ifFalse:[
+            ^ self fileNotFoundError:self
+        ].
+
+        OperatingSystem isUNIXlike ifTrue:[
+            OperatingSystem lastErrorSymbol == #EXDEV ifTrue:[
+                "/ try to copy - and remove the original
+                "/ this helps with cross-device renames.
+
+              self copyTo:newName.
+              ^ self
+          ].
+        ].
+        ^ self accessDeniedError:newName asFilename.
+    ].
+
+    "
+     '/tmp/foo' asFilename renameTo:'/tmp/bar'
+    "
+
+    "Modified: / 5.5.1999 / 13:41:27 / cg"
+!
+
 renameTo:newName
     "rename the file - the argument must be convertable to a String.
      Raises an exception if not successful."
@@ -3483,6 +3522,6 @@
 !Filename class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.171 1999-12-01 10:33:47 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.172 1999-12-07 14:14:56 cg Exp $'
 ! !
 Filename initialize!