Question

I work on Mac OS & Qt and I'd like to copy files (with a home-made function) in /Library/Frameworks but the copy fail each time. The problem is coming from identification but I don't know how to solve it.

Here's my copy function witch work perfectly when copying to home (for example)

void copyFolder(QString sourceFolder, QString destFolder)
{
    QDir sourceDir(sourceFolder);
    if(!sourceDir.exists())
        return;
    QDir destDir(destFolder);
    if(!destDir.exists())
    {
        if(destDir.mkdir(destFolder))
        {
            QStringList files = sourceDir.entryList(QDir::Files);
            for(int i = 0; i< files.count(); i++)
            {
                QString srcName = sourceFolder + "/" + files[i];
                QString destName = destFolder + "/" + files[i];
                QFile::copy(srcName, destName);
            }
            files.clear();
            files = sourceDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
            for(int i = 0; i< files.count(); i++)
            {
                QString srcName = sourceFolder + "/" + files[i];
                QString destName = destFolder + "/" + files[i];
                copyFolder(srcName, destName);
            }
        }
        else
        {
            qDebug() << "There's a problem while creating : " + destFolder;
        }
    }

}
Was it helpful?

Solution

As the problem you have is with permissions, you can solve this, but not with Qt alone.

Apple's solution, for security, is that when an application is required to access something with elevated privileges (in this case, the Frameworks folder), a second helper application is required that is spawned via launchd and it is that 2nd application that is given the privileges to perform the task.

There is an example of this called SMJobBless, which you can see here: -

However, you'll notice that it is written in Objective-C. If that's new to you, just be aware that it's only an extension of C, so you should be able to pick up the new parts reasonably easily; enough to modify the SMJobBless example for your needs.

With little documentation available for SMJobBless, there's more about it here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top