add code to restore missing environment files and links, fix #2960, fix #2911