parameters: (filepath, targpath, try_mklink)
return_statement: return try_mklink
docstring: Create a hardlink on Win32 if possible
  
    Uses mklink to create a hardlink if possible.  On failure, it will
    assume mklink is unavailible and copy the file instead, returning False
    to indicate future calls should not attempt to use mklink.
docstring_summary: Create a hardlink on Win32 if possible
docstring_tokens: Create a hardlink on Win32 if possible
function: def CreateWin32Hardlink(filepath, targpath, try_mklink):
    """Create a hardlink on Win32 if possible
  
    Uses mklink to create a hardlink if possible.  On failure, it will
    assume mklink is unavailible and copy the file instead, returning False
    to indicate future calls should not attempt to use mklink."""
  
    # Assume an error, if subprocess succeeds, then it should return 0
    err = 1
    if try_mklink:
      dst_src = ToNativePath(filepath) + ' ' + ToNativePath(targpath)
      try:
        err = subprocess.call(['cmd', '/C', 'mklink /H ' + dst_src],
                              stdout = open(os.devnull, 'wb'))
      except EnvironmentError:
        try_mklink = False
  
    # If we failed to create a hardlink, then just copy it.  We wrap this in a
    # retry for Windows which often has stale file lock issues.
    if err or not os.path.isfile(filepath):
      for cnt in range(1,4):
        try:
          shutil.copyfile(targpath, filepath)
          return False
        except EnvironmentError:
          print 'Try %d: Failed hardlink %s -> %s\n' % (cnt, filepath, targpath)
      print 'Giving up.'
    return try_mklink
function_tokens: def CreateWin32Hardlink ( filepath , targpath , try_mklink ) : # Assume an error, if subprocess succeeds, then it should return 0 err = 1 if try_mklink : dst_src = ToNativePath ( filepath ) + ' ' + ToNativePath ( targpath ) try : err = subprocess . call ( [ 'cmd' , '/C' , 'mklink /H ' + dst_src ] , stdout = open ( os . devnull , 'wb' ) ) except EnvironmentError : try_mklink = False # If we failed to create a hardlink, then just copy it.  We wrap this in a # retry for Windows which often has stale file lock issues. if err or not os . path . isfile ( filepath ) : for cnt in range ( 1 , 4 ) : try : shutil . copyfile ( targpath , filepath ) return False except EnvironmentError : print 'Try %d: Failed hardlink %s -> %s\n' % ( cnt , filepath , targpath ) print 'Giving up.' return try_mklink