Handle errors when renaming files.
authorStefan Vogel <sv@exept.de>
Wed, 24 Sep 1997 17:13:50 +0200
changeset 1331 73e712c85588
parent 1330 2d8c64367afc
child 1332 ede81999d902
Handle errors when renaming files. Get stderr when executing commands.
FBrowser.st
FileBrowser.st
--- a/FBrowser.st	Wed Sep 24 06:43:08 1997 +0200
+++ b/FBrowser.st	Wed Sep 24 17:13:50 1997 +0200
@@ -10,8 +10,6 @@
  hereby transferred.
 "
 
-'From Smalltalk/X, Version:3.2.10 on 22-sep-1997 at 10:04:11 pm'                !
-
 StandardSystemView subclass:#FileBrowser
 	instanceVariableNames:'labelView filterField fileListView subView currentDirectory
 		fileList checkBlock checkDelta timeOfLastCheck showLongList
@@ -1900,13 +1898,13 @@
      kill will make me raise the stopSignal when pressed
     "
     killButton 
-	action:[
-	    stream notNil ifTrue:[
-		access critical:[
-		    myProcess interruptWith:[stopSignal raise].
-		]
-	    ]
-	].
+        action:[
+            stream notNil ifTrue:[
+                access critical:[
+                    myProcess interruptWith:[stopSignal raise].
+                ]
+            ]
+        ].
 
     "
      pause makes me stop reading the commands output
@@ -1934,170 +1932,172 @@
     self label:(myName , ': executing ' , (command copyTo:(20 min:command size)) , ' ...').
     [
       self withWaitCursorDo:[
-	stopSignal catch:[
-	    startLine := subView cursorLine.
-	    startCol := subView cursorCol.
-
-	    "
-	     this can be a time consuming operation; therefore lower my priority
-	    "
-	    myProcess := Processor activeProcess.
-	    myPriority := myProcess priority.
-	    myProcess priority:(Processor userBackgroundPriority).
-
-	    stream := PipeStream 
-			readingFrom:command
-			inDirectory:currentDirectory.
-	    stream notNil ifTrue:[
-		[
-		    |codeView lines noPauseSema|
-
-		    stream buffered:true.
-		    codeView := subView.
-		    codeView unselect.
-
-		    replace ifTrue:[
-			codeView list:nil.
-			lnr := 1.
-		    ].
-
-		    stillReplacing := replace.
-
-		    [stream atEnd] whileFalse:[
-			pauseHolder value ifTrue:[
-			    "/    
-			    "/ allow interaction with
-			    "/ the codeView via the other windowGroup
-			    "/
-			    lowerFrameView windowGroup:(killButton windowGroup).
-
-			    "/
-			    "/ wait for pause to be turned off
-			    "/
-			    noPauseSema := Semaphore new.
-			    pauseHolder onChangeSend:#signal to:noPauseSema.
-			    noPauseSema wait.
-
-			    "/    
-			    "/ no interaction with the codeView ...
-			    "/
-			    lowerFrameView windowGroup:(self windowGroup).
-
-			] ifFalse:[
-			    (stream readWaitWithTimeoutMs:50) ifFalse:[
-				"
-				 data available; read up to 100 lines
-				 and insert as a single junk. This speeds up
-				 display of long output (less line-scrolling).
-				"
-				lines := OrderedCollection new:100.
-				line := stream nextLine.
-				line notNil ifTrue:[lines add:line].
-
-				[stream atEnd not
-				and:[stream canReadWithoutBlocking
-				and:[lines size < 100]]] whileTrue:[
-				    line := stream nextLine.
-				    line notNil ifTrue:[lines add:line].
-				].
-
-				"
-				 need this critical section; otherwise,
-				 we could get the signal while waiting for
-				 an expose event ...
-				"
-				access critical:[                        
-				    lines size > 0 ifTrue:[
-					stillReplacing ifTrue:[
-					    lines do:[:line |
-						codeView at:lnr put:line withTabsExpanded.
-						codeView cursorToBottom; cursorDown:1.
-						lnr := lnr + 1.
-						lnr > codeView list size ifTrue:[
-						    stillReplacing := false
-						]
-					    ].
-					] ifFalse:[
-					    codeView insertLines:lines before:codeView cursorLine.
-					    codeView cursorDown:lines size.
-					]
-				    ].
-				].
-			    ].
-			].
-
-			"
-			 give others running at same prio a chance too
-			 (especially other FileBrowsers doing the same)
-			"
-			Processor yield
-		    ].
-		] valueNowOrOnUnwindDo:[
-		    stream shutDown "close". stream := nil.
-		].
-
-		"/
-		"/ the command could have changed the directory
-		"/
-		self updateCurrentDirectoryIfChanged
-	    ].
-	    replace ifTrue:[
-		subView modified:false.
-	    ].
-	]
+        stopSignal catch:[
+            startLine := subView cursorLine.
+            startCol := subView cursorCol.
+
+            "
+             this can be a time consuming operation; therefore lower my priority
+            "
+            myProcess := Processor activeProcess.
+            myPriority := myProcess priority.
+            myProcess priority:(Processor userBackgroundPriority).
+
+            stream := PipeStream 
+                        readingFrom:command
+                        errorDisposition:#inline
+                        inDirectory:currentDirectory.
+            stream notNil ifTrue:[
+                [
+                    |codeView lines noPauseSema|
+
+                    stream buffered:true.
+                    codeView := subView.
+                    codeView unselect.
+
+                    replace ifTrue:[
+                        codeView list:nil.
+                        lnr := 1.
+                    ].
+
+                    stillReplacing := replace.
+
+                    [stream atEnd] whileFalse:[
+                        pauseHolder value ifTrue:[
+                            "/    
+                            "/ allow interaction with
+                            "/ the codeView via the other windowGroup
+                            "/
+                            lowerFrameView windowGroup:(killButton windowGroup).
+
+                            "/
+                            "/ wait for pause to be turned off
+                            "/
+                            noPauseSema := Semaphore new.
+                            pauseHolder onChangeSend:#signal to:noPauseSema.
+                            noPauseSema wait.
+
+                            "/    
+                            "/ no interaction with the codeView ...
+                            "/
+                            lowerFrameView windowGroup:(self windowGroup).
+
+                        ] ifFalse:[
+                            (stream readWaitWithTimeoutMs:50) ifFalse:[
+                                "
+                                 data available; read up to 100 lines
+                                 and insert as a single junk. This speeds up
+                                 display of long output (less line-scrolling).
+                                "
+                                lines := OrderedCollection new:100.
+                                line := stream nextLine.
+                                line notNil ifTrue:[lines add:line].
+
+                                [stream atEnd not
+                                and:[stream canReadWithoutBlocking
+                                and:[lines size < 100]]] whileTrue:[
+                                    line := stream nextLine.
+                                    line notNil ifTrue:[lines add:line].
+                                ].
+
+                                "
+                                 need this critical section; otherwise,
+                                 we could get the signal while waiting for
+                                 an expose event ...
+                                "
+                                access critical:[                        
+                                    lines size > 0 ifTrue:[
+                                        stillReplacing ifTrue:[
+                                            lines do:[:line |
+                                                codeView at:lnr put:line withTabsExpanded.
+                                                codeView cursorToBottom; cursorDown:1.
+                                                lnr := lnr + 1.
+                                                lnr > codeView list size ifTrue:[
+                                                    stillReplacing := false
+                                                ]
+                                            ].
+                                        ] ifFalse:[
+                                            codeView insertLines:lines before:codeView cursorLine.
+                                            codeView cursorDown:lines size.
+                                        ]
+                                    ].
+                                ].
+                            ].
+                        ].
+
+                        "
+                         give others running at same prio a chance too
+                         (especially other FileBrowsers doing the same)
+                        "
+                        Processor yield
+                    ].
+                ] valueNowOrOnUnwindDo:[
+                    stream shutDown "close". stream := nil.
+                ].
+
+                "/
+                "/ the command could have changed the directory
+                "/
+                self updateCurrentDirectoryIfChanged
+            ].
+            replace ifTrue:[
+                subView modified:false.
+            ].
+        ]
       ]
     ] valueNowOrOnUnwindDo:[
-	|wg|
-
-	self label:myName; iconLabel:myName.
-	myProcess notNil ifTrue:[myProcess priority:myPriority].
-
-	"
-	 hide the button, and make sure it will stay
-	 hidden when we are realized again
-	"
-	killButton beInvisible.
-	pauseToggle beInvisible.
-
-	commandView beVisible.
-
-	"
-	 remove the killButton from its group
-	 (otherwise, it will be destroyed when we shut down the group)
-	"
-	wg := killButton windowGroup.
-	killButton windowGroup:nil.
-	pauseToggle windowGroup:nil.
-
-	"
-	 shut down the kill buttons windowgroup
-	"
-	wg notNil ifTrue:[
-	    wg process terminate.
-	].
-	"
-	 clear its action (actually not needed, but
-	 releases reference to thisContext earlier)
-	"
-	killButton action:nil.
-
-	"/    
-	"/ allow interaction with the codeView
-	"/ (bring it back into my group)
-	"/
-	lowerFrameView windowGroup:(self windowGroup).
+        |wg|
+
+        self label:myName; iconLabel:myName.
+        myProcess notNil ifTrue:[myProcess priority:myPriority].
+
+        "
+         hide the button, and make sure it will stay
+         hidden when we are realized again
+        "
+        killButton beInvisible.
+        pauseToggle beInvisible.
+
+        commandView beVisible.
+
+        "
+         remove the killButton from its group
+         (otherwise, it will be destroyed when we shut down the group)
+        "
+        wg := killButton windowGroup.
+        killButton windowGroup:nil.
+        pauseToggle windowGroup:nil.
+
+        "
+         shut down the kill buttons windowgroup
+        "
+        wg notNil ifTrue:[
+            wg process terminate.
+        ].
+        "
+         clear its action (actually not needed, but
+         releases reference to thisContext earlier)
+        "
+        killButton action:nil.
+
+        "/    
+        "/ allow interaction with the codeView
+        "/ (bring it back into my group)
+        "/
+        lowerFrameView windowGroup:(self windowGroup).
     ].
 
     currentFileName isNil ifTrue:[
-	subView modified:false.
+        subView modified:false.
     ].
 
     subView size > 10000 ifTrue:[
-	self warn:'text quite large now - please cut off some lines'
+        self warn:'text quite large now - please cut off some lines'
     ]
 
     "Modified: 21.9.1995 / 11:18:46 / claus"
     "Modified: 20.8.1997 / 19:09:09 / cg"
+    "Modified: 24.9.1997 / 09:34:42 / stefan"
 !
 
 imageAction:aFilename
@@ -2882,21 +2882,27 @@
 !
 
 doRename:oldName to:newName
-    "rename file(s) (or directories)"
+    "rename a file (or directory)"
 
     |old new|
 
     (oldName notNil and:[newName notNil]) ifTrue:[
-	(oldName isBlank or:[newName isBlank]) ifFalse:[
-	    old := currentDirectory filenameFor:oldName.
-	    new := currentDirectory filenameFor:newName.
-	    old renameTo:new.
-	    self updateCurrentDirectoryIfChanged.
-	]
+        (oldName isBlank or:[newName isBlank]) ifFalse:[
+            old := currentDirectory filenameFor:oldName.
+            new := currentDirectory filenameFor:newName.
+            OperatingSystem errorSignal handle:[:ex|
+                self showAlert:(resources string:'cannot rename file ''%1'' to %2 !!' 
+                                          with:oldName with:newName)
+                          with:(OperatingSystem lastErrorString)
+            ] do:[
+                old renameTo:new.
+            ].
+            self updateCurrentDirectoryIfChanged.
+        ]
     ]
 
     "Modified: 23.4.1997 / 13:19:37 / cg"
-    "Modified: 18.9.1997 / 14:35:14 / stefan"
+    "Modified: 24.9.1997 / 09:20:00 / stefan"
 ! !
 
 !FileBrowser methodsFor:'private - file type & info'!
@@ -3928,5 +3934,5 @@
 !FileBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Attic/FBrowser.st,v 1.197 1997-09-24 04:43:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Attic/FBrowser.st,v 1.198 1997-09-24 15:13:50 stefan Exp $'
 ! !
--- a/FileBrowser.st	Wed Sep 24 06:43:08 1997 +0200
+++ b/FileBrowser.st	Wed Sep 24 17:13:50 1997 +0200
@@ -10,8 +10,6 @@
  hereby transferred.
 "
 
-'From Smalltalk/X, Version:3.2.10 on 22-sep-1997 at 10:04:11 pm'                !
-
 StandardSystemView subclass:#FileBrowser
 	instanceVariableNames:'labelView filterField fileListView subView currentDirectory
 		fileList checkBlock checkDelta timeOfLastCheck showLongList
@@ -1900,13 +1898,13 @@
      kill will make me raise the stopSignal when pressed
     "
     killButton 
-	action:[
-	    stream notNil ifTrue:[
-		access critical:[
-		    myProcess interruptWith:[stopSignal raise].
-		]
-	    ]
-	].
+        action:[
+            stream notNil ifTrue:[
+                access critical:[
+                    myProcess interruptWith:[stopSignal raise].
+                ]
+            ]
+        ].
 
     "
      pause makes me stop reading the commands output
@@ -1934,170 +1932,172 @@
     self label:(myName , ': executing ' , (command copyTo:(20 min:command size)) , ' ...').
     [
       self withWaitCursorDo:[
-	stopSignal catch:[
-	    startLine := subView cursorLine.
-	    startCol := subView cursorCol.
-
-	    "
-	     this can be a time consuming operation; therefore lower my priority
-	    "
-	    myProcess := Processor activeProcess.
-	    myPriority := myProcess priority.
-	    myProcess priority:(Processor userBackgroundPriority).
-
-	    stream := PipeStream 
-			readingFrom:command
-			inDirectory:currentDirectory.
-	    stream notNil ifTrue:[
-		[
-		    |codeView lines noPauseSema|
-
-		    stream buffered:true.
-		    codeView := subView.
-		    codeView unselect.
-
-		    replace ifTrue:[
-			codeView list:nil.
-			lnr := 1.
-		    ].
-
-		    stillReplacing := replace.
-
-		    [stream atEnd] whileFalse:[
-			pauseHolder value ifTrue:[
-			    "/    
-			    "/ allow interaction with
-			    "/ the codeView via the other windowGroup
-			    "/
-			    lowerFrameView windowGroup:(killButton windowGroup).
-
-			    "/
-			    "/ wait for pause to be turned off
-			    "/
-			    noPauseSema := Semaphore new.
-			    pauseHolder onChangeSend:#signal to:noPauseSema.
-			    noPauseSema wait.
-
-			    "/    
-			    "/ no interaction with the codeView ...
-			    "/
-			    lowerFrameView windowGroup:(self windowGroup).
-
-			] ifFalse:[
-			    (stream readWaitWithTimeoutMs:50) ifFalse:[
-				"
-				 data available; read up to 100 lines
-				 and insert as a single junk. This speeds up
-				 display of long output (less line-scrolling).
-				"
-				lines := OrderedCollection new:100.
-				line := stream nextLine.
-				line notNil ifTrue:[lines add:line].
-
-				[stream atEnd not
-				and:[stream canReadWithoutBlocking
-				and:[lines size < 100]]] whileTrue:[
-				    line := stream nextLine.
-				    line notNil ifTrue:[lines add:line].
-				].
-
-				"
-				 need this critical section; otherwise,
-				 we could get the signal while waiting for
-				 an expose event ...
-				"
-				access critical:[                        
-				    lines size > 0 ifTrue:[
-					stillReplacing ifTrue:[
-					    lines do:[:line |
-						codeView at:lnr put:line withTabsExpanded.
-						codeView cursorToBottom; cursorDown:1.
-						lnr := lnr + 1.
-						lnr > codeView list size ifTrue:[
-						    stillReplacing := false
-						]
-					    ].
-					] ifFalse:[
-					    codeView insertLines:lines before:codeView cursorLine.
-					    codeView cursorDown:lines size.
-					]
-				    ].
-				].
-			    ].
-			].
-
-			"
-			 give others running at same prio a chance too
-			 (especially other FileBrowsers doing the same)
-			"
-			Processor yield
-		    ].
-		] valueNowOrOnUnwindDo:[
-		    stream shutDown "close". stream := nil.
-		].
-
-		"/
-		"/ the command could have changed the directory
-		"/
-		self updateCurrentDirectoryIfChanged
-	    ].
-	    replace ifTrue:[
-		subView modified:false.
-	    ].
-	]
+        stopSignal catch:[
+            startLine := subView cursorLine.
+            startCol := subView cursorCol.
+
+            "
+             this can be a time consuming operation; therefore lower my priority
+            "
+            myProcess := Processor activeProcess.
+            myPriority := myProcess priority.
+            myProcess priority:(Processor userBackgroundPriority).
+
+            stream := PipeStream 
+                        readingFrom:command
+                        errorDisposition:#inline
+                        inDirectory:currentDirectory.
+            stream notNil ifTrue:[
+                [
+                    |codeView lines noPauseSema|
+
+                    stream buffered:true.
+                    codeView := subView.
+                    codeView unselect.
+
+                    replace ifTrue:[
+                        codeView list:nil.
+                        lnr := 1.
+                    ].
+
+                    stillReplacing := replace.
+
+                    [stream atEnd] whileFalse:[
+                        pauseHolder value ifTrue:[
+                            "/    
+                            "/ allow interaction with
+                            "/ the codeView via the other windowGroup
+                            "/
+                            lowerFrameView windowGroup:(killButton windowGroup).
+
+                            "/
+                            "/ wait for pause to be turned off
+                            "/
+                            noPauseSema := Semaphore new.
+                            pauseHolder onChangeSend:#signal to:noPauseSema.
+                            noPauseSema wait.
+
+                            "/    
+                            "/ no interaction with the codeView ...
+                            "/
+                            lowerFrameView windowGroup:(self windowGroup).
+
+                        ] ifFalse:[
+                            (stream readWaitWithTimeoutMs:50) ifFalse:[
+                                "
+                                 data available; read up to 100 lines
+                                 and insert as a single junk. This speeds up
+                                 display of long output (less line-scrolling).
+                                "
+                                lines := OrderedCollection new:100.
+                                line := stream nextLine.
+                                line notNil ifTrue:[lines add:line].
+
+                                [stream atEnd not
+                                and:[stream canReadWithoutBlocking
+                                and:[lines size < 100]]] whileTrue:[
+                                    line := stream nextLine.
+                                    line notNil ifTrue:[lines add:line].
+                                ].
+
+                                "
+                                 need this critical section; otherwise,
+                                 we could get the signal while waiting for
+                                 an expose event ...
+                                "
+                                access critical:[                        
+                                    lines size > 0 ifTrue:[
+                                        stillReplacing ifTrue:[
+                                            lines do:[:line |
+                                                codeView at:lnr put:line withTabsExpanded.
+                                                codeView cursorToBottom; cursorDown:1.
+                                                lnr := lnr + 1.
+                                                lnr > codeView list size ifTrue:[
+                                                    stillReplacing := false
+                                                ]
+                                            ].
+                                        ] ifFalse:[
+                                            codeView insertLines:lines before:codeView cursorLine.
+                                            codeView cursorDown:lines size.
+                                        ]
+                                    ].
+                                ].
+                            ].
+                        ].
+
+                        "
+                         give others running at same prio a chance too
+                         (especially other FileBrowsers doing the same)
+                        "
+                        Processor yield
+                    ].
+                ] valueNowOrOnUnwindDo:[
+                    stream shutDown "close". stream := nil.
+                ].
+
+                "/
+                "/ the command could have changed the directory
+                "/
+                self updateCurrentDirectoryIfChanged
+            ].
+            replace ifTrue:[
+                subView modified:false.
+            ].
+        ]
       ]
     ] valueNowOrOnUnwindDo:[
-	|wg|
-
-	self label:myName; iconLabel:myName.
-	myProcess notNil ifTrue:[myProcess priority:myPriority].
-
-	"
-	 hide the button, and make sure it will stay
-	 hidden when we are realized again
-	"
-	killButton beInvisible.
-	pauseToggle beInvisible.
-
-	commandView beVisible.
-
-	"
-	 remove the killButton from its group
-	 (otherwise, it will be destroyed when we shut down the group)
-	"
-	wg := killButton windowGroup.
-	killButton windowGroup:nil.
-	pauseToggle windowGroup:nil.
-
-	"
-	 shut down the kill buttons windowgroup
-	"
-	wg notNil ifTrue:[
-	    wg process terminate.
-	].
-	"
-	 clear its action (actually not needed, but
-	 releases reference to thisContext earlier)
-	"
-	killButton action:nil.
-
-	"/    
-	"/ allow interaction with the codeView
-	"/ (bring it back into my group)
-	"/
-	lowerFrameView windowGroup:(self windowGroup).
+        |wg|
+
+        self label:myName; iconLabel:myName.
+        myProcess notNil ifTrue:[myProcess priority:myPriority].
+
+        "
+         hide the button, and make sure it will stay
+         hidden when we are realized again
+        "
+        killButton beInvisible.
+        pauseToggle beInvisible.
+
+        commandView beVisible.
+
+        "
+         remove the killButton from its group
+         (otherwise, it will be destroyed when we shut down the group)
+        "
+        wg := killButton windowGroup.
+        killButton windowGroup:nil.
+        pauseToggle windowGroup:nil.
+
+        "
+         shut down the kill buttons windowgroup
+        "
+        wg notNil ifTrue:[
+            wg process terminate.
+        ].
+        "
+         clear its action (actually not needed, but
+         releases reference to thisContext earlier)
+        "
+        killButton action:nil.
+
+        "/    
+        "/ allow interaction with the codeView
+        "/ (bring it back into my group)
+        "/
+        lowerFrameView windowGroup:(self windowGroup).
     ].
 
     currentFileName isNil ifTrue:[
-	subView modified:false.
+        subView modified:false.
     ].
 
     subView size > 10000 ifTrue:[
-	self warn:'text quite large now - please cut off some lines'
+        self warn:'text quite large now - please cut off some lines'
     ]
 
     "Modified: 21.9.1995 / 11:18:46 / claus"
     "Modified: 20.8.1997 / 19:09:09 / cg"
+    "Modified: 24.9.1997 / 09:34:42 / stefan"
 !
 
 imageAction:aFilename
@@ -2882,21 +2882,27 @@
 !
 
 doRename:oldName to:newName
-    "rename file(s) (or directories)"
+    "rename a file (or directory)"
 
     |old new|
 
     (oldName notNil and:[newName notNil]) ifTrue:[
-	(oldName isBlank or:[newName isBlank]) ifFalse:[
-	    old := currentDirectory filenameFor:oldName.
-	    new := currentDirectory filenameFor:newName.
-	    old renameTo:new.
-	    self updateCurrentDirectoryIfChanged.
-	]
+        (oldName isBlank or:[newName isBlank]) ifFalse:[
+            old := currentDirectory filenameFor:oldName.
+            new := currentDirectory filenameFor:newName.
+            OperatingSystem errorSignal handle:[:ex|
+                self showAlert:(resources string:'cannot rename file ''%1'' to %2 !!' 
+                                          with:oldName with:newName)
+                          with:(OperatingSystem lastErrorString)
+            ] do:[
+                old renameTo:new.
+            ].
+            self updateCurrentDirectoryIfChanged.
+        ]
     ]
 
     "Modified: 23.4.1997 / 13:19:37 / cg"
-    "Modified: 18.9.1997 / 14:35:14 / stefan"
+    "Modified: 24.9.1997 / 09:20:00 / stefan"
 ! !
 
 !FileBrowser methodsFor:'private - file type & info'!
@@ -3928,5 +3934,5 @@
 !FileBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.197 1997-09-24 04:43:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.198 1997-09-24 15:13:50 stefan Exp $'
 ! !