What is the recommended way to determine whether an item can be moved to Finder Trash on a given volume?
If no Trash directory is available, is user confirmation followed by immediate deletion the expected path?
For which common volume types is a Trash directory unavailable?
Thanks!
What is the recommended way to determine whether an item can be moved to Finder Trash on a given volume?
So, my general recommendation would be that you not try to predict this. Just call NSFileManager.trashItem(at:...) and do "something else" if it fails. You can use url(for:in:appropriateFor:create:) and .trashDirectory, but that tells you where the trash dir is/"should" be, NOT whether or not the trash will work (more on that shortly...). I'm also not sure it's entirely reliable either since, for example, FileProvider clients aren't really required to implement "trash" semantics using the same "put the object in this directory" approach the system uses, assuming they return a target directory at all.
Similarly, in terms of doing your own prediction...
For which common volume types is a Trash directory unavailable?
...The problem is that there are a huge number of edge cases, most of which aren't necessarily tied to the volume itself. Our general behavior is that we try to find/create a trash directory on most volume formats, but regardless of our default behavior edge cases issue like:
-
A nested file provider can create a "trash-able" location on a volume that we wouldn't normally support trash on.
-
Access issues mean we may not be able to trash an item we "should" be able to trash.
That last point is what makes this really challenging, as this isn't just an issue of simple permissions. The EndpointSecurity API basically gives an ES client the ability to "veto" a broad set of system calls, which means the trash attempt can still fail even if EVERYTHING else said it "should" work. Critically, this also means that the failure can be entirely arbitrary, so even the failure or success of one request doesn't ACTUALLY mean the next request will succeed.
All of that makes doing any kind of preflighting fairly pointless, since you'll always have failures your preflight can't predict.
If no Trash directory is available, is user confirmation followed by immediate deletion the expected path?
That's the typical approach, though there are certainly cases where a different approach might make sense. For example, a "shoebox" app that's particularly concerned about unintentional data loss might create its own "trash" directory instead of using the system-level trash. Case in point, that's essentially what Photos.app is doing with its "Recently Deleted" album.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware