MDL-42387 standardise file lifetime handling