FtpURI.st
changeset 1264 650132956801
parent 1258 a0eda4db4dad
child 1265 f0ea5f786b16
--- a/FtpURI.st	Wed Jul 09 18:18:48 2003 +0200
+++ b/FtpURI.st	Thu Jul 10 11:42:47 2003 +0200
@@ -33,30 +33,6 @@
     ^ 'anonymous'
 ! !
 
-!FtpURI methodsFor:'file operations'!
-
-ftp:aFtpClient copyContentsOfStream:aReadStream toDestFilePath:aDestiantionPath
-
-    |writestream buffer n|
-
-    writestream := aFtpClient putStreamFor:aDestiantionPath.
-
-    (writestream notNil and:[writestream isWritable]) ifTrue:[
-        buffer := ByteArray new:(self class transferBufferSize).
-        [aReadStream atEnd] whileFalse:[
-            n := aReadStream nextBytes:(buffer size) into:buffer.
-            writestream isExternalStream ifTrue:[
-                writestream writeWait.
-            ].
-            writestream nextPutBytes:n from:buffer.
-        ].
-    ] ifFalse:[ 
-        OperatingSystem fileNotFoundErrorSignal
-            raiseRequestWith:aDestiantionPath
-            errorString:('Write: %1' bindWith:aDestiantionPath asString)
-    ].
-! !
-
 !FtpURI methodsFor:'ftp requests'!
 
 connectThenDo:aOneArgBlock
@@ -112,24 +88,6 @@
     ^ self pathExists:self path ftpClient:aFtpClient
 ! !
 
-!FtpURI methodsFor:'private'!
-
-ftp:aFtpClient moveStream:anOpenedStream ofPath:aSourcePath baseName:aBasename intoDir:aDirectoryPathName
-
-    |path dir|
-
-    dir := aDirectoryPathName asFilename.
-    path := (dir construct:aBasename) asString.
-    (self pathExists:path ftpClient:aFtpClient) ifTrue:[
-        path := AbsoluteTime now printString.
-        path := (dir construct:(aBasename, '-', path)) asString.
-    ].
-    anOpenedStream resetPosition.
-    self ftp:aFtpClient copyContentsOfStream:anOpenedStream toDestFilePath:path.
-    anOpenedStream close.
-    aFtpClient delete:aSourcePath.
-! !
-
 !FtpURI methodsFor:'stream access'!
 
 readStreamDo:aBlock
@@ -168,10 +126,10 @@
      The streams are closed after aBlock has been evaluated.
      Attributes may be the mime type (key #MIME)"
 
-    self readStreamsDo:aBlock thenRemove:false
+    self readStreamsDo:aBlock skipFilenamesWithSuffix:nil thenRemove:false
 !
 
-readStreamsDo:aBlock thenRemove:doRemoveSource
+readStreamsDo:aBlock skipFilenamesWithSuffix:aSuffix thenRemove:doRemoveSource
     "evaluate the block with a Collection of streams as first argument
      and a dictionary containing attributes as second argument,
      - a collection with a stream on a single file,
@@ -198,6 +156,28 @@
             list addAll:((ftp list) collect:[:aLine| aLine asCollectionOfWords last]).
         ].
 
+        requestDirectory ifFalse:[ |bName|
+            bName := self pathSegements last.
+            (bName startsWith:'*') ifTrue:[
+                list removeAll.
+                requestDirectory := true.
+                attributes at:#requestDirectory put:true.
+                ftp cd:(path asFilename directory) pathName.
+                list addAll:((ftp list) collect:[:aLine| aLine asCollectionOfWords last]).
+            ].
+            (bName startsWith:'*.') ifTrue:[ |rest|
+                rest := bName restAfter:$*.
+                (rest includesString:'*') ifTrue:[
+                    self error:'can''t resolve path:', self printString
+                ].
+                list := list select:[:str| str endsWith:rest ]
+            ].
+        ].
+
+        aSuffix size ~~ 0 ifTrue:[
+            list := list select:[:str| (str ensWith:aSuffix) not ]
+        ].
+
         list do:[:aPathName| |baseName stream|
             FTPClient fileErrorSignal handle:[:ex| 
                 "/ skip subdirectories and the summary of the list
@@ -244,6 +224,18 @@
     "
 !
 
+readStreamsDo:aBlock thenRemove:doRemoveSource
+    "evaluate the block with a Collection of streams as first argument
+     and a dictionary containing attributes as second argument,
+     - a collection with a stream on a single file,
+     - or a collection with streams on a directorie's files, but not recursive
+
+     The streams are closed after aBlock has been evaluated.
+     Attributes may be the mime type (key #MIME)"
+
+    self readStreamsDo:aBlock skipFilenamesWithSuffix:nil thenRemove:doRemoveSource
+!
+
 writeStreamDo:aBlock
     "use FTPClient for now"
 
@@ -272,5 +264,5 @@
 !FtpURI class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/FtpURI.st,v 1.3 2003-07-09 12:55:24 tm Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/FtpURI.st,v 1.4 2003-07-10 09:42:47 tm Exp $'
 ! !