diff --git a/base/deprecated.jl b/base/deprecated.jl index 19aa8f977ee30..8b271a2543e45 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -469,3 +469,4 @@ end scale!{T<:Base.LinAlg.BlasReal}(X::Array{T}, s::Complex) = error("scale!: Cannot scale a real array by a complex value in-place. Use scale(X::Array{Real}, s::Complex) instead.") @deprecate which(f::Callable, args...) @which f(args...) +@deprecate rmdir rm diff --git a/base/exports.jl b/base/exports.jl index 700623c0ca41d..07a3c26e37fcd 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1238,7 +1238,6 @@ export isfifo, isfile, islink, - isfileorlink, ispath, isreadable, issetgid, @@ -1256,7 +1255,6 @@ export operm, pwd, rm, - rmdir, stat, symlink, tempdir, diff --git a/base/file.jl b/base/file.jl index d5fb78c0fbadf..25d2188e08b01 100644 --- a/base/file.jl +++ b/base/file.jl @@ -51,22 +51,24 @@ end mkdir(path::String, mode::Signed) = error("mode must be an unsigned integer; try 0o$mode") mkpath(path::String, mode::Signed) = error("mode must be an unsigned integer; try 0o$mode") -function rmdir(path::String, recursive::Bool=false) - if recursive - for p=readdir(path) - p = joinpath(path, p) - isfileorlink(p) ? rm(p) : rmdir(p, true) +function rm(path::String; recursive::Bool=false) + if islink(path) || !isdir(path) + FS.unlink(path) + else + if recursive + for p in readdir(path) + rm(joinpath(path, p), recursive=true) + end end + @unix_only ret = ccall(:rmdir, Int32, (Ptr{Uint8},), bytestring(path)) + @windows_only ret = ccall(:_wrmdir, Int32, (Ptr{Uint16},), utf16(path)) + systemerror(:rmdir, ret != 0) end - @unix_only ret = ccall(:rmdir, Int32, (Ptr{Uint8},), bytestring(path)) - @windows_only ret = ccall(:_wrmdir, Int32, (Ptr{Uint16},), utf16(path)) - systemerror(:rmdir, ret != 0) end # The following use Unix command line facilites -rm(path::String) = FS.unlink(path) cp(src::String, dst::String) = FS.sendfile(src, dst) mv(src::String, dst::String) = FS.rename(src, dst) touch(path::String) = run(`touch $path`) diff --git a/base/pkg/cache.jl b/base/pkg/cache.jl index f77df9c16c8ce..b0d7bc4d4e9c1 100644 --- a/base/pkg/cache.jl +++ b/base/pkg/cache.jl @@ -33,7 +33,7 @@ function prefetch{S<:String}(pkg::String, url::String, sha1s::Vector{S}) info("Cloning cache of $pkg from $url") try Git.run(`clone -q --mirror $url $cache`) catch - rmdir(cache, true) + rm(cache, recursive=true) rethrow() end end diff --git a/base/pkg/dir.jl b/base/pkg/dir.jl index 869e9c553fce0..722357b11af4a 100644 --- a/base/pkg/dir.jl +++ b/base/pkg/dir.jl @@ -45,7 +45,7 @@ function init(meta::String=DEFAULT_META, branch::String=META_BRANCH) run(`touch REQUIRE`) end catch e - rmdir(dir, true) + rm(dir, recursive=true) rethrow(e) end end diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index 509988c995a78..0e64bd90fe1d5 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -150,7 +150,7 @@ function clone(url::String, pkg::String) Git.run(`clone -q $url $pkg`) Git.set_remote_url(url, dir=pkg) catch - rmdir(pkg, true) + rm(pkg, recursive=true) rethrow() end isempty(Reqs.parse("$pkg/REQUIRE")) && return diff --git a/base/pkg/generate.jl b/base/pkg/generate.jl index 7e70a37ad3ec2..e77ddd671a441 100644 --- a/base/pkg/generate.jl +++ b/base/pkg/generate.jl @@ -76,7 +76,7 @@ function package( end end catch - isnew && rmdir(pkg, true) + isnew && rm(pkg, recursive=true) rethrow() end end diff --git a/base/pkg/write.jl b/base/pkg/write.jl index 30f4fd768f07e..7df4cd9c0824e 100644 --- a/base/pkg/write.jl +++ b/base/pkg/write.jl @@ -39,7 +39,7 @@ end function remove(pkg::String) isdir(".trash") || mkdir(".trash") - ispath(".trash/$pkg") && rmdir(".trash/$pkg", true) + ispath(".trash/$pkg") && rm(".trash/$pkg", recursive=true) mv(pkg, ".trash/$pkg") end diff --git a/base/stat.jl b/base/stat.jl index 30129bcefb833..b76e7f28152e9 100644 --- a/base/stat.jl +++ b/base/stat.jl @@ -58,15 +58,14 @@ lstat(path...) = lstat(joinpath(path...)) # mode type predicates - ispath(st::StatStruct) = st.mode & 0xf000 != 0x0000 - isfifo(st::StatStruct) = st.mode & 0xf000 == 0x1000 - ischardev(st::StatStruct) = st.mode & 0xf000 == 0x2000 - isdir(st::StatStruct) = st.mode & 0xf000 == 0x4000 - isblockdev(st::StatStruct) = st.mode & 0xf000 == 0x6000 - isfile(st::StatStruct) = st.mode & 0xf000 == 0x8000 - islink(st::StatStruct) = st.mode & 0xf000 == 0xa000 - issocket(st::StatStruct) = st.mode & 0xf000 == 0xc000 -isfileorlink(st::StatStruct) = st.mode & 0xd000 == 0x8000 + ispath(st::StatStruct) = st.mode & 0xf000 != 0x0000 + isfifo(st::StatStruct) = st.mode & 0xf000 == 0x1000 + ischardev(st::StatStruct) = st.mode & 0xf000 == 0x2000 + isdir(st::StatStruct) = st.mode & 0xf000 == 0x4000 +isblockdev(st::StatStruct) = st.mode & 0xf000 == 0x6000 + isfile(st::StatStruct) = st.mode & 0xf000 == 0x8000 + islink(st::StatStruct) = st.mode & 0xf000 == 0xa000 + issocket(st::StatStruct) = st.mode & 0xf000 == 0xc000 # mode permission predicates @@ -74,8 +73,8 @@ issetuid(st::StatStruct) = (st.mode & 0o4000) > 0 issetgid(st::StatStruct) = (st.mode & 0o2000) > 0 issticky(st::StatStruct) = (st.mode & 0o1000) > 0 -isreadable(st::StatStruct) = (st.mode & 0o444) > 0 -iswritable(st::StatStruct) = (st.mode & 0o222) > 0 + isreadable(st::StatStruct) = (st.mode & 0o444) > 0 + iswritable(st::StatStruct) = (st.mode & 0o222) > 0 isexecutable(st::StatStruct) = (st.mode & 0o111) > 0 uperm(st::StatStruct) = uint8(st.mode >> 6) & 0x7 @@ -92,7 +91,6 @@ for f in { :isblockdev :isfile :islink - :isfileorlink :issocket :issetuid :issetgid @@ -108,7 +106,6 @@ for f in { end islink(path...) = islink(lstat(path...)) -isfileorlink(path...) = isfileorlink(lstat(path...)) # some convenience functions diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index fab6766675df9..d79562a86eabf 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -1778,9 +1778,10 @@ I/O Move a file from `src` to `dst`. -.. function:: rm(path::String) +.. function:: rm(path::String; recursive=false) - Delete the file at the given path. Note that this does not work on directories. + Delete the file, link, or empty directory at the given path. If ``recursive=true`` is + passed and the path is a directory, then all contents are removed recursively. .. function:: touch(path::String) @@ -5152,10 +5153,6 @@ System Create all directories in the given ``path``, with permissions ``mode``. ``mode`` defaults to 0o777, modified by the current file creation mask. -.. function:: rmdir(path, [recursive=false]) - - Remove the directory named ``path``. To remove a non-empty directory you must pass recursive true. - .. function:: getpid() -> Int32 Get julia's process ID. diff --git a/doc/stdlib/file.rst b/doc/stdlib/file.rst index 8e6c41ec74c0f..e38620c1f1b3a 100644 --- a/doc/stdlib/file.rst +++ b/doc/stdlib/file.rst @@ -33,10 +33,6 @@ Filesystem Returns ``true`` if ``path`` is a symbolic link, ``false`` otherwise. -.. function:: isfileorlink(path) -> Bool - - Returns ``true`` if ``path`` is a regular file or a symbolic link, ``false`` otherwise. - .. function:: ispath(path) -> Bool Returns ``true`` if ``path`` is a valid filesystem path, ``false`` otherwise. diff --git a/test/file.jl b/test/file.jl index 7fdf3b80654b0..dda8415153e8b 100644 --- a/test/file.jl +++ b/test/file.jl @@ -23,11 +23,9 @@ end @test isdir(dir) @test !isfile(dir) @test !islink(dir) -@test !isfileorlink(dir) @test !isdir(file) @test isfile(file) @test !islink(file) -@test isfileorlink(file) @test isreadable(file) @test iswritable(file) # Here's something else that might be UNIX-specific? @@ -54,7 +52,6 @@ newfile = joinpath(dir, "bfile.txt") mv(file, newfile) @test !ispath(file) @test isfile(newfile) -@test isfileorlink(newfile) file = newfile # Test renaming directories @@ -73,9 +70,9 @@ mv(a_tmpdir, b_tmpdir) b_stat = stat(b_tmpdir) @test Base.samefile(a_stat, b_stat) -rmdir(b_tmpdir) +rm(b_tmpdir) -# rmdir recursive TODO add links +# rm recursive TODO add links c_tmpdir = mktempdir() c_subdir = joinpath(c_tmpdir, "c_subdir") mkdir(c_subdir) @@ -84,9 +81,9 @@ cp(newfile, c_file) @test isdir(c_subdir) @test isfile(c_file) -@test_throws rmdir(c_tmpdir) +@test_throws SystemError rm(c_tmpdir) -rmdir(c_tmpdir, true) +rm(c_tmpdir, recursive=true) @test !isdir(c_tmpdir) @@ -298,8 +295,8 @@ close(f) @non_windowsxp_only rm(dirlink) rm(file) -rmdir(subdir) -rmdir(dir) +rm(subdir) +rm(dir) @test !ispath(file) @test !ispath(dir) diff --git a/test/git.jl b/test/git.jl index 8a6dfa3339625..218c96eb9a998 100644 --- a/test/git.jl +++ b/test/git.jl @@ -30,4 +30,4 @@ try cd(dir) do end git_verify(states[1:3]...) -end finally rmdir(dir, true) end +end finally rm(dir, recursive=true) end diff --git a/test/gitutils.jl b/test/gitutils.jl index a7dd36e7c72e7..1c6655905bb9b 100644 --- a/test/gitutils.jl +++ b/test/gitutils.jl @@ -91,7 +91,7 @@ function git_setup(h::Dict, i::Dict, w::Dict, parents::String...) # clear the repo for line in eachline(`ls -A`) name = chomp(line) - name == ".git" || rmdir(name, true) + name == ".git" || rm(name, recursive=true) end # create the head commit diff --git a/test/pkg.jl b/test/pkg.jl index e4627f1d64400..feeacd252cc0c 100644 --- a/test/pkg.jl +++ b/test/pkg.jl @@ -9,7 +9,7 @@ function temp_pkg_dir(fn::Function) fn() finally - rmdir(tmpdir, true) + rm(tmpdir, recursive=true) end end diff --git a/test/replcompletions.jl b/test/replcompletions.jl index 41e53d073e121..34a866fb0f018 100644 --- a/test/replcompletions.jl +++ b/test/replcompletions.jl @@ -90,8 +90,8 @@ c,r = test_latexcomplete(s) # @test "CompletionFoo2" in c # @test s[r] == "Completion" # -# rmdir(Pkg.dir("MyAwesomePackage")) -# rmdir(Pkg.dir("CompletionFooPackage")) +# rm(Pkg.dir("MyAwesomePackage")) +# rm(Pkg.dir("CompletionFooPackage")) #end @unix_only begin diff --git a/test/unicode.jl b/test/unicode.jl index cee22748366c3..7a9bf6fbc04dd 100644 --- a/test/unicode.jl +++ b/test/unicode.jl @@ -89,5 +89,5 @@ else for encoding in ["UTF-32BE", "UTF-32LE", "UTF-16BE", "UTF-16LE", "UTF-8"] rm(joinpath(unicodedir,encoding*".unicode")) end - rmdir(unicodedir) + rm(unicodedir) end