copyFile on Mac


#1

Hello,

I use copyFile function to copy a file from DVD to hard disk, after copying works proper, but after copying if I try to eject the DVD, but finder shows a error saying cant eject the DVD because some application is using it. But the same code works on Win. and you can eject the DVD

Can anyone tell me what’s the problem.

Thanks in advance.


#2

I just fixed this one recently, will be in the next release. The fix is in juce_mac_Files.cpp:

[code]bool juce_copyFile (const String& src, const String& dst)
{
const File destFile (dst);

if (! destFile.create())
    return false;

FSRef srcRef, dstRef;

if (! (PlatformUtilities::makeFSRefFromPath (&srcRef, src)
        && PlatformUtilities::makeFSRefFromPath (&dstRef, dst)))
{
    return false;
}

int okForks = 0;

CatPositionRec iter;
iter.initialize = 0;
HFSUniStr255 forkName;

// can't just copy the data because this is a bloody Mac, so we need to copy each
// fork separately...
while (FSIterateForks (&srcRef, &iter, &forkName, 0, 0) == noErr)
{
    SInt16 srcForkNum = 0, dstForkNum = 0;
    OSErr err = FSOpenFork (&srcRef, forkName.length, forkName.unicode, fsRdPerm, &srcForkNum);

    if (err == noErr)
    {
        err = FSOpenFork (&dstRef, forkName.length, forkName.unicode, fsRdWrPerm, &dstForkNum);

        if (err == noErr)
        {
            MemoryBlock buf (32768);
            SInt64 pos = 0;

            for (;;)
            {
                ByteCount bytesRead = 0;
                err = FSReadFork (srcForkNum, fsFromStart, pos, buf.getSize(), (char*) buf, &bytesRead);

                if (bytesRead > 0)
                {
                    err = FSWriteFork (dstForkNum, fsFromStart, pos, bytesRead, (const char*) buf, &bytesRead);
                    pos += bytesRead;
                }

                if (err != noErr)
                {
                    if (err == eofErr)
                        ++okForks;

                    break;
                }
            }

            FSFlushFork (dstForkNum);
            FSCloseFork (dstForkNum);
        }

        FSCloseFork (srcForkNum);
    }
}

return okForks > 0; // some files seem to be ok even if not all their forks get copied..

}[/code]


#3