File.open(name, 'w') { |f| f.flock(File::EX); ... }  truncates the file before gaining the lock