Refuse to convert a non-empty directory into a link with the file module

Also adds an integration test for the above.

Fixes #7254