Fix transaction timeouts and directory removal.

- Downloads are no longer done inside a transaction, as this can time out.
- Fixed a bug where we could try to delete a directory that wasn't empty, causing an exception.