parameters: (src, target_dir)
docstring: Copy specified |src| file to |target_dir|, but only write to target if
    the file has changed. This avoids a problem during packaging where parts of
    the build have not completed and have the runtime DLL locked when we try to
    copy over it. See http://crbug.com/305877 for details.
docstring_summary: Copy specified |src| file to |target_dir|, but only write to target if
    the file has changed. This avoids a problem during packaging where parts of
    the build have not completed and have the runtime DLL locked when we try to
    copy over it. See http://crbug.com/305877 for details.
docstring_tokens: Copy specified |src| file to |target_dir| but only write to target if the file has changed . This avoids a problem during packaging where parts of the build have not completed and have the runtime DLL locked when we try to copy over it . See http : // crbug . com / 305877 for details .
function: def CopyIfChanged(src, target_dir):
    """Copy specified |src| file to |target_dir|, but only write to target if
    the file has changed. This avoids a problem during packaging where parts of
    the build have not completed and have the runtime DLL locked when we try to
    copy over it. See http://crbug.com/305877 for details."""
    assert os.path.isdir(target_dir)
    dest = os.path.join(target_dir, os.path.basename(src))
    if os.path.exists(dest):
      # We assume the files are OK to buffer fully into memory since we know
      # they're only 1-2M.
      with open(src, 'rb') as fsrc:
        src_data = fsrc.read()
      with open(dest, 'rb') as fdest:
        dest_data = fdest.read()
      if src_data != dest_data:
        # This may still raise if we get here, but this really should almost
        # never happen (it would mean that the contents of e.g. msvcr100d.dll
        # had been changed).
        shutil.copyfile(src, dest)
    else:
      shutil.copyfile(src, dest)
function_tokens: def CopyIfChanged ( src , target_dir ) : assert os . path . isdir ( target_dir ) dest = os . path . join ( target_dir , os . path . basename ( src ) ) if os . path . exists ( dest ) : # We assume the files are OK to buffer fully into memory since we know # they're only 1-2M. with open ( src , 'rb' ) as fsrc : src_data = fsrc . read ( ) with open ( dest , 'rb' ) as fdest : dest_data = fdest . read ( ) if src_data != dest_data : # This may still raise if we get here, but this really should almost # never happen (it would mean that the contents of e.g. msvcr100d.dll # had been changed). shutil . copyfile ( src , dest ) else : shutil . copyfile ( src , dest )