'Converts a glob pattern into a list of pathspec components.
Wildcards are also converted to regular expressions. The pathspec components
do not span directories, and are marked as a regex or a literal component.
We also support recursion into directories using the ** notation.  For
example, /home/**2/foo.txt will find all files named foo.txt recursed 2
directories deep. If the directory depth is omitted, it defaults to 3.
Example:
/home/test/* -> [\'home\', \'test\', \'.*\\Z(?ms)\']
Args:
pattern: A glob expression with wildcards.
Returns:
A list of PathSpec instances for each component.
Raises:
ValueError: If the glob is invalid.'

def ConvertGlobIntoPathComponents(self, pattern):

    components = []
    for path_component in pattern.split('/'):
        m = rdf_paths.GlobExpression.RECURSION_REGEX.search(path_component)
        if m:
            path_component = path_component.replace(m.group(0), '*')
            component = rdf_paths.PathSpec(path=fnmatch.translate(path_component), pathtype=self.state.pathtype, path_options=rdf_paths.PathSpec.Options.RECURSIVE)
            if m.group(1):
                component.recursion_depth = int(m.group(1))
        elif self.GLOB_MAGIC_CHECK.search(path_component):
            component = rdf_paths.PathSpec(path=fnmatch.translate(path_component), pathtype=self.state.pathtype, path_options=rdf_paths.PathSpec.Options.REGEX)
        else:
            pathtype = self.state.pathtype
            if ((pathtype == rdf_paths.PathSpec.PathType.TSK) and re.match('^.:$', path_component)):
                path_component = ('%s\\' % path_component)
            component = rdf_paths.PathSpec(path=path_component, pathtype=pathtype, path_options=rdf_paths.PathSpec.Options.CASE_INSENSITIVE)
        components.append(component)
    return components
