Skip to content
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

FIX don't shell out when you can mv #7046

Merged
merged 1 commit into from
Jun 9, 2014

Conversation

hayd
Copy link
Member

@hayd hayd commented May 30, 2014

fixes #7041

@simonster
Copy link
Member

AFAIK rmdir can only delete empty directories, so it's not a drop-in replacement for rm -rf. I'm not sure if we already have a function to delete files and folders recursively, but if not, it shouldn't be too hard to write.

@hayd
Copy link
Member Author

hayd commented May 31, 2014

Moved this aspect to a separate PR.

One potential solution is to add recursive argument (with the first few lines):

function rmdir(path::String, recursive::Bool=false)
    if recursive
        dir_contents = map(p -> joinpath(path, p), readdir(path))
        for f=dir_contents
            isfile(f) && rm(f) || rmdir(f, true)
        end
    end
    @unix_only ret = ccall(:rmdir, Int32, (Ptr{Uint8},), bytestring(path))
    @windows_only ret = ccall(:_rmdir, Int32, (Ptr{Uint8},), bytestring(path))
    systemerror(:rmdir, ret != 0)
end

Should I pull out the rm -rf bits and add this to a separate PR?

@StefanKarpinski
Copy link
Member

If this will also handle files then calling it rmrf might be better.

@hayd hayd mentioned this pull request May 31, 2014
@StefanKarpinski
Copy link
Member

Although I guess allowing recursive to also remove files would be reasonable too.

@hayd
Copy link
Member Author

hayd commented Jun 4, 2014

@simonster @StefanKarpinski I've fixed this up to be just the two calls to mv.

@simonster
Copy link
Member

I think that mv() requires that the second argument be the new path as opposed to the destination directory.

@hayd hayd changed the title FIX don't shell out when you can mv or rmdir FIX don't shell out when you can mv Jun 6, 2014
@hayd
Copy link
Member Author

hayd commented Jun 6, 2014

@simonster you're right, sorry about that. corrected

JeffBezanson added a commit that referenced this pull request Jun 9, 2014
FIX don't shell out when you can mv
@JeffBezanson JeffBezanson merged commit b771481 into JuliaLang:master Jun 9, 2014
@hayd hayd deleted the dont_shell_out branch June 9, 2014 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pkg should not shell out for filesystem calls
4 participants