Search code examples
objective-cmacoscocoapluginsnsbundle

How to disable (or be notified of) the deletion of a loaded plugin (NSBundle) file?


I wrote an app with a plugin system (with NSBundle), all is ok but i want to handle the case of when a plugin file is deleted during the app execution.

I think the best way to do that is to disable the deletion of a loaded plugin file (like dll in windows, they can't be deleted when loaded by applications)

But in OSX it's possible to delete the plugin file even if it is used by an app.

Is it possible to disable the deletion of the plugin file when an app uses it ?

Or at least is it possible to be notified when a file is deleted so i can update my app when a plugin file is deleted ?

Thank you


Solution

  • I do not think that you can disable the deletion of a loaded plug-in, but there are possibilities to monitor changes to the file system which may help.

    1. The "File System Events API"

      With the File System Events API, your app can be notified if the contents of a specified directory changes. Then you have to scan the directory yourself, e.g. to check which plug-ins still exist or have been removed.

    2. Kernel Queues

      This is a more lower-level approach, using the kqueue(), kevent() system calls. You can for example register a file descriptor and will be notified if unlink() was called on the referenced file.

    Both mechanisms are described in the File System Events Programming Guide. There is also a sample project Monitoring File Changes with the File System Events API.