Skip to content

Commit a315725

Browse files
committed
Replace use of mktemp
This uses NamedTemporaryFile with delete=False to replace the one use of the deprecated mktemp function in smmap (reported in #41). This avoids the race condition inherent to mktemp, as the file is named and created together in a way that is effectively atomic. Because NamedTemporaryFile is not being used to automatically delete the file, it use and cleanup are unaffected by the change.
1 parent 7d6f97c commit a315725

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

smmap/test/lib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ class FileCreator:
1818
def __init__(self, size, prefix=''):
1919
assert size, "Require size to be larger 0"
2020

21-
self._path = tempfile.mktemp(prefix=prefix)
2221
self._size = size
2322

24-
with open(self._path, "wb") as fp:
25-
fp.seek(size - 1)
26-
fp.write(b'1')
23+
with tempfile.NamedTemporaryFile("wb", prefix=prefix, delete=False) as file:
24+
self._path = file.name
25+
file.seek(size - 1)
26+
file.write(b'1')
2727

2828
assert os.path.getsize(self.path) == size
2929

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy