-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-38355][PYTHON][TESTS] Use mkstemp instead of mktemp
#35775
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
[SPARK-38355][PYTHON][TESTS] Use mkstemp instead of mktemp
#35775
Conversation
mktemp to mkstempmkstemp instead of mktemp
|
cc @HyukjinKwon |
mkstemp instead of mktempmkstemp instead of mktemp
|
Looks pretty good, but would you mind elaborating the PR description why For example, "Unlike mktemp , mkstemp is actually guaranteed to create a unique file that cannot possibly clash with any other program trying to create a temporary file" ?? (refer to https://www.gnu.org/software/libc/manual/html_node/Temporary-Files.html) |
| def temp_file(self): | ||
| with self.temp_dir() as tmp: | ||
| yield tempfile.mktemp(dir=tmp) | ||
| yield tempfile.mkstemp(dir=tmp)[1] |
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.
qq: Does mkstemp always guarantees returning the (fd, name pair) ?? Maybe don't we need to check the length or something to make sure mkstemp returning the proper value ?
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.
|
Merged to master. |
|
Can one of the admins verify this patch? |
### What changes were proposed in this pull request? To change from `mktemp` to `mkstemp`. ### Why are the changes needed? Pandas API on Spark use `mktemp` in test. `mktemp` "THIS FUNCTION IS UNSAFE AND SHOULD NOT BE USED. The file name may refer to a file that did not exist at some point, but by the time you get around to creating it, someone else may have beaten you to the punch." ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Got the green light. Closes apache#35775 from bjornjorgensen/Upgrade-mktemp-to-mkstemp. Authored-by: bjornjorgensen <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
|
@itholic @HyukjinKwon and @LuciferYang mktemp is deprecated since Python 2.3 witch was released July 29, 2003. This is the text that I got from Sonarqubes :
In the past, it has led to the following vulnerabilities I did have some issues implementing this function. What to do with So I open a post at SO upgrade-from-mktemp-to-mkstemp |
|
LGTM +1 |
What changes were proposed in this pull request?
To change from
mktemptomkstemp.Why are the changes needed?
Pandas API on Spark use
mktempin test.mktemp"THIS FUNCTION IS UNSAFE AND SHOULD NOT BE USED. The file name mayrefer to a file that did not exist at some point, but by the time
you get around to creating it, someone else may have beaten you to
the punch."
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Got the green light.