diff options
Diffstat (limited to 'bitbake/lib/bb/utils.py')
| -rw-r--r-- | bitbake/lib/bb/utils.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 95b3c89805..92d44c5260 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
| @@ -28,6 +28,8 @@ import signal | |||
| 28 | import collections | 28 | import collections |
| 29 | import copy | 29 | import copy |
| 30 | import ctypes | 30 | import ctypes |
| 31 | import random | ||
| 32 | import tempfile | ||
| 31 | from subprocess import getstatusoutput | 33 | from subprocess import getstatusoutput |
| 32 | from contextlib import contextmanager | 34 | from contextlib import contextmanager |
| 33 | from ctypes import cdll | 35 | from ctypes import cdll |
| @@ -1756,3 +1758,22 @@ def is_local_uid(uid=''): | |||
| 1756 | if str(uid) == line_split[2]: | 1758 | if str(uid) == line_split[2]: |
| 1757 | return True | 1759 | return True |
| 1758 | return False | 1760 | return False |
| 1761 | |||
| 1762 | def mkstemp(suffix=None, prefix=None, dir=None, text=False): | ||
| 1763 | """ | ||
| 1764 | Generates a unique filename, independent of time. | ||
| 1765 | |||
| 1766 | mkstemp() in glibc (at least) generates unique file names based on the | ||
| 1767 | current system time. When combined with highly parallel builds, and | ||
| 1768 | operating over NFS (e.g. shared sstate/downloads) this can result in | ||
| 1769 | conflicts and race conditions. | ||
| 1770 | |||
| 1771 | This function adds additional entropy to the file name so that a collision | ||
| 1772 | is independent of time and thus extremely unlikely. | ||
| 1773 | """ | ||
| 1774 | entropy = "".join(random.choices("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", k=20)) | ||
| 1775 | if prefix: | ||
| 1776 | prefix = prefix + entropy | ||
| 1777 | else: | ||
| 1778 | prefix = tempfile.gettempprefix() + entropy | ||
| 1779 | return tempfile.mkstemp(suffix=suffix, prefix=prefix, dir=dir, text=text) | ||
