code: def _test_existing_clone_target(
      destds: Dataset, candidate_sources: List
  ) -> Tuple:
      """Check if the clone target exists, inspect it, if so
  
      Returns
      -------
      (bool, dict or None)
        A flag whether the target exists, and either a dict with properties
        of a result that should be yielded before an immediate return, or
        None, if the processing can continue
      """
      # important test! based on this `rmtree` will happen below after
      # failed clone
      dest_path = destds.pathobj
      dest_path_existed = dest_path.exists()
      if dest_path_existed and any(dest_path.iterdir()):
          if destds.is_installed():
              # check if dest was cloned from the given source before
              # this is where we would have installed this from
              # this is where it was actually installed from
              track_name, track_url = _get_tracking_source(destds)
              try:
                  # this will get us track_url in system native path conventions,
                  # whenever it is a path (and not a URL)
                  # this is needed to match it to any potentially incoming local
                  # source path in the 'notneeded' test below
                  track_path = str(Path(track_url))
              except Exception as e:
                  CapturedException(e)
                  # this should never happen, because Path() will let any non-path
                  # stringification pass through unmodified, but we do not want any
                  # potential crash due to pathlib behavior changes
                  lgr.debug("Unexpected behavior of pathlib!")
                  track_path = None
              for cand in candidate_sources:
                  src = cand["giturl"]
                  if (
                      track_url == src
                      or (
                          not is_url(track_url)
                          and get_local_file_url(
                              track_url, compatibility="git"
                          )
                          == src
                      )
                      or track_path == expanduser(src)
                  ):
                      return dest_path_existed, dict(
                          status="notneeded",
                          message=(
                              "dataset %s was already cloned from '%s'",
                              destds,
                              src,
                          ),
                      )
          # anything else is an error
          return dest_path_existed, dict(
              status="error",
              message="target path already exists and not empty, "
              "refuse to clone into target path",
          )
      # found no reason to stop, i.e. empty target dir
      return dest_path_existed, None
  
imports: import logging
  import re
  from os.path import expanduser
  from pathlib import Path
  from typing import Dict, List, Tuple
  from urllib.parse import unquote
  from datalad.cmd import CommandError, GitWitlessRunner, StdOutCapture
  from datalad.config import ConfigManager
  from datalad.distributed.ora_remote import LocalIO, RIARemoteError, SSHRemoteIO
  from datalad.distribution.dataset import Dataset
  from datalad.distribution.utils import _get_flexible_source_candidates
  from datalad.dochelpers import single_or_plural
  from datalad.log import log_progress
  from datalad.runner.exception import CommandError
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.exceptions import CapturedException, DownloadError
  from datalad.support.gitrepo import GitRepo
  from datalad.support.network import RI, SSHRI, URL, DataLadRI, download_url, get_local_file_url, is_url
  from datalad.support.strings import get_replacement_dict
  from datalad.utils import Path, PurePosixPath, ensure_bool, ensure_list, make_tempfile, rmtree
label_desc: Use image node_id 9 for calling a global function with example usage: _test_existing_clone_target(destds, candidate_sources) and returns: dest_path_existed,  None, dest_path_existed,  dict, dest_path_existed,  dict