3074 |
3092 |
3075 recursiveCopyTo:destination |
3093 recursiveCopyTo:destination |
3076 "if I represent a regular file, copy it. |
3094 "if I represent a regular file, copy it. |
3077 Otherwise, copy the directory and recursively |
3095 Otherwise, copy the directory and recursively |
3078 all of its subfiles/subdirectories. |
3096 all of its subfiles/subdirectories. |
3079 Raises an exception if not successful." |
3097 |
3080 |
3098 Raises an exception if not successful. |
3081 |ok d| |
3099 Do not resolve symbolic links. |
3082 |
3100 If a whole directory is to be copied and the destination directory |
|
3101 does not exist, it will be created." |
|
3102 |
|
3103 |ok destinationFilename| |
|
3104 |
|
3105 destinationFilename := destination asFilename. |
3083 self isDirectory ifFalse:[ |
3106 self isDirectory ifFalse:[ |
3084 d := destination asFilename. |
3107 destinationFilename isDirectory ifTrue:[ |
3085 d isDirectory ifTrue:[ |
3108 destinationFilename := destinationFilename construct:self baseName. |
3086 d := d construct:self baseName. |
|
3087 ]. |
3109 ]. |
3088 self copyTo:d. |
3110 self copyTo:destinationFilename. |
3089 ^ self. |
3111 ^ self. |
3090 ]. |
3112 ]. |
3091 |
3113 |
3092 "/ typically, an 'cp -r' is faster; |
3114 "/ typically, an 'cp -r' is faster; |
3093 "/ however, if the command fails (or the OS does not support it), |
3115 "/ however, if the command fails (or the OS does not support it), |
3094 "/ fallBack doing a manual directory walk. |
3116 "/ fallBack doing a manual directory walk. |
3095 |
3117 |
3096 ok := OperatingSystem |
3118 ok := OperatingSystem |
3097 recursiveCopyDirectory:(self osNameForDirectory) |
3119 recursiveCopyDirectory:(self osNameForDirectory) |
3098 to:(destination asFilename osNameForDirectory). |
3120 to:(destinationFilename osNameForDirectory). |
3099 |
3121 |
3100 ok ifFalse:[ |
3122 ok ifFalse:[ |
3101 self recursiveCopyWithoutOSCommandTo:destination |
3123 self recursiveCopyWithoutOSCommandTo:destinationFilename |
3102 ]. |
3124 ]. |
|
3125 |
|
3126 " |
|
3127 '.' asFilename recursiveCopyTo:'/tmp/xxx'. |
|
3128 " |
3103 |
3129 |
3104 "Created: / 05-05-1999 / 13:35:01 / cg" |
3130 "Created: / 05-05-1999 / 13:35:01 / cg" |
3105 "Modified: / 31-05-1999 / 13:11:34 / cg" |
3131 "Modified: / 31-05-1999 / 13:11:34 / cg" |
3106 "Modified: / 29-07-2010 / 12:41:06 / sr" |
3132 "Modified: / 29-07-2010 / 12:41:06 / sr" |
3107 ! |
3133 ! |
3108 |
3134 |
3109 recursiveCopyWithoutOSCommandTo:destination |
3135 recursiveCopyWithoutOSCommandTo:destination |
3110 "if I represent a regular file, copy it. |
3136 "if I represent a regular file, copy it. |
3111 Otherwise, copy the directory and all of its subfiles/subdirectories. |
3137 Otherwise, copy the directory and all of its subfiles/subdirectories. |
3112 This one walks down the directory hierarchy, not using any OS command to do the copy. |
3138 This one walks down the directory hierarchy, not using any OS command to do the copy. |
3113 Raises an exception if not successful." |
3139 Raises an exception if not successful. |
|
3140 |
|
3141 Do not resolve symbolic links. |
|
3142 If a whole directory is to be copied and the destination directory |
|
3143 does not exist, it will be created." |
3114 |
3144 |
3115 |destinationFilename| |
3145 |destinationFilename| |
3116 |
3146 |
3117 destinationFilename := destination asFilename. |
3147 destinationFilename := destination asFilename. |
3118 |
3148 |
3119 self isDirectory ifTrue:[ |
3149 self isDirectory ifTrue:[ |
3120 destinationFilename exists ifTrue:[ |
3150 destinationFilename exists ifFalse:[ |
3121 destinationFilename := destinationFilename construct:self baseName. |
|
3122 destinationFilename makeDirectory. |
|
3123 ] ifFalse:[ |
|
3124 destinationFilename makeDirectory. |
3151 destinationFilename makeDirectory. |
3125 destinationFilename accessRights:self accessRights. |
3152 destinationFilename accessRights:self accessRights. |
3126 ]. |
3153 ]. |
3127 |
3154 |
3128 self directoryContents do:[:aFilenameString | |
3155 self directoryContents do:[:aFilenameString | |
3129 |src dst| |
3156 |src dst| |
3130 |
3157 |
3131 src := self construct:aFilenameString. |
3158 src := self construct:aFilenameString. |
|
3159 dst := destinationFilename construct:aFilenameString. |
|
3160 |
3132 src isDirectory ifTrue:[ |
3161 src isDirectory ifTrue:[ |
3133 src recursiveCopyWithoutOSCommandTo:destinationFilename |
3162 src recursiveCopyWithoutOSCommandTo:dst |
|
3163 ] ifFalse:[src isSymbolicLink ifTrue:[ |
|
3164 dst |
|
3165 remove; |
|
3166 createAsSymbolicLinkTo:src linkInfo path. |
3134 ] ifFalse:[ |
3167 ] ifFalse:[ |
3135 src copyTo:(destinationFilename construct:aFilenameString) |
3168 src copyTo:dst. |
3136 ]. |
3169 ]]. |
3137 ] |
3170 ]. |
3138 ] ifFalse:[ |
3171 ] ifFalse:[ |
3139 self copyTo:destinationFilename |
3172 destinationFilename isDirectory ifTrue:[ |
|
3173 destinationFilename := destinationFilename construct:self baseName. |
|
3174 ]. |
|
3175 self copyTo:destinationFilename. |
3140 ] |
3176 ] |
3141 |
3177 |
3142 " |
3178 " |
3143 '.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
3179 '.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
3144 'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
3180 'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |