Remove Tempfile#6485
Conversation
| # It is the caller's responsibility to remove the file when no longer needed. | ||
| def self.tempfile(prefix : String?, suffix : String?, *, dir : String = Dir.tempdir, encoding = nil, invalid = nil) | ||
| fileno, path = Crystal::System::File.mktemp(prefix, suffix, dir) | ||
| new(path, fileno, blocking: true, encoding: encoding, invalid: invalid) |
There was a problem hiding this comment.
Not sure... I just copied it form Tempfile#initialize.
There was a problem hiding this comment.
all files use blocking IO anyway because O_NONBLOCK has no effect on files.
83d62c8 to
e511c80
Compare
|
As said in issues about this, I don't like this breaking change. I prefer to keep concerns distinct, and really see no need to push this into corelib. |
e511c80 to
e87ba4e
Compare
|
I think we established that there is little reason for An alternative option might be to keep But the changes in the method signatures need to be breaking anyways in order to provide a sane API. |
e87ba4e to
089e9fe
Compare
| # It is the caller's responsibility to remove the file when no longer needed. | ||
| def self.tempfile(prefix : String?, suffix : String?, *, dir : String = Dir.tempdir, encoding = nil, invalid = nil) | ||
| fileno, path = Crystal::System::File.mktemp(prefix, suffix, dir) | ||
| new(path, fileno, blocking: true, encoding: encoding, invalid: invalid) |
There was a problem hiding this comment.
all files use blocking IO anyway because O_NONBLOCK has no effect on files.
089e9fe to
cf9eb74
Compare
|
Rebased |
cf9eb74 to
400f70f
Compare
sdogruyol
left a comment
There was a problem hiding this comment.
Thank you @straight-shoota 👍
|
@ysbaddaden Would you feel more comfortable if we put the tempfile methods back in |
|
I see no reason why they can't be in the corelib, it's not particularly much more code (most of the code would be required as part of crystal/system anyway) and it's only dependency is libc. It doesn't drag in anything more to the corelib. This PR is fine as-is. |
asterite
left a comment
There was a problem hiding this comment.
I like this change. It removes one type from the standard library (Tempfile) which isn't much different than a file. So I find this way simpler than the previous one.
This removes
Tempfileand places its methods inFileandDiras proposed in #5939 and standardizes the arguments as proposed in #5938. All tempfile methods now receiveprefix,suffix(and optionaldir) arguments. There are also overload for only one argumentsuffix(and optionaldir) because it is pretty common to create a temp file with a specific extension.Previously,
require "tempfile"was needed in order to use this feature. Now that it is integrated intoFileI think it makes sense to have it in corelib.I'm not sure if
tempfilewith block should perhaps actually delete the tempfile. Or if there could be some other mechanism to simplify automatic deletion of tempfiles. This could be discussed in a follow-up issue, though.Same goes for the addition of a method to create a temporary directory (see #4096). The only issue with this is that
Dir.tempdirwould also be a fitting name for this but it is now used to query the tempdir environment setting.Related to that, there could also be a future improvement to allow modifying the global tempdir, probably in a way similar to
Time::Location.local.Fixes #5939 and #5938