-
-
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
Feature/mktmpdir #4096
Feature/mktmpdir #4096
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
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
As discussed on crystal-lang#2911
👍 |
src/dir.cr
Outdated
end | ||
|
||
# Creates a new temporary directory within the lifecycle | ||
# of the given block and destroys it, and its content, later on. |
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.
...and its content, when the block returns
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.
👍
src/dir.cr
Outdated
# Dir.tmpdir # => "/tmp" | ||
# ``` | ||
def self.tmpdir | ||
unless tmpdir = ENV["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.
This is a bit confusing, how about
tmpdir = ENV["TMPDIR"]? || "/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.
👍
@bramswenson do you want to make the changes? because if I would require access to your fork/branch. |
@marceloboeira @RX14 Done! Thanks! |
@bramswenson great! |
# Dir.rm_r("dir") | ||
# Dir.rm_r("file.cr") | ||
# ``` | ||
def self.rm_r(path : String) |
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.
This belongs to FileUtils, not Dir
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.
Dir can rm_r , FileUtils can rm_r too .
just like String can have add method , Number can add too .
Right ?
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.
@sevk stop trolling please.
@bramswenson Thank you for this! In general the PR looks very good. However:
I'm all the time unsure about File, Dir, FileUtils and where to put things. Maybe things are too complex/messy right now. I'll discuss this with the team, maybe we can just put all methods in File and Dir and remove FileUtils. |
For now we can merge your change if it doesn't introduce breaking changes (Use |
@asterite Thanks for the kind words, but I did nothing but the rebase to master out of selfish desire to use this feature ;) @marceloboeira Did the actual work and there was reasonable discussion about the move between |
I will say that the removal of |
I didn't have time to take a look at the comments yet folks, but I will do it soon. @bramswenson thanks for the invitation to your repository and the efforts on making it happen. 👍 |
I was about to (suggest to) add this! About naming I was thinking, since we already have the Temporary::File.new # gives a file
Temporary::Dir.new # gives a dir
Temporary::Dir.open do |dir|
# do something with the `dir`
puts dir.path
end # the block ensures that the temp dir is deleted
Temporary.create_name("foo.XXX") # gives a (file/dir)name following a pattern
# etc.. |
I think we shouldn't have "tempdir" and "tempfile" classes, just methods on |
I thought the same. |
@RX14 any updates here? |
@marceloboeira |
Too old, I think should be closed now. A new PR can be opened if wanted. As now, to create a temp dir: dir = File.tempname
Dir.mkdir dir
begin
# do things
ensure
FileUtils.rm_rf dir
end |
This is simply a rebase of #2911 to current master (03-01-2017)