diff options
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r-- | bitbake/lib/bb/utils.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 0624a4f3e9..b401fa5ec7 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -1828,6 +1828,29 @@ def mkstemp(suffix=None, prefix=None, dir=None, text=False): | |||
1828 | prefix = tempfile.gettempprefix() + entropy | 1828 | prefix = tempfile.gettempprefix() + entropy |
1829 | return tempfile.mkstemp(suffix=suffix, prefix=prefix, dir=dir, text=text) | 1829 | return tempfile.mkstemp(suffix=suffix, prefix=prefix, dir=dir, text=text) |
1830 | 1830 | ||
1831 | def path_is_descendant(descendant, ancestor): | ||
1832 | """ | ||
1833 | Returns True if the path `descendant` is a descendant of `ancestor` | ||
1834 | (including being equivalent to `ancestor` itself). Otherwise returns False. | ||
1835 | Correctly accounts for symlinks, bind mounts, etc. by using | ||
1836 | os.path.samestat() to compare paths | ||
1837 | |||
1838 | May raise any exception that os.stat() raises | ||
1839 | """ | ||
1840 | |||
1841 | ancestor_stat = os.stat(ancestor) | ||
1842 | |||
1843 | # Recurse up each directory component of the descendant to see if it is | ||
1844 | # equivalent to the ancestor | ||
1845 | check_dir = os.path.abspath(descendant).rstrip("/") | ||
1846 | while check_dir: | ||
1847 | check_stat = os.stat(check_dir) | ||
1848 | if os.path.samestat(check_stat, ancestor_stat): | ||
1849 | return True | ||
1850 | check_dir = os.path.dirname(check_dir).rstrip("/") | ||
1851 | |||
1852 | return False | ||
1853 | |||
1831 | # If we don't have a timeout of some kind and a process/thread exits badly (for example | 1854 | # If we don't have a timeout of some kind and a process/thread exits badly (for example |
1832 | # OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better | 1855 | # OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better |
1833 | # we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked. | 1856 | # we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked. |