database: be robust to empty folders in the filesystem

When a handler is removed leaving an empty folder, we don't remove
the empty folder from the filesystem, but we do from the Git tree.

If then we remove the empty folder in a different transaction, then we
will attempt to remove the empty tree from the parent tree too, and that
will fail since it is not there.