code: def link_or_copy(src, dst):
      """Attempts to hardlink ``src`` to ``dst``, copying if the link fails.
  
      Attempts to maintain the semantics of ``shutil.copy``.
  
      Because ``os.link`` does not overwrite files, a unique temporary file
      will be used if the target already exists, then that file will be moved
      into place.
      """
  
      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:
              # dst is already a hard link to the correct file, so we don't need
              # to do anything else. If we try to link and rename the file
              # anyway, we get duplicate files - see http://bugs.python.org/issue21876
              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:
          # Either link isn't supported, or the filesystem doesn't support
          # linking, or 'src' and 'dst' are on different filesystems.
          shutil.copy(src, dst)
  
imports: import os
  import sys
  import errno
  import shutil
  import random
  import glob
  from IPython.utils.process import system
label_desc: Use image node_id 15 for calling a global function with example usage: link_or_copy(src, dst) without return types