FileOperation.st
branchjv
changeset 17138 72bf03c1ff80
parent 17137 2c2f7c9fc909
parent 17121 0d404f4364cd
equal deleted inserted replaced
17137:2c2f7c9fc909 17138:72bf03c1ff80
   987 !
   987 !
   988 
   988 
   989 doCreateLinkFrom:oldPath to:newPathArg soft:symbolic
   989 doCreateLinkFrom:oldPath to:newPathArg soft:symbolic
   990     "actually create a soft or hard link"
   990     "actually create a soft or hard link"
   991 
   991 
   992     |resources err newPath newPathFile oldPathFile|
   992     |resources newPath newPathFile oldPathFile|
   993 
   993 
   994     newPath := newPathArg.
   994     newPath := newPathArg.
   995 
   995 
   996     resources := AbstractFileBrowser classResources.
   996     resources := AbstractFileBrowser classResources.
   997 
   997 
   998     (oldPath size == 0) ifTrue:[
   998     oldPath isNil ifTrue:[
   999 	self operationError:'Missing source'.
   999         self operationError:'Missing source'.
  1000 	^ self.
  1000         ^ self.
  1001     ].
  1001     ].
  1002     (newPath size == 0) ifTrue:[
  1002     newPath isNil ifTrue:[
  1003 	self operationError:'Missing link name (target)'.
  1003         self operationError:'Missing link name (target)'.
  1004 	^ self.
  1004         ^ self.
  1005     ].
  1005     ].
  1006 
  1006 
  1007     newPathFile := newPath asFilename.
  1007     newPathFile := newPath asFilename.
  1008     oldPathFile := oldPath asFilename.
  1008     oldPathFile := oldPath asFilename.
  1009 
  1009 
  1010     newPathFile exists ifTrue:[
  1010     newPathFile exists ifTrue:[
  1011 	newPathFile isDirectory ifTrue:[
  1011         newPathFile isDirectory ifTrue:[
  1012 	    newPathFile := newPathFile construct:(oldPathFile baseName).
  1012             newPathFile := newPathFile construct:(oldPathFile baseName).
  1013 	    newPath := newPathFile name.
  1013             newPath := newPathFile name.
  1014 	].
  1014         ].
  1015     ].
  1015     ].
  1016 
  1016 
  1017     newPathFile exists ifTrue:[
  1017     newPathFile exists ifTrue:[
  1018 	self operationError:(resources string:'%1 already exists' with:newPath allBold).
  1018         self operationError:(resources string:'%1 already exists' with:newPath allBold).
  1019 	^ self.
  1019         ^ self.
  1020     ].
  1020     ].
  1021     oldPathFile exists ifFalse:[
  1021     oldPathFile exists ifFalse:[
  1022 	symbolic ifTrue:[
  1022         symbolic ifTrue:[
  1023 	    oldPathFile isAbsolute ifTrue:[
  1023             oldPathFile isAbsolute ifTrue:[
  1024 		self operationError:(resources string:'%1 does not exist' with:oldPath allBold).
  1024                 self operationError:(resources string:'%1 does not exist' with:oldPath allBold).
  1025 		^ self.
  1025                 ^ self.
  1026 	    ].
  1026             ].
  1027 	    (newPathFile directory construct:oldPath) exists ifFalse:[
  1027             (newPathFile directory construct:oldPath) exists ifFalse:[
  1028 		Dialog warn:(resources string:'%1 does not exist (Warning only)' with:oldPath allBold).
  1028                 Dialog warn:(resources string:'%1 does not exist (Warning only)' with:oldPath allBold).
  1029 	    ].
  1029             ].
  1030 	] ifFalse:[
  1030         ] ifFalse:[
  1031 	    self operationError:(resources string:'%1 does not exist' with:oldPath allBold).
  1031             self operationError:(resources string:'%1 does not exist' with:oldPath allBold).
  1032 	    ^ self.
  1032             ^ self.
  1033 	].
  1033         ].
  1034     ].
  1034     ].
  1035     ((symbolic not) and:[oldPathFile isDirectory]) ifTrue:[
  1035     ((symbolic not) and:[oldPathFile isDirectory]) ifTrue:[
  1036 	self operationError:(resources string:'%1 is a directory' with:oldPath allBold).
  1036         self operationError:(resources string:'%1 is a directory' with:oldPath allBold).
  1037 	^ self.
  1037         ^ self.
  1038     ].
  1038     ].
  1039     ErrorSignal handle:[:ex |
  1039     ErrorSignal handle:[:ex |
  1040 	err := ex errorString.
  1040         self operationError:ex description.
  1041 	self operationError:err.
       
  1042     ] do:[
  1041     ] do:[
  1043 	symbolic ifTrue:[
  1042         symbolic ifTrue:[
  1044 	    OperatingSystem createSymbolicLinkFrom:oldPath to:newPath.
  1043             newPathFile createAsSymbolicLinkTo:oldPathFile.
  1045 	] ifFalse:[
  1044         ] ifFalse:[
  1046 	    OperatingSystem createHardLinkFrom:oldPath to:newPath
  1045             newPathFile createAsHardLinkTo:oldPathFile.
  1047 	].
  1046         ].
  1048 	self createdFile:newPathFile.
  1047         self createdFile:newPathFile.
  1049 	self result:true.
  1048         self result:true.
  1050     ].
  1049     ].
  1051 ! !
  1050 ! !
  1052 
  1051 
  1053 !FileOperation::Delete class methodsFor:'actions'!
  1052 !FileOperation::Delete class methodsFor:'actions'!
  1054 
  1053