-
-
Notifications
You must be signed in to change notification settings - Fork 939
Safer tempfiles #1450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safer tempfiles #1450
Changes from 8 commits
27a915b
76b0e06
320523a
2b5467e
2d24778
6fec99e
32785d3
4256ccf
6c832bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,8 @@ class TemporaryFileSwap(object): | |
|
||
def __init__(self, file_path: PathLike) -> None: | ||
self.file_path = file_path | ||
self.tmp_file_path = str(self.file_path) + tempfile.mktemp("", "", "") | ||
self.tmp_file_path = str(self.file_path) + osp.basename(tempfile.mkstemp("", "", "")[1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user is responsible for closing the file in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Byron, to be exact, functions that create temporary file names (such as Also, if nothing else, |
||
|
||
# it may be that the source does not exist | ||
try: | ||
os.rename(self.file_path, self.tmp_file_path) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this effectively opens a temporary file, extracts the name, and then forgets about the opened file.
As there are no destructors in
python
, it's unclear when (or if) this resource is ever freed and is effectively leaking a very limited process resource over time.