MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / _IsParentOrSame

Function _IsParentOrSame

src/tests/coding/cpplint.py:6858–6874  ·  view source on GitHub ↗

Return true if child is subdirectory of parent. Assumes both paths are absolute and don't contain symlinks.

(parent, child)

Source from the content-addressed store, hash-verified

6856 if _IsParentOrSame(e, os.path.abspath(f)))]
6857
6858def _IsParentOrSame(parent, child):
6859 """Return true if child is subdirectory of parent.
6860 Assumes both paths are absolute and don't contain symlinks.
6861 """
6862 parent = os.path.normpath(parent)
6863 child = os.path.normpath(child)
6864 if parent == child:
6865 return True
6866
6867 prefix = os.path.commonprefix([parent, child])
6868 if prefix != parent:
6869 return False
6870 # Note: os.path.commonprefix operates on character basis, so
6871 # take extra care of situations like '/foo/ba' and '/foo/bar/baz'
6872 child_suffix = child[len(prefix):]
6873 child_suffix = child_suffix.lstrip(os.sep)
6874 return child == os.path.join(prefix, child_suffix)
6875
6876def main():
6877 filenames = ParseArguments(sys.argv[1:])

Callers 1

_FilterExcludedFilesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected