Mantis - Squeak
Viewing Issue Advanced Details
4829 Kernel minor always 09-09-06 17:37 07-25-13 10:22
Krivanek  
FrankShearar  
normal  
resolved 3.10  
no change required  
none    
none  
0004829: [KernelImageOverride] FileDirectory rename:toBe:
FileDirectory >> rename:toBe:

original:

rename: oldFileName toBe: newFileName
    | selection oldName newName |
    "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"
    oldName := self fullNameFor: oldFileName.
    newName := self fullNameFor: newFileName.
    (StandardFileStream
        retryWithGC:[self primRename: oldName asVmPathName to: newName asVmPathName]
        until:[:result| result notNil]
        forFileNamed: oldName) ~~ nil ifTrue:[^self].
    (self fileExists: oldFileName) ifFalse:[
        ^self error:'Attempt to rename a non-existent file'.
    ].
    (self fileExists: newFileName) ifTrue:[
        selection := (PopUpMenu labels:
'delete old version
cancel')
                startUpWithCaption: 'Trying to rename a file to be
', newFileName , '
and it already exists.'.
        selection = 1 ifTrue:
            [self deleteFileNamed: newFileName.
            ^ self rename: oldFileName toBe: newFileName]].
    ^self error:'Failed to rename file'.

override:

rename: oldFileName toBe: newFileName
    | selection oldName newName |
    "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"
    oldName := self fullNameFor: oldFileName.
    newName := self fullNameFor: newFileName.
    (StandardFileStream
        retryWithGC:[self primRename: oldName asVmPathName to: newName asVmPathName]
        until:[:result| result notNil]
        forFileNamed: oldName) ~~ nil ifTrue:[^self].
    (self fileExists: oldFileName) ifFalse:[
        ^self error:'Attempt to rename a non-existent file'.
    ].
    (self fileExists: newFileName) ifTrue:[
        selection := UIManager default chooseFrom: #('delete old version' 'cancel') values: #(1 2) title: 'Trying to rename a file to be
', newFileName , '
and it already exists.'..
        selection = 1 ifTrue:
            [self deleteFileNamed: newFileName.
            ^ self rename: oldFileName toBe: newFileName]].
    ^self error:'Failed to rename file'.

UI dependent code replaced with UIManager message

Notes
(0014421)
FrankShearar   
07-25-13 10:22   
I replaced the UI reference with a resumable exception, ReplaceExistingFileException, in Files-fbs.125.