Return true if child is subdirectory of parent. Assumes both paths are absolute and don't contain symlinks.
(parent, child)
| 7989 | |
| 7990 | |
| 7991 | def _IsParentOrSame(parent, child): |
| 7992 | """Return true if child is subdirectory of parent. |
| 7993 | Assumes both paths are absolute and don't contain symlinks. |
| 7994 | """ |
| 7995 | parent = os.path.normpath(parent) |
| 7996 | child = os.path.normpath(child) |
| 7997 | if parent == child: |
| 7998 | return True |
| 7999 | |
| 8000 | prefix = os.path.commonprefix([parent, child]) |
| 8001 | if prefix != parent: |
| 8002 | return False |
| 8003 | # Note: os.path.commonprefix operates on character basis, so |
| 8004 | # take extra care of situations like '/foo/ba' and '/foo/bar/baz' |
| 8005 | child_suffix = child[len(prefix) :] |
| 8006 | child_suffix = child_suffix.lstrip(os.sep) |
| 8007 | return child == os.path.join(prefix, child_suffix) |
| 8008 | |
| 8009 | |
| 8010 | def main(): |
no test coverage detected
searching dependent graphs…