summaryrefslogtreecommitdiff
path: root/coverage/data.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-08-14 20:38:39 -0400
committerNed Batchelder <ned@nedbatchelder.com>2018-08-14 20:38:39 -0400
commit067d0a60384b5f12cfee622381cfb5905efb8e13 (patch)
tree68327a81460c1751ceeb6286967d524b75dd261f /coverage/data.py
parentda37af9a65b144ce6b1f26430bcbc9786e055f8b (diff)
downloadpython-coveragepy-git-067d0a60384b5f12cfee622381cfb5905efb8e13.tar.gz
Use pid-random suffixes for SQL files
Diffstat (limited to 'coverage/data.py')
-rw-r--r--coverage/data.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/coverage/data.py b/coverage/data.py
index 5e85fc10..aa23e7d4 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -21,6 +21,17 @@ from coverage.misc import CoverageException, file_be_gone, isolate_module
os = isolate_module(os)
+def filename_suffix(suffix):
+ if suffix is True:
+ # If data_suffix was a simple true value, then make a suffix with
+ # plenty of distinguishing information. We do this here in
+ # `save()` at the last minute so that the pid will be correct even
+ # if the process forks.
+ dice = random.Random(os.urandom(8)).randint(0, 999999)
+ suffix = "%s.%s.%06d" % (socket.gethostname(), os.getpid(), dice)
+ return suffix
+
+
class CoverageJsonData(object):
"""Manages collected coverage data, including file storage.
@@ -444,15 +455,7 @@ class CoverageJsonData(object):
"""
filename = self.filename
- suffix = self.suffix
- if suffix is True:
- # If data_suffix was a simple true value, then make a suffix with
- # plenty of distinguishing information. We do this here in
- # `save()` at the last minute so that the pid will be correct even
- # if the process forks.
- dice = random.Random(os.urandom(8)).randint(0, 999999)
- suffix = "%s.%s.%06d" % (socket.gethostname(), os.getpid(), dice)
-
+ suffix = filename_suffix(self.suffix)
if suffix:
filename += "." + suffix
self._write_file(filename)