[5.0] Refactored And Improved Flysystem Integration

Replaces #5884.