-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add temporary directory creation on Dir class #2911
Conversation
Dir class assumes the responsability of resolving the system tmpdir from the Tempfile class. Reference: - http://rxr.whitequark.org/mri/source/lib/tmpdir.rb
@jhass for some reason the tests are failing only on linux builds, could you take a look to check what I'm doing wrong? |
original_tmpdir = ENV["TMPDIR"]? | ||
ENV["TMPDIR"] = "/my/tmp" | ||
Dir.tmpdir.should eq("/my/tmp") | ||
ENV["TMPDIR"] = original_tmpdir if original_tmpdir |
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.
If TMPDIR
wasn't set, this keeps it set at "/my/tmp"
.
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.
Thanks, I'll fix that!
I was trying to create a better interface to work with temporary directories, something like: Dir.mktmpdir do |dir|
....
end On which the |
There's FileUtils.rm_r |
@asterite thanks, I didn't remembered to check FileUtils. |
Thanks! Before merging this, I would try to think of a different name, |
The mkdtemp function creates a directory with a unique name. If it succeeds, it overwrites template with the name of the directory, and returns template. As with mktemp and mkstemp, template should be a string ending with ‘XXXXXX’. The directory is created using mode 0700 References: - http://www.gnu.org/software/libc/manual/html_node/Temporary-Files.html - http://ruby-doc.org/stdlib-2.0.0/libdoc/tmpdir/rdoc/Dir.html
@asterite I was trying to keep Ruby's syntax, I would happily take your name suggestions. |
I'm not sure if is good that we add Perhaps this helper method can be treated in similar way as Just a thought. |
@luislavena you are absolutely correct, I was actually wondering why the paths were being concatenated that way (a + b...) but considering your comment, which haven't crossed my mind until now, makes sense. However I think we should find a more elegant way of doing this. Either way, for now I will fix this. |
Ideally we should have a way to do |
@asterite can I refactor this and move |
As discussed on #2911
@marceloboeira Ideally I'd like this method to be in Problem is, I don't know what a good name for |
What about: module Dir
def self.delete(path, *, recursive= false)
end
end |
Could you accept this pull request and we rename the methods later? I really would like this feature for some projects and I would not like to "monkey patch". Also I think this is something important for several projects, not only mine. |
@marceloboeira There's nothing wrong with "monkey patching" until this gets merged with time |
so the only thing missing here is rename rm_r to delete ... or what is ? ... would love to use this feature :) |
@grosser not sure anymore. I need this feature, I believe I will create a temp shard to use it while I wait for it to be merged. |
TL;DR - This is a monkey-patch to create temporary directories with Crystal standard library. The PR is open, but still solving some issues. crystal-lang/crystal#2911 The mkdtemp function creates a directory with a unique name. If it succeeds, it overwrites template with the name of the directory, and returns template. As with mktemp and mkstemp, template should be a string ending with ‘XXXXXX’. The directory is created using mode 0700 References: - http://www.gnu.org/software/libc/manual/html_node/Temporary-Files.html - http://ruby-doc.org/stdlib-2.0.0/libdoc/tmpdir/rdoc/Dir.html
TL;DR - This is a monkey-patch to create temporary directories with Crystal standard library. The PR is open, but still solving some issues. crystal-lang/crystal#2911 The mkdtemp function creates a directory with a unique name. If it succeeds, it overwrites template with the name of the directory, and returns template. As with mktemp and mkstemp, template should be a string ending with ‘XXXXXX’. The directory is created using mode 0700 References: - http://www.gnu.org/software/libc/manual/html_node/Temporary-Files.html - http://ruby-doc.org/stdlib-2.0.0/libdoc/tmpdir/rdoc/Dir.html
This is pretty useful, especially for writing tests 👍 |
As discussed on crystal-lang#2911
I've submitted a PR that is simply a rebase of this one to master. #4096 |
@bramswenson thx! |
Usage:
Without prefix:
With prefix:
The solution uses the
LibC.mkdtemp
bind.The mkdtemp function creates a directory with a unique name. If it
succeeds, it overwrites template with the name of the directory, and
returns template. As with mktemp and mkstemp, template should be a
string ending with ‘XXXXXX’.
Reference: