file.copy = function copy(srcpath, destpath, options) {
  if (file.isLink(destpath)) {
    // in case destpath is a symlink, avoid following the symlink, instead overwrite it later
    fs.unlinkSync(destpath);
  }

  if (file.isLink(srcpath)) {
    file._copySymbolicLink(srcpath, destpath);
  } else if (file.isDir(srcpath)) {
    // Copy a directory, recursively.
    // Explicitly create new dest directory.
    file.mkdir(destpath);
    // Iterate over all sub-files/dirs, recursing.
    fs.readdirSync(srcpath).forEach(function(filepath) {
      copy(path.join(srcpath, filepath), path.join(destpath, filepath), options);
    });
  } else {
    // Copy a single file.
    file._copy(srcpath, destpath, options);
  }
};
The software checks the state of a resource before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check. This can cause the software to perform invalid actions when the resource is in an unexpected state.