code: def get_unique_file_path(
      dir_path, filename, cache=collections.defaultdict(set)
  ):
      """
      Get unique filename in dir with proper filename length, using given filename/dir.
      File/dir won't be created (thread nonsafe)
      :param dir_path: path to dir
      :param filename: original filename
      :return: unique filename
      """
      max_suffix = 10000
      # + 1 symbol for dot before suffix
      tail_length = int(round(math.log(max_suffix, 10))) + 1
      # truncate filename length in accordance with filesystem limitations
      filename, extension = os.path.splitext(filename)
      # XXX
      if sys.platform.startswith("win"):
          # Trying to fit into MAX_PATH if it's possible.
          # Remove after DEVTOOLS-1646
          max_path = 260
          filename_len = (
              len(dir_path) + len(extension) + tail_length + len(os.sep)
          )
          if filename_len < max_path:
              filename = yatest_lib.tools.trim_string(
                  filename, max_path - filename_len
              )
      filename = (
          yatest_lib.tools.trim_string(
              filename,
              get_max_filename_length(dir_path)
              - tail_length
              - len(extension),
          )
          + extension
      )
      candidate = os.path.join(dir_path, filename)
  
      key = dir_path + filename
      counter = sorted(
          cache.get(
              key,
              {
                  0,
              },
          )
      )[-1]
      while os.path.exists(candidate):
          cache[key].add(counter)
          counter += 1
          assert counter < max_suffix
          candidate = os.path.join(
              dir_path, filename + ".{}".format(counter)
          )
      return candidate
  
imports: import collections
  import functools
  import math
  import os
  import re
  import sys
  import yatest_lib.tools
label_desc: Use image node_id 4 for calling a global function with example usage: get_unique_file_path(dir_path, filename, cache) and returns: candidate