[Pkg] The Trunk: Files-fbs.125.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Jul 12 19:06:35 UTC 2013


Frank Shearar uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-fbs.125.mcz

==================== Summary ====================

Name: Files-fbs.125
Author: fbs
Time: 12 July 2013, 8:06:14.937 pm
UUID: 0107eac6-3a03-1346-b4b0-cbc9655d4d04
Ancestors: Files-fbs.124

Break File's dependency on System by pushing error handling into System-Files. ReplaceExistingFileException turns a UIManager request into a resumable exception.

Files thus contains the definition of the exceptions, while System decorates these with basic error handling (in the default case).

=============== Diff against Files-fbs.124 ===============

Item was changed:
  ----- Method: FileDirectory>>rename:toBe: (in category 'file operations') -----
  rename: oldFileName toBe: newFileName 
  	"Rename the file of the given name to the new name. Fail if there is no file of the old name or if there is an existing file with the new name."
  	"Modified for retry after GC ar 3/21/98 18:09"
+ 	| replaceIt oldName newName |
- 	| selection oldName newName |
  	oldName := self fullNameFor: oldFileName.
  	newName := self fullNameFor: newFileName.
  	(self fileExists: oldFileName) ifFalse: [ ^ self error: 'Attempt to rename a non-existent file' ].
  	(self fileExists: newFileName) ifTrue:
+ 		[replaceIt := (ReplaceExistingFileException fileName: newFileName) signal.
+ 		replaceIt ifTrue: [ self deleteFileNamed: newFileName ]	ifFalse: [ ^ self ]].
- 		[ selection := UIManager default
- 			chooseFrom: #('delete version in target directory' 'cancel' )
- 			title: newFileName , ' already exists'.
- 		selection = 1
- 			ifTrue: [ self deleteFileNamed: newFileName ]
- 			ifFalse: [ ^ self ] ].
  	(StandardFileStream
  		retryWithGC:
  			[ self
  				primRename: oldName asVmPathName
  				to: newName asVmPathName ]
  		until: [ : result | result notNil ]
  		forFileNamed: oldName) ~~ nil ifTrue: [ ^ self ].
  	^ self error: 'Failed to rename file'!

Item was removed:
- ----- Method: FileDoesNotExistException>>defaultAction (in category 'exceptionDescription') -----
- defaultAction
- 	"The default action taken if the exception is signaled."
- 
- 	^self readOnly
- 		ifTrue: [StandardFileStream readOnlyFileDoesNotExistUserHandling: self fileName
- 			ifDebug: [super defaultAction]]
- 		ifFalse: [StandardFileStream fileDoesNotExistUserHandling: self fileName
- 			ifDebug: [super defaultAction]]
- !

Item was removed:
- ----- Method: FileExistsException>>defaultAction (in category 'exceptionDescription') -----
- defaultAction
- 	"The default action taken if the exception is signaled."
- 
- 	^ self fileClass fileExistsUserHandling: self fileName ifDebug: [super defaultAction]
- !

Item was added:
+ FileStreamException subclass: #ReplaceExistingFileException
+ 	instanceVariableNames: 'fileClass'
+ 	classVariableNames: ''
+ 	poolDictionaries: ''
+ 	category: 'Files-Exceptions'!

Item was added:
+ ----- Method: ReplaceExistingFileException>>messageText (in category 'exceptionDescription') -----
+ messageText
+ 	^ fileName , ' already exists'.!

Item was removed:
- ----- Method: StandardFileStream class>>fileDoesNotExistUserHandling:ifDebug: (in category 'error handling') -----
- fileDoesNotExistUserHandling: fullFileName ifDebug: debugBlock
- 
- 	| selection newName |
- 	selection := UIManager default chooseFrom: {
- 		'create a new file' translated.
- 		'choose another name' translated.
- 		'debug' translated.
- 		'cancel' translated
- 	} title: (FileDirectory localNameFor: fullFileName) , '
- does not exist.'.
- 	selection = 1 ifTrue:
- 		[^ self new open: fullFileName forWrite: true].
- 	selection = 2 ifTrue:
- 		[ newName := UIManager default request: 'Enter a new file name'
- 						initialAnswer:  fullFileName.
- 		^ self oldFileNamed:
- 			(self fullName: newName)].
- 	selection = 3 ifTrue: [^ debugBlock value].
- 	self halt!

Item was removed:
- ----- Method: StandardFileStream class>>fileExistsUserHandling:ifDebug: (in category 'error handling') -----
- fileExistsUserHandling: fullFileName ifDebug: debugBlock
- 	| dir localName choice newName newFullFileName |
- 	dir := FileDirectory forFileName: fullFileName.
- 	localName := FileDirectory localNameFor: fullFileName.
- 	choice := (UIManager default 
- 		chooseFrom: #('overwrite that file' 'append (risky!!!!)' 'choose another name' 'debug' 'cancel')
- 		title: localName, ' already exists.').
- 
- 	choice = 1 ifTrue: [
- 		dir deleteFileNamed: localName
- 			ifAbsent: [self error: 'Could not delete the old version of that file'].
- 		^ self new open: fullFileName forWrite: true].
- 
- 	choice = 2 ifTrue: [
- 		^ (self new open: fullFileName forWrite: true) setToEnd].
- 
- 	choice = 3 ifTrue: [
- 		newName := UIManager default request: 'Enter a new file name' initialAnswer: fullFileName.
- 		newFullFileName := self fullName: newName.
- 		^ self newFileNamed: newFullFileName].
- 
- 	choice = 4 ifTrue: [^ debugBlock value].
- 
- 	self error: 'Please close this to abort file opening'!

Item was removed:
- ----- Method: StandardFileStream class>>readOnlyFileDoesNotExistUserHandling:ifDebug: (in category 'error handling') -----
- readOnlyFileDoesNotExistUserHandling: fullFileName ifDebug: debugBlock
- 
- 	| dir files choices selection newName fileName |
- 	dir := FileDirectory forFileName: fullFileName.
- 	files := dir fileNames.
- 	fileName := FileDirectory localNameFor: fullFileName.
- 	choices := fileName correctAgainst: files.
- 	choices add: 'Choose another name'.
- 	choices add: 'Debug'.
- 	choices add: 'Cancel'.
- 	selection := UIManager default chooseFrom: choices lines: (Array with: 5)
- 		title: (FileDirectory localNameFor: fullFileName), '
- does not exist.'.
- 	selection = choices size ifTrue:["cancel" ^ nil "should we raise another exception here?"].
- 	selection < (choices size - 1) ifTrue: [
- 		newName := (dir pathName , FileDirectory slash , (choices at: selection))].
- 	selection = (choices size - 2) ifTrue: [
- 		newName := UIManager default 
- 							request: 'Enter a new file name' 
- 							initialAnswer: fileName].
- 	selection = (choices size - 1) ifTrue: [^ debugBlock value].
- 	newName = '' ifFalse: [^ self readOnlyFileNamed: (self fullName: newName)].
- 	^ self error: 'Could not open a file'!



More information about the Packages mailing list