FileProvider needs to invalidate materialised items

I'm developing a macOS FileProvider extension which provides decrypted views of folders encrypted by our main application. If the user logs out of our app, the FileProvider re-enumerates the encrypted folder, replacing all the plain-text item names with their on-disk encrypted names, and any attempts to open an encrypted file will return encrypted garbage. This all works successfully for the most part.

But if a given file has already been opened before the logout, the system still has its decrypted contents as a materialized item -- and while it won't open in its normal application, an "Open With" can still view the decrypted contents.

Basically, is there a way to force the system to invalidate and remove the materialised copy of an item? At the moment I'm tracking all items in my working set, and not tracking materialised items separately... do I need to implement a separate set? Is it as simple as preserving the URL of any item whose contents I fetch, and then deleting that URL?

Including the item in the set of re-enumerated items when the parent folder calls enumerateChanges doesn't seem to be enough to indicate that local contents are now invalid. How do I do that?

In macOS 13, you can set the contentPolicy on NSFileProviderItem to .downloadLazilyAndEvictOnRemoteUpdate. (https://developer.apple.com/documentation/fileprovider/nsfileprovidercontentpolicy/downloadlazilyandevictonremoteupdate)

That will cause the system to evict the item's contents whenever you push a change to the contentVersion. (https://developer.apple.com/documentation/fileprovider/nsfileprovideritemversion/3043898-contentversion)

If you push a change to the contentVersion whenever you decide that the user should no longer have access to the file, the system will attempt to evict the contents from disk. (There is no guarantee, it could fail for various reasons, but that is what the system will try to do).

Prior to macOS 13, you can call -[NSFileProviderManager evictItemWithIdentifier:completionHandler:], to evict items in an imperative way. (https://developer.apple.com/documentation/fileprovider/nsfileprovidermanager/3191974-evictitem)

FileProvider needs to invalidate materialised items
 
 
Q