code: def _hardlink_cachepath(cls, ivy_repository_cache_dir, inpath, hardlink_dir, outpath):
      
      safe_mkdir(hardlink_dir)
      # The ivy_repository_cache_dir might itself be a hardlink. In this case, ivy may return paths that
      # reference the realpath of the .jar file after it is resolved in the cache dir. To handle
      # this case, add both the hardlink'ed path and the realpath to the jar to the hardlink map.
      real_ivy_cache_dir = os.path.realpath(ivy_repository_cache_dir)
      hardlink_map = OrderedDict()
  
      inpaths = cls._load_classpath_from_cachepath(inpath)
      paths = OrderedSet([os.path.realpath(path) for path in inpaths])
  
      for path in paths:
        if path.startswith(real_ivy_cache_dir):
          hardlink_map[path] = os.path.join(hardlink_dir, os.path.relpath(path, real_ivy_cache_dir))
        else:
          # This path is outside the cache. We won't hardlink it.
          hardlink_map[path] = path
  
      # Create hardlinks for paths in the ivy cache dir.
      for path, hardlink in six.iteritems(hardlink_map):
        if path == hardlink:
          # Skip paths that aren't going to be hardlinked.
          continue
        safe_mkdir(os.path.dirname(hardlink))
        safe_hardlink_or_copy(path, hardlink)
  
      # (re)create the classpath with all of the paths
      with safe_open(outpath, 'w') as outfile:
        outfile.write(':'.join(OrderedSet(hardlink_map.values())))
  
      return dict(hardlink_map)
docs: hardlinks all paths listed in inpath that are under ivy_repository_cache_dir into hardlink_dir.
  
      If there is an existing hardlink for a file under inpath, it is used rather than creating
      a new hardlink. Preserves all other paths. Writes the resulting paths to outpath.
      Returns a map of path -> hardlink to that path.