TODO: tests for this.
We'll need this for cleanup operations as well. This should likely be factored out again into an entirely separate package that deals with storage access.