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

new__cp_function #10888

Merged
merged 1 commit into from
Apr 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ Library improvements

* The `randexp` and `randexp!` functions are exported ([#9144])

* File

* Added function `readlink` which returns the value of a symbolic link "path" ([#10714]).

* The `cp` function now accepts keyword arguments `remove_destination` and `follow_symlinks` ([#10888]).

* Other improvements

* You can now tab-complete Emoji characters via their [short names](http://www.emoji-cheat-sheet.com/), using `\:name:<tab>` ([#10709]).
Expand Down Expand Up @@ -1374,9 +1380,11 @@ Too numerous to mention.
[#10659]: https://github.com/JuliaLang/julia/issues/10659
[#10679]: https://github.com/JuliaLang/julia/issues/10679
[#10709]: https://github.com/JuliaLang/julia/issues/10709
[#10714]: https://github.com/JuliaLang/julia/pull/10714
[#10747]: https://github.com/JuliaLang/julia/issues/10747
[#10844]: https://github.com/JuliaLang/julia/issues/10844
[#10870]: https://github.com/JuliaLang/julia/issues/10870
[#10885]: https://github.com/JuliaLang/julia/issues/10885
[#10888]: https://github.com/JuliaLang/julia/pull/10888
[#10893]: https://github.com/JuliaLang/julia/pull/10893
[#10914]: https://github.com/JuliaLang/julia/issues/10914
49 changes: 39 additions & 10 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,47 @@ end

# The following use Unix command line facilites

function cp(src::AbstractString, dst::AbstractString; recursive::Bool=false)
if islink(src) || !isdir(src)
FS.sendfile(src, dst)
elseif recursive
mkdir(dst)
for p in readdir(src)
cp(joinpath(src, p), joinpath(dst, p), recursive=recursive)
function cptree(src::AbstractString, dst::AbstractString; remove_destination::Bool=false,
follow_symlinks::Bool=false)
isdir(src) || throw(ArgumentError("'$src' is not a directory. Use `cp(src, dst)`"))
if ispath(dst)
if remove_destination
rm(dst; recursive=true)
else
throw(ArgumentError(string("'$dst' exists. `remove_destination=true` ",
"is required to remove '$dst' before copying.")))
end
end
mkdir(dst)
for name in readdir(src)
srcname = joinpath(src, name)
if !follow_symlinks && islink(srcname)
symlink(readlink(srcname), joinpath(dst, name))
elseif isdir(srcname)
cptree(srcname, joinpath(dst, name); remove_destination=remove_destination,
follow_symlinks=follow_symlinks)
else
FS.sendfile(srcname, joinpath(dst, name))
end
end
end

function cp(src::AbstractString, dst::AbstractString; remove_destination::Bool=false,
follow_symlinks::Bool=false)
if ispath(dst)
if remove_destination
rm(dst; recursive=true)
else
throw(ArgumentError(string("'$dst' exists. `remove_destination=true` ",
"is required to remove '$dst' before copying.")))
end
end
if !follow_symlinks && islink(src)
symlink(readlink(src), dst)
elseif isdir(src)
cptree(src, dst; remove_destination=remove_destination, follow_symlinks=follow_symlinks)
else
throw(ArgumentError(string("'$src' is a directory. ",
"Use `cp(src, dst, recursive=true)` ",
"to copy directories recursively.")))
FS.sendfile(src, dst)
end
end
mv(src::AbstractString, dst::AbstractString) = FS.rename(src, dst)
Expand Down
10 changes: 7 additions & 3 deletions doc/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5172,10 +5172,14 @@ Millisecond(v)

"),

("Base","cp","cp(src::AbstractString, dst::AbstractString; recursive=false)
("Base","cp","cp(src::AbstractString, dst::AbstractString; remove_destination::Bool=false, follow_symlinks::Bool=false)

Copy a file from *src* to *dest*. Passing \"recursive=true\" will
enable recursive copying of directories.
Copy the file, link, or directory from *src* to *dest*.
\"remove_destination=true\" will first remove an existing `dst`.

If `follow_symlinks=false`, and src is a symbolic link, dst will be created as a symbolic link.
If `follow_symlinks=true` and src is a symbolic link, dst will be a copy of the file or directory
`src` refers to.

"),

Expand Down
10 changes: 7 additions & 3 deletions doc/stdlib/file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,14 @@
Like uperm but gets the permissions for people who neither own the file nor are a
member of the group owning the file

.. function:: cp(src::AbstractString,dst::AbstractString; recursive=false)
.. function:: cp(src::AbstractString, dst::AbstractString; remove_destination::Bool=false, follow_symlinks::Bool=false)

Copy a file from `src` to `dest`. Passing ``recursive=true`` will enable
recursive copying of directories.
Copy the file, link, or directory from *src* to *dest*.
\"remove_destination=true\" will first remove an existing `dst`.

If `follow_symlinks=false`, and src is a symbolic link, dst will be created as a symbolic link.
If `follow_symlinks=true` and src is a symbolic link, dst will be a copy of the file or directory
`src` refers to.

.. function:: download(url,[localfile])

Expand Down
Loading