Made file resize operation more robust

File resize is tried until it succeeds.