tools/symsrc/source_index.py
def CheckForJunction(filename):
  """Check if a directory containing a file is a junction to another directory.

  If so return 3 values:
      - The real path to this file.
      - The root directory of this checkout relative to |filename| (i.e. not
        relative to the real path).
      - The sub directory of the repository that has been checked out.
  """
  # Process the path of |filename| from right to left until a junction has been
  # found.
  #
  # Here's an example of what this does, for this example
  # |filename| = 'C:/a/b/c/d.h' and 'C:/a' is a junction to 'C:/real_a/'.
  #
  # - We remove the filename part (we're only looking at directory junctions
  #   here), that left us with 'C:/a/b/c'.
  # - During the first iteration we take 'C:/a/b' as our current root value and
  #   'c' as the leaf value.
  # - We run the 'dir' command on 'C:/a/b' and we look for a junction to 'c'. As
  #   we don't find any we go up one directory. Now the current root is 'C:/a'
  #   and the current leaf value is 'b'.
  # - We run the 'dir' command on 'C:/a' and we look for a junction to 'b'. This
  #   time we find one so we return the following triplet:
  #     - C:/real_a/b/c/d.h   # The real file path.
  #     - C:/a                # The root directory containing this junction.
  #     - b                   # The name of the junction.
  cur_root, cur_leaf = os.path.split(os.path.dirname(filename))
  while cur_leaf:
    # Run the 'dir' command and look for a junction.
    dir_cmd = RunCommand('cmd', '/c', 'dir', cur_root)
    for entry in dir_cmd.splitlines():
      m = _DIR_JUNCTION_RE.match(entry)
      if not m:
        continue
      if not m.group('dirname') == cur_leaf:
        continue
      real_path = filename.replace(os.path.join(cur_root, cur_leaf),
                                    m.group('real_path'))
      # This should always be the case.
      # TODO(sebmarchand): Remove this check if it proves to be useless.
      if os.path.exists(real_path):
        return real_path, cur_root, cur_leaf
      else:
        print('Source indexing: error: Unexpected non existing file \'%s\'' %
              real_path)
        return None, None, None
    cur_root, cur_leaf = os.path.split(cur_root)
  return None, None, None
Check if a directory containing a file is a junction to another directory.

  If so return 3 values:
      - The real path to this file.
      - The root directory of this checkout relative to |filename| (i.e. not
        relative to the real path).
      - The sub directory of the repository that has been checked out.
  
Check if a directory containing a file is a junction to another directory.
If so return 3 values:
The real path to this file.
The root directory of this checkout relative to |filename| .
The sub directory of the repository that has been checked out.
Check if a directory containing a file is a junction to another directory . If so return 3 values : The real path to this file . The root directory of this checkout relative to |filename| . The sub directory of the repository that has been checked out .
def CheckForJunction(filename):
   Here's an example of what this does, for this example
   |filename| = 'C:/a/b/c/d.h' and 'C:/a' is a junction to 'C:/real_a/'.
   - We remove the filename part (we're only looking at directory junctions
     here), that left us with 'C:/a/b/c'.
   - During the first iteration we take 'C:/a/b' as our current root value and
     'c' as the leaf value.
   - We run the 'dir' command on 'C:/a/b' and we look for a junction to 'c'. As
     we don't find any we go up one directory. Now the current root is 'C:/a'
     and the current leaf value is 'b'.
   - We run the 'dir' command on 'C:/a' and we look for a junction to 'b'. This
     time we find one so we return the following triplet:
       - C:/real_a/b/c/d.h    The real file path.
       - C:/a                 The root directory containing this junction.
       - b                    The name of the junction.
  cur_root, cur_leaf = os.path.split(os.path.dirname(filename))
  while cur_leaf:
     Run the 'dir' command and look for a junction.
    dir_cmd = RunCommand('cmd', '/c', 'dir', cur_root)
    for entry in dir_cmd.splitlines():
      m = _DIR_JUNCTION_RE.match(entry)
      if not m:
        continue
      if not m.group('dirname') == cur_leaf:
        continue
      real_path = filename.replace(os.path.join(cur_root, cur_leaf),
                                    m.group('real_path'))
       This should always be the case.
       TODO(sebmarchand): Remove this check if it proves to be useless.
      if os.path.exists(real_path):
        return real_path, cur_root, cur_leaf
      else:
        print('Source indexing: error: Unexpected non existing file \'%s\'' %
              real_path)
        return None, None, None
    cur_root, cur_leaf = os.path.split(cur_root)
  return None, None, None
def CheckForJunction ( filename ) : cur_root , cur_leaf = os . path . split ( os . path . dirname ( filename ) ) while cur_leaf : dir_cmd = RunCommand ( 'cmd' , '/c' , 'dir' , cur_root ) for entry in dir_cmd . splitlines ( ) : m = _DIR_JUNCTION_RE . match ( entry ) if not m : continue if not m . group ( 'dirname' ) == cur_leaf : continue real_path = filename . replace ( os . path . join ( cur_root , cur_leaf ) , m . group ( 'real_path' ) ) if os . path . exists ( real_path ) : return real_path , cur_root , cur_leaf else : print ( 'Source indexing: error: Unexpected non existing file \'%s\'' % real_path ) return None , None , None cur_root , cur_leaf = os . path . split ( cur_root ) return None , None , None
Check if a directory containing a file is a junction to another directory.
Check if a directory containing a file is a junction to another directory .
"""Check if a directory containing a file is a junction to another directory.

  If so return 3 values:
      - The real path to this file.
      - The root directory of this checkout relative to |filename| (i.e. not
        relative to the real path).
      - The sub directory of the repository that has been checked out.
  """ # Process the path of |filename| from right to left until a junction has been # found. # # Here's an example of what this does, for this example # |filename| = 'C:/a/b/c/d.h' and 'C:/a' is a junction to 'C:/real_a/'. # # - We remove the filename part (we're only looking at directory junctions #   here), that left us with 'C:/a/b/c'. # - During the first iteration we take 'C:/a/b' as our current root value and #   'c' as the leaf value. # - We run the 'dir' command on 'C:/a/b' and we look for a junction to 'c'. As #   we don't find any we go up one directory. Now the current root is 'C:/a' #   and the current leaf value is 'b'. # - We run the 'dir' command on 'C:/a' and we look for a junction to 'b'. This #   time we find one so we return the following triplet: #     - C:/real_a/b/c/d.h   # The real file path. #     - C:/a                # The root directory containing this junction. #     - b                   # The name of the junction. # Run the 'dir' command and look for a junction. # This should always be the case. # TODO(sebmarchand): Remove this check if it proves to be useless.
filename