Return true if child is subdirectory of parent. Assumes both paths are absolute and don't contain symlinks.
(parent, child)
| 6856 | if _IsParentOrSame(e, os.path.abspath(f)))] |
| 6857 | |
| 6858 | def _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 | |
| 6876 | def main(): |
| 6877 | filenames = ParseArguments(sys.argv[1:]) |
no outgoing calls
no test coverage detected