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