def link_or_copy(src, dst):
 if os.path.isdir(dst):
  dst = os.path.join(dst, os.path.basename(src))
 link_errno = link(src, dst)
 if (link_errno == errno.EEXIST):
  if (os.stat(src).st_ino == os.stat(dst).st_ino):
   return
  new_dst = (dst + ('-temp-%04X' % (random.randint(1, (16 ** 4)),)))
  try:
   link_or_copy(src, new_dst)
  except:
   try:
    os.remove(new_dst)
   except OSError:
    pass
   raise
  os.rename(new_dst, dst)
 elif (link_errno != 0):
  shutil.copy(src, dst)

def link_or_copy ( src , dst ) : if os . path . isdir ( dst ) : dst = os . path . join ( dst , os . path . basename ( src ) ) link_errno = link ( src , dst ) if ( link_errno == errno . EEXIST ) : if ( os . stat ( src ) . st_ino == os . stat ( dst ) . st_ino ) : return new_dst = ( dst + ( '-temp-%04X' % ( random . randint ( 1 , ( 16 ** 4 ) ) , ) ) ) try : link_or_copy ( src , new_dst ) except : try : os . remove ( new_dst ) except OSError : pass raise os . rename ( new_dst , dst ) elif ( link_errno != 0 ) : shutil . copy ( src , dst )
attempts to hardlink src to dst .