Context - I'm involved with both dedicated real servers running 10+ moodles each and with clients wanting a moodle install on a VM. In the former case when doing upgrades (copy moodledata folder is advised) the moodledata copy time can be 40 mins+. In the latter case disc space is a significant cost factor.
Example case - one install has a moodledata folder of 21G - assuming my sql is correct 8.4G is duplicated files (this test based on mdl_files.contenthash) perhaps arising from copied courses or same resource in multiple courses.
Could resource file upload process check for duplication (contenthash) and in mdl_files use the same pathnamehash for the new record ?
If, on deletion of a course or resource, could the process check if another file record uses the same contenthash and not remove the file, while still removing the mdl_files record ?