title: Is fs.renameSync an atomic operation that is resistant to corruption?
body: <pre><code>const path = require('path');
  const fs = require('fs');
  const os = require('os');
  
  const from_dir = path.resolve(os.homedir(), './from_dir');
  const to_dir= path.resolve(os.homedir(), './new_dir');
  fs.renameSync(from_dir, to_dir);
  </code></pre>
  <p>Suppose I have the following snippet of code in a NodeJS application, and my goal is to rename &quot;from_dir&quot; to &quot;to_dir&quot;. Based on my understanding, the rename operation is supposed to be atomic. Can I also rely on this operation to never corrupt the &quot;from_dir&quot; directory contents during the rename process, even if the process is being forcefully shut down during? Or is it better to first copy the contents of the directory to a backup, and then attempt to rename (something equivalent to <code>cp -r ~/from_dir ~/from_dir_backup</code>)? I have tried to reproduce such a scenario and couldn't do it.</p>