Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita315725

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

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
assertsize,"Require size to be larger 0"
2020

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

24-
withopen(self._path,"wb")asfp:
25-
fp.seek(size-1)
26-
fp.write(b'1')
23+
withtempfile.NamedTemporaryFile("wb",prefix=prefix,delete=False)asfile:
24+
self._path=file.name
25+
file.seek(size-1)
26+
file.write(b'1')
2727

2828
assertos.path.getsize(self.path)==size
2929

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp