169 | | static OSErr |
170 | | filecopy(char *src, char *dst, UInt64 maxbufsize, int preserve){ |
171 | | OSErr err; |
172 | | FSCatalogInfo srcCat, dstCat; |
173 | | FSRef srcFS, dstFS; |
174 | | HFSUniStr255 forkName; |
175 | | UTCDateTime now; |
176 | | |
177 | | if (err = FSPathMakeRef(src, &srcFS, NULL)) |
178 | | { return err; } |
179 | | |
180 | | if (err = FSGetCatalogInfo(&srcFS, kFSCatInfoGettableInfo, &srcCat, |
181 | | NULL, NULL, NULL)) |
182 | | { return err; } |
183 | | |
184 | | bcopy(&srcCat, &dstCat, sizeof(FSCatalogInfo)); |
185 | | |
186 | | if (err = newfile(dst, &dstFS, &dstCat)){ |
187 | | fpf(stderr, "Cannot Create File %s\n", dst); |
188 | | return err; |
189 | | } |
190 | | if (srcCat.dataLogicalSize){ |
191 | | setbufsiz(min(srcCat.dataPhysicalSize, maxbufsize)); |
192 | | FSGetDataForkName(&forkName); |
193 | | if (err = copyfork(&forkName, &srcFS, &dstFS)) |
194 | | { return err; } |
195 | | } |
196 | | if (srcCat.rsrcLogicalSize){ |
197 | | setbufsiz(min(srcCat.rsrcPhysicalSize, maxbufsize)); |
198 | | FSGetResourceForkName(&forkName); |
199 | | if (err = copyfork(&forkName, &srcFS, &dstFS)) |
200 | | { return err; } |
201 | | } |
202 | | freebuf(); |
203 | | if (preserve){ |
204 | | err = FSSetCatalogInfo(&dstFS, kFSCatInfoSettableInfo, &srcCat); |
205 | | } |
206 | | return err; |
| 178 | static OSStatus |
| 179 | filecopy(char *src, char *dst, UInt64 maxbufsize, int preserve) |
| 180 | { |
| 181 | OSStatus status; |
| 182 | char *destDir = NULL; |
| 183 | CFStringRef destFname; |
| 184 | char *lastSlash = NULL; |
| 185 | char *tmpString = NULL; |
| 186 | |
| 187 | if (NULL == dst || NULL == src) { |
| 188 | return -1; |
| 189 | } |
| 190 | /* split the dst into the dir and the filename */ |
| 191 | if (NULL == (tmpString = dirname(dst))) { |
| 192 | /* dirname() failed... */ |
| 193 | return errno + kPOSIXErrorBase; |
| 194 | } |
| 195 | destDir = calloc((strlen(tmpString) + 2), sizeof(char)); |
| 196 | if (NULL == destDir) { |
| 197 | /* failed to allocate mem */ |
| 198 | return errno + kPOSIXErrorBase; |
| 199 | } |
| 200 | if (strlcpy(destDir, tmpString, (strlen(tmpString) + 1)) > (strlen(tmpString))) { |
| 201 | /* argh! */ |
| 202 | return kPOSIXErrorERANGE; |
| 203 | } |
| 204 | if (NULL == (tmpString = basename(dst))) { |
| 205 | /* basename() failed... */ |
| 206 | return errno + kPOSIXErrorBase; |
| 207 | } |
| 208 | destFname = CFStringCreateWithCString(kCFAllocatorDefault, tmpString, kCFStringEncodingMacRoman); |
| 209 | |
| 210 | status = FSPathCopyObjectSync(src, destDir, destFname, NULL, kFSFileOperationSkipPreflight); |
| 211 | |
| 212 | // fprintf(stderr, "FSPathCOpyObjectSync(%s, %s, %s,...) status is \"%d\"\n", (NULL != src ? src : "<NULL>"), (NULL != destDir ? destDir: "<NULL>"), (NULL != tmpString ? tmpString: "<NULL>"), status); |
| 213 | |
| 214 | return status; |