file exists error handling
authortm
Thu, 24 Jul 2003 11:29:43 +0200
changeset 1284 57550436b55b
parent 1283 974c05685dc6
child 1285 0b70d88e4a74
file exists error handling
FileURI.st
FtpURI.st
--- a/FileURI.st	Mon Jul 21 11:12:36 2003 +0200
+++ b/FileURI.st	Thu Jul 24 11:29:43 2003 +0200
@@ -279,8 +279,18 @@
                 ex reject
             ].    
             fileName directory recursiveMakeDirectory.
+            self exists ifTrue:[ |infoStream|
+                infoStream := '' writeStream.
+                self publicPrintOn:infoStream.
+                self error:('Local write: Datei %1 already exists!!' bindWith:infoStream contents).
+            ].
             stream := toFileName writeStream.
         ] do:[
+            self exists ifTrue:[ |infoStream|
+                infoStream := '' writeStream.
+                self publicPrintOn:infoStream.
+                self error:('Local write: Datei %1 already exists!!' bindWith:infoStream contents).
+            ].
             stream := toFileName writeStream.
         ].
         aBlock value:stream value:self class attributes.
@@ -304,5 +314,5 @@
 !FileURI class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/FileURI.st,v 1.8 2003-07-13 22:50:00 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/FileURI.st,v 1.9 2003-07-24 09:29:43 tm Exp $'
 ! !
--- a/FtpURI.st	Mon Jul 21 11:12:36 2003 +0200
+++ b/FtpURI.st	Thu Jul 24 11:29:43 2003 +0200
@@ -77,10 +77,18 @@
 
 pathExists:aPathname ftpClient:aFtpClient
 
-    |list|
+    |stream ok|
+
+    FTPClient fileNotFoundErrorSignal handle:[:ex|] do:[
+        stream := aFtpClient getStreamFor:aPathname.
+    ].
 
-    list := aFtpClient list:aPathname.
-    ^ list contains:[:aLine| (aLine asCollectionOfWords last) = aPathname ] 
+    ok := stream notNil.
+    stream notNil ifTrue:[
+        stream close
+    ].
+
+    ^ ok
 !
 
 pathExistsFtp:aFtpClient
@@ -232,14 +240,14 @@
 
                 renameBlock notNil ifTrue:[ |renameFilenameString|
                     renameFilenameString := renameBlock value:eachBaseName.
-                    [
+"/                    [
                         ftp rename:eachBaseName to:renameFilenameString.
-                    ] on:FTPClient fileErrorSignal do:[:ex|
-                        "rename failed, maybe file already exists"
-                        renameFilenameString := renameFilenameString, '.', 
-                            (AbsoluteTime now printStringFormat:'%(year)%(mon)%(day)%h%m%s').
-                        ftp rename:eachBaseName to:renameFilenameString.
-                    ]
+"/                    ] on:FTPClient fileErrorSignal do:[:ex|
+"/                        "rename failed, maybe file already exists"
+"/                        renameFilenameString := renameFilenameString, '.', 
+"/                            (AbsoluteTime now printStringFormat:'%(year)%(mon)%(day)%h%m%s').
+"/                        ftp rename:eachBaseName to:renameFilenameString.
+"/                    ].
                 ].
             ].
         ].
@@ -314,6 +322,11 @@
     self connectThenDo:[:ftp| |stream|
         [
             [
+                (self pathExists:path ftpClient:ftp) ifTrue:[ |infoStream|
+                    infoStream := '' writeStream.
+                    self publicPrintOn:infoStream.
+                    self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents).
+                ].
                 stream := ftp putStreamFor:toPath.
             ] on:FTPClient filePutErrorSignal do:[:ex|
                 doCreate ifFalse:[
@@ -325,6 +338,11 @@
                     ftp mkdir:directory.
                 ].
                 ftp cd:directory.
+                (self pathExists:path ftpClient:ftp) ifTrue:[ |infoStream|
+                    infoStream := '' writeStream.
+                    self publicPrintOn:infoStream.
+                    self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents).
+                ].
                 stream := ftp putStreamFor:toPath.
             ].
             aBlock value:stream value:self class attributes.
@@ -357,5 +375,5 @@
 !FtpURI class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/FtpURI.st,v 1.11 2003-07-14 13:03:51 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/FtpURI.st,v 1.12 2003-07-24 09:29:33 tm Exp $'
 ! !