Skip to content

Commit d612c47

Browse files
authored
file.jl: add a note differentiating cp function from cp command (#41761)
The `cp` function behaves more deterministically than the command and can have serious consequences if `force=true` when `dst` is a directory. Add a note to the docstring mentioning this.
1 parent 5ff9e3a commit d612c47

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

base/file.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,13 @@ If `follow_symlinks=false`, and `src` is a symbolic link, `dst` will be created
359359
symbolic link. If `follow_symlinks=true` and `src` is a symbolic link, `dst` will be a copy
360360
of the file or directory `src` refers to.
361361
Return `dst`.
362+
363+
!!! note
364+
The `cp` function is different from the `cp` command. The `cp` function always operates on
365+
the assumption that `dst` is a file, while the command does different things depending
366+
on whether `dst` is a directory or a file.
367+
Using `force=true` when `dst` is a directory will result in loss of all the contents present
368+
in the `dst` directory, and `dst` will become a file that has the contents of `src` instead.
362369
"""
363370
function cp(src::AbstractString, dst::AbstractString; force::Bool=false,
364371
follow_symlinks::Bool=false)

0 commit comments

Comments
 (0)