Index: Copy/filecopy.c =================================================================== --- Copy/filecopy.c.orig +++ Copy/filecopy.c @@ -166,46 +166,46 @@ copyfork(HFSUniStr255 *forkName, FSRef * #define min(x, y) ((x) < y) ? (x) : (y) -static OSErr -filecopy(char *src, char *dst, UInt64 maxbufsize, int preserve){ - OSErr err; - FSCatalogInfo srcCat, dstCat; - FSRef srcFS, dstFS; - HFSUniStr255 forkName; - UTCDateTime now; - - if (err = FSPathMakeRef(src, &srcFS, NULL)) - { return err; } - - if (err = FSGetCatalogInfo(&srcFS, kFSCatInfoGettableInfo, &srcCat, - NULL, NULL, NULL)) - { return err; } - - bcopy(&srcCat, &dstCat, sizeof(FSCatalogInfo)); - - if (err = newfile(dst, &dstFS, &dstCat)){ - fpf(stderr, "Cannot Create File %s\n", dst); - return err; - } - if (srcCat.dataLogicalSize){ - setbufsiz(min(srcCat.dataPhysicalSize, maxbufsize)); - FSGetDataForkName(&forkName); - if (err = copyfork(&forkName, &srcFS, &dstFS)) - { return err; } - } - if (srcCat.rsrcLogicalSize){ - setbufsiz(min(srcCat.rsrcPhysicalSize, maxbufsize)); - FSGetResourceForkName(&forkName); - if (err = copyfork(&forkName, &srcFS, &dstFS)) - { return err; } - } - freebuf(); - if (preserve){ - err = FSSetCatalogInfo(&dstFS, kFSCatInfoSettableInfo, &srcCat); - } - return err; +static OSStatus +filecopy(char *src, char *dst, UInt64 maxbufsize, int preserve) +{ + OSStatus status; + char *destDir = NULL; + CFStringRef destFname; + char *lastSlash = NULL; + char *tmpString = NULL; + + if (NULL == dst || NULL == src) { + return -1; + } + /* split the dst into the dir and the filename */ + if (NULL == (tmpString = dirname(dst))) { + /* dirname() failed... */ + return errno + kPOSIXErrorBase; + } + destDir = calloc((strlen(tmpString) + 2), sizeof(char)); + if (NULL == destDir) { + /* failed to allocate mem */ + return errno + kPOSIXErrorBase; + } + if (strlcpy(destDir, tmpString, (strlen(tmpString) + 1)) > (strlen(tmpString))) { + /* argh! */ + return kPOSIXErrorERANGE; + } + if (NULL == (tmpString = basename(dst))) { + /* basename() failed... */ + return errno + kPOSIXErrorBase; + } + destFname = CFStringCreateWithCString(kCFAllocatorDefault, tmpString, kCFStringEncodingMacRoman); + + status = FSPathCopyObjectSync(src, destDir, destFname, NULL, kFSFileOperationSkipPreflight); + + // fprintf(stderr, "FSPathCOpyObjectSync(%s, %s, %s,...) status is \"%d\"\n", (NULL != src ? src : ""), (NULL != destDir ? destDir: ""), (NULL != tmpString ? tmpString: ""), status); + + return status; } + /* static OSErr filemove(char *src, char *dst){ Index: Copy/Copy.pm =================================================================== --- Copy/Copy.pm.orig +++ Copy/Copy.pm @@ -85,7 +85,7 @@ sub copy($$;$$){ my ($srcdev, $srcino, $srcmode, $srcuid, $srcgid, $srcatime, $srcmtime) = (lstat($src))[0,1,2,4,5,8,9]; - unless(-f _){ + unless(-e _){ $MacOSX::File::OSErr = -43; # fnfErr; $! = &Errno::ENOENT; return;