Verified Commit c0f4ec57 authored by Niko Tyni's avatar Niko Tyni Committed by Paul Gevers

Ensure that autocleaned TempPath file names are unique

In some circumstances the TempPath.__del__() finalizer may get
run late enough that a new TempPath instance has been created
with the same name.

Prepend a running counter to the actual file names used to prevent

Closes: #916499
parent 4d004550
Pipeline #29011 passed with stage
in 8 minutes and 34 seconds
......@@ -1484,6 +1484,10 @@ class TempPath(Path):
These are only guaranteed to exit within one testbed run.
# private; used to make sure the names of autocleaned files don't collide
_filename_prefix = 1
def __init__(self, testbed, name, is_dir=False, autoclean=True):
'''Create a temporary Path object.
......@@ -1507,6 +1511,10 @@ class TempPath(Path):
host = testbed.output_dir
self.autoclean = autoclean
if autoclean:
name = str(self._filename_prefix) + '-' + name
TempPath._filename_prefix += 1
Path.__init__(self, testbed, os.path.join(host, name),
os.path.join(testbed.scratch, name),
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment