From 067d0a60384b5f12cfee622381cfb5905efb8e13 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 14 Aug 2018 20:38:39 -0400 Subject: Use pid-random suffixes for SQL files --- coverage/data.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'coverage/data.py') 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) -- cgit v1.2.1