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

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
collisions.

Closes: #916499
parent 4d004550
Loading
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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):
        else:
            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),
                      is_dir)