Filename.st
changeset 16490 1be874f7ae34
parent 16485 a3dd0c8d395c
child 16492 0d3a253fe98d
equal deleted inserted replaced
16489:7d7c4d8c47fe 16490:1be874f7ae34
  3007      s close.
  3007      s close.
  3008      f moveTo:'./foo'
  3008      f moveTo:'./foo'
  3009     "
  3009     "
  3010 !
  3010 !
  3011 
  3011 
  3012 moveTo:newName
  3012 moveTo:newNameArg
  3013     "copy the file represented by the receiver, then delete it.
  3013     "copy the file represented by the receiver, then delete it.
  3014      This is different to renaming in case of cross device moves.
  3014      This is different to renaming in case of cross device moves.
  3015      Raise an exception if not successful.
  3015      Raise an exception if not successful.
  3016      (Notice, that a rename is tried first, in case of non-cross device move)"
  3016      (Notice, that a rename is tried first, in case of non-cross device move)"
  3017 
  3017 
       
  3018     |newName|
       
  3019 
       
  3020     newName := newNameArg asFilename.    
  3018     [self renameTo:newName] 
  3021     [self renameTo:newName] 
  3019         on:(OSErrorHolder inappropriateReferentSignal) 
  3022         on:(OSErrorHolder inappropriateReferentSignal) 
  3020         do:[:ex |
  3023         do:[:ex |
  3021             "handle renames accross device boundaries (Unix. cross device link)"
  3024             "handle renames accross device boundaries (Unix. cross device link)"
  3022             self isDirectory ifTrue:[
  3025             self isDirectory ifTrue:[
  3350      'foo' asFilename makeDirectory.
  3353      'foo' asFilename makeDirectory.
  3351      'foo' asFilename removeFile   
  3354      'foo' asFilename removeFile   
  3352     "
  3355     "
  3353 !
  3356 !
  3354 
  3357 
  3355 renameTo:newName
  3358 renameTo:newNameArg
  3356     "rename the file - the argument must be convertable to a String.
  3359     "rename the file - the argument must be convertable to a String.
  3357      Raises an exception if not successful.
  3360      Raises an exception if not successful.
  3358      If newName already exists, it will be replaced by myself."
  3361      If newName already exists, it will be replaced by myself."
  3359 
  3362 
  3360     |errno|
  3363     |errno newName|
  3361 
  3364 
       
  3365     newName := newNameArg asFilename.
  3362     (OperatingSystem 
  3366     (OperatingSystem 
  3363         renameFile:(self osNameForFile) 
  3367         renameFile:(self osNameForFile) 
  3364         to:(newName asFilename osNameForFile)
  3368         to:(newName osNameForFile)
  3365     ) ifFalse:[
  3369     ) ifFalse:[
  3366         errno := OperatingSystem lastErrorNumber.
  3370         errno := OperatingSystem lastErrorNumber.
  3367 
  3371 
  3368         self exists ifFalse:[
  3372         self exists ifFalse:[
  3369             ^ self fileNotFoundError:self
  3373             ^ self fileNotFoundError:self
  3370         ].
  3374         ].
  3371         (OperatingSystem errorHolderForNumber:errno) 
  3375         (OperatingSystem errorHolderForNumber:errno) 
  3372             parameter:newName asFilename;
  3376             parameter:newName;
  3373             reportError.
  3377             reportError.
  3374     ].
  3378     ].
  3375 
  3379 
  3376     "
  3380     "
  3377      '/tmp/foo' asFilename renameTo:'/tmp/bar'
  3381      '/tmp/foo' asFilename renameTo:'/tmp/bar'
  3400         accessRights := self accessRights.
  3404         accessRights := self accessRights.
  3401     ].
  3405     ].
  3402 
  3406 
  3403     [
  3407     [
  3404         "let the temp filename start with a ~ to make it invisible"    
  3408         "let the temp filename start with a ~ to make it invisible"    
  3405         tempStream := FileStream newTemporaryIn:newName directory nameTemplate:'~%1_%2'.
  3409         tempStream := FileStream newTemporaryIn:newName directory osNameForFile nameTemplate:'~%1_%2'.
  3406         [
  3410         [
  3407             "would be nice to keep the access rights of the original test suite"    
  3411             "would be nice to keep the access rights of the original test suite"    
  3408             tempStream fileName accessRights:accessRights.
  3412             tempStream fileName accessRights:accessRights.
  3409         ] on:OperatingSystem accessDeniedErrorSignal do:[:ex|
  3413         ] on:OperatingSystem accessDeniedErrorSignal do:[:ex|
  3410             "ignore the error - may occure when copying to a network drive"
  3414             "ignore the error - may occure when copying to a network drive"
  6134 ! !
  6138 ! !
  6135 
  6139 
  6136 !Filename class methodsFor:'documentation'!
  6140 !Filename class methodsFor:'documentation'!
  6137 
  6141 
  6138 version
  6142 version
  6139     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.415 2014-05-22 17:49:07 stefan Exp $'
  6143     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.416 2014-05-23 19:42:31 stefan Exp $'
  6140 !
  6144 !
  6141 
  6145 
  6142 version_CVS
  6146 version_CVS
  6143     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.415 2014-05-22 17:49:07 stefan Exp $'
  6147     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.416 2014-05-23 19:42:31 stefan Exp $'
  6144 ! !
  6148 ! !
  6145 
  6149 
  6146 
  6150 
  6147 Filename initialize!
  6151 Filename initialize!