*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Mon, 02 Mar 2009 16:02:35 +0100
changeset 8557 9b5fdaaad07d
parent 8556 33a3a06f329c
child 8558 a85166102cb7
*** empty log message ***
FileOperation.st
--- a/FileOperation.st	Mon Mar 02 15:59:41 2009 +0100
+++ b/FileOperation.st	Mon Mar 02 16:02:35 2009 +0100
@@ -202,7 +202,7 @@
     "return true, if the file should be moved/copied.
      If oldFile exists, ask user.
      If withRemoveIfSame is true, two additional possible values are returned:
-	#removeSource and #removeDestination.
+        #removeSource and #removeDestination.
     "
 
     |msg oldSize newSize sameContents resources sourceType destType|
@@ -214,53 +214,54 @@
     sameContents := false.
 
     newFile isDirectory ifTrue:[
-	oldFile isDirectory ifTrue:[
-	    "/ could (should?) recursively look for same contents here...
-	].
+        oldFile isDirectory ifTrue:[
+            "/ could (should?) recursively look for same contents here...
+        ].
     ] ifFalse:[
-	oldFile isDirectory ifFalse:[
-	    sameContents := oldSize = newSize and:[oldFile sameContentsAs:newFile].
-	]
+        oldFile isDirectory ifFalse:[
+            sameContents := oldSize = newSize and:[oldFile sameContentsAs:newFile].
+        ]
     ].
 
+    resources := AbstractFileBrowser classResources.
+
     "/ for now:
     oldFile isDirectory ~~ newFile isDirectory ifTrue:[
-	Dialog warn:(resources string:'Will not overwrite directory with file and vice versa.').
-	^  false.
+        Dialog warn:(resources string:'Will not overwrite directory with file and vice versa.').
+        ^  false.
     ].
 
     sourceType := newFile isDirectory ifTrue:'directory' ifFalse:'file'.
     destType := oldFile isDirectory ifTrue:'directory' ifFalse:'file'.
 
     sameContents ifTrue:[
-	msg := 'Overwrite existing destination %7:\\  %1\    size: %3 of %2\\with source (same contents):\\  %4\    size: %6 of %5'.
+        msg := 'Overwrite existing destination %7:\\  %1\    size: %3 of %2\\with source (same contents):\\  %4\    size: %6 of %5'.
     ] ifFalse:[
-	msg := 'Overwrite existing destination %7:\\  %1\    size: %3 of %2\\with source:\\  %4\    size: %6 of %5'.
+        msg := 'Overwrite existing destination %7:\\  %1\    size: %3 of %2\\with source:\\  %4\    size: %6 of %5'.
     ].
 
-    resources := AbstractFileBrowser classResources.
     msg := resources
-	    stringWithCRs:msg
-	    withArgs:(Array
-		with:newFile asString allBold
-		with:(newFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s')
-		with:newSize
-		with:oldFile asString allBold
-		with:(oldFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s')
-		with:oldSize
-		with:destType).
+            stringWithCRs:msg
+            withArgs:(Array
+                with:newFile asString allBold
+                with:(newFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s')
+                with:newSize
+                with:oldFile asString allBold
+                with:(oldFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s')
+                with:oldSize
+                with:destType).
 
     (sameContents and:[withRemoveIfSame]) ifTrue:[
-	^ OptionBox
-		  request:msg
-		  label:(resources string:'Overwrite existing file')
-		  image:(YesNoBox iconBitmap)
-		  buttonLabels:(resources array:( #('No' 'Remove Source' 'Remove Destination' 'Yes' ) , (withCancel ifTrue:[#('Cancel')] ifFalse:[#()])))
-		  values:#( false #removeSource #removeDestination true )
-		  default:#removeSource
-		  onCancel:nil.
+        ^ OptionBox
+                  request:msg
+                  label:(resources string:'Overwrite existing file')
+                  image:(YesNoBox iconBitmap)
+                  buttonLabels:(resources array:( #('No' 'Remove Source' 'Remove Destination' 'Yes' ) , (withCancel ifTrue:[#('Cancel')] ifFalse:[#()])))
+                  values:#( false #removeSource #removeDestination true )
+                  default:#removeSource
+                  onCancel:nil.
     ] ifFalse:[
-	^ Dialog confirm:msg withCancel:withCancel.
+        ^ Dialog confirm:msg withCancel:withCancel.
     ].
 ! !
 
@@ -518,104 +519,104 @@
     out := destFile writeStream binary.
 
     doWrite := [:n |
-		nWritten := out nextPutBytes:n from:buffer startingAt:1.
-		offset := offset + nWritten.
-		nWritten ~= n ifTrue:[
-		    self error:'Write error'.
-		].
-	       ].
+                nWritten := out nextPutBytes:n from:buffer startingAt:1.
+                offset := offset + nWritten.
+                nWritten ~= n ifTrue:[
+                    self error:'Write error'.
+                ].
+               ].
 
     doRead := [:n |
-		ReadError handle:[:ex |
-		    nRead := 0.
-		    in position:offset.
-		] do:[
-		    nRead := in nextBytes:n into:buffer startingAt:1.
-		].
-	       ].
+                ReadError handle:[:ex |
+                    nRead := 0.
+                    in position:offset.
+                ] do:[
+                    nRead := in nextBytes:n into:buffer startingAt:1.
+                ].
+               ].
 
     [
-	[offset < fileSize] whileTrue:[
-	    doRead value:(bufferSize min:(fileSize - offset)).
-	    nRead > 0 ifTrue:[
-		lostStart notNil ifTrue:[
-		    Transcript showCR:'CORRUPT: ',(lostStart printString),' .. ',(lostEnd printString).
-		    lostStart := nil.
-		].
-		doWrite value:nRead.
-	    ].
+        [offset < fileSize] whileTrue:[
+            doRead value:(bufferSize min:(fileSize - offset)).
+            nRead > 0 ifTrue:[
+                lostStart notNil ifTrue:[
+                    Transcript showCR:'CORRUPT: ',(lostStart printString),' .. ',(lostEnd printString).
+                    lostStart := nil.
+                ].
+                doWrite value:nRead.
+            ].
 
-	    nRead == (bufferSize min:(fileSize - offset)) ifTrue:[
-		bufferSize < buffer size ifTrue:[
-		    bufferSize := bufferSize * 2.
-		].
-	    ] ifFalse:[
-		nRead == 0 ifTrue:[
-		    "/ try reading single blocks for a while...
-		    nSingle := 512.
-		    [
-			nSingle > 0
-			and:[
-			    doRead value:256.
-			    nRead > 0]
-		    ] whileTrue:[
-			lostStart notNil ifTrue:[
-			    Transcript showCR:'CORRUPT: ',(lostStart printString),' .. ',(lostEnd printString).
-			    lostStart := nil.
-			].
+            nRead == (bufferSize min:(fileSize - offset)) ifTrue:[
+                bufferSize < buffer size ifTrue:[
+                    bufferSize := bufferSize * 2.
+                ].
+            ] ifFalse:[
+                nRead == 0 ifTrue:[
+                    "/ try reading single blocks for a while...
+                    nSingle := 16.
+                    [
+                        nSingle > 0
+                        and:[
+                            doRead value:256.
+                            nRead > 0]
+                    ] whileTrue:[
+                        lostStart notNil ifTrue:[
+                            Transcript showCR:'CORRUPT: ',(lostStart printString),' .. ',(lostEnd printString).
+                            lostStart := nil.
+                        ].
 Transcript showCR:'single block at ',offset printString.
-			doWrite value:nRead.
-			nSingle := nSingle - 1.
-		    ].
+                        doWrite value:nRead.
+                        nSingle := nSingle - 1.
+                    ].
 
-		    nRead == 0 ifTrue:[
-			in2 := sourceFile readStream binary.
-			Error handle:[:ex |
-			] do:[
-			    in2 position:0.
-			    in2 nextBytes:buffer size into:buffer startingAt:1.
-			].
-			seekFailed := false.
-			Error handle:[:ex |
-			    seekFailed := true.
-			] do:[
-			    in2 position:offset.
-			].
-			seekFailed ifTrue:[
-			    buffer from:1 to:256 put:0.
-			    Transcript showCR:'bad seek at ',offset printString.
-			    doWrite value:256.
-			] ifFalse:[
-			    in close.
-			    in := in2.
-			    doRead value:256.
-			    nRead > 0 ifTrue:[
+                    nRead == 0 ifTrue:[
+                        in2 := sourceFile readStream binary.
+                        Error handle:[:ex |
+                        ] do:[
+                            in2 position:0.
+                            in2 nextBytes:buffer size into:buffer startingAt:1.
+                        ].
+                        seekFailed := false.
+                        Error handle:[:ex |
+                            seekFailed := true.
+                        ] do:[
+                            in2 position:offset.
+                        ].
+                        seekFailed ifTrue:[
+                            buffer from:1 to:256 put:0.
+                            Transcript showCR:'bad seek at ',offset printString.
+                            doWrite value:256.
+                        ] ifFalse:[
+                            in close.
+                            in := in2.
+                            doRead value:256.
+                            nRead > 0 ifTrue:[
 Transcript showCR:'single after reopen at ',offset printString.
-				doWrite value:nRead.
-			    ] ifFalse:[
-				lostStart isNil ifTrue:[
-				    lostStart := lostEnd := offset.
-				] ifFalse:[
-				    lostEnd := offset.
-				].
-				buffer from:1 to:256 put:0.
+                                doWrite value:nRead.
+                            ] ifFalse:[
+                                lostStart isNil ifTrue:[
+                                    lostStart := lostEnd := offset.
+                                ] ifFalse:[
+                                    lostEnd := offset.
+                                ].
+                                buffer from:1 to:256 put:0.
 Transcript showCR:'bad at ',offset printString.
-				doWrite value:256.
-				bufferSize := 256.
-			    ].
-			]
-		    ]
-		].
-	    ].
-	    Transcript showCR:offset.
-	].
+                                doWrite value:256.
+                                bufferSize := 256.
+                            ].
+                        ]
+                    ]
+                ].
+            ].
+            Transcript showCR:offset.
+        ].
     ] ensure:[
-	in close.
-	out close.
+        in close.
+        out close.
     ].
     lostStart notNil ifTrue:[
-	Transcript showCR:'CORRUPT: ',(lostStart printString),' .. ',(lostEnd printString).
-	lostStart := nil.
+        Transcript showCR:'CORRUPT: ',(lostStart printString),' .. ',(lostEnd printString).
+        lostStart := nil.
     ].
 
     "Created: / 07-02-2007 / 18:40:32 / cg"
@@ -1507,5 +1508,5 @@
 !FileOperation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.82 2008-11-03 11:22:50 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.83 2009-03-02 15:02:35 cg Exp $'
 ! !