Skip to content

Commit

Permalink
Rename remove_destination to force in cp, mv, and cptree
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Feb 15, 2018
1 parent fd06d20 commit 17771b6
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 71 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,9 @@ Deprecated or removed

* `scale!` has been deprecated in favor of `mul!`, `lmul!`, and `rmul!` ([#25701], [#25812]).

* The `remove_destination` keyword argument to `cp`, `mv`, and the unexported `cptree`
has been renamed to `force` ([#25979]).

* The methods of `range` based on positional arguments have been deprecated in favor of
keyword arguments ([#25896]).

Expand Down
6 changes: 6 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,12 @@ end
# PR #23332
@deprecate ^(x, p::Integer) Base.power_by_squaring(x,p)

# Issue #25979
# The `remove_destination` keyword to `cp`, `mv`, and the unexported `cptree` has been
# renamed to `force`. To remove this deprecation, remove the `remove_destination` keyword
# argument from the function signatures as well as the internal logic that deals with the
# renaming. These live in base/file.jl.

# issue #25928
@deprecate wait(t::Task) fetch(t)

Expand Down
61 changes: 41 additions & 20 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ end

# The following use Unix command line facilites
function checkfor_mv_cp_cptree(src::AbstractString, dst::AbstractString, txt::AbstractString;
remove_destination::Bool=false)
force::Bool=false)
if ispath(dst)
if remove_destination
if force
# Check for issue when: (src == dst) or when one is a link to the other
# https://github.com/JuliaLang/julia/pull/11172#issuecomment-100391076
if Base.samefile(src, dst)
Expand All @@ -186,23 +186,30 @@ function checkfor_mv_cp_cptree(src::AbstractString, dst::AbstractString, txt::Ab
end
rm(dst; recursive=true)
else
throw(ArgumentError(string("'$dst' exists. `remove_destination=true` ",
throw(ArgumentError(string("'$dst' exists. `force=true` ",
"is required to remove '$dst' before $(txt).")))
end
end
end

function cptree(src::AbstractString, dst::AbstractString; remove_destination::Bool=false,
follow_symlinks::Bool=false)
function cptree(src::AbstractString, dst::AbstractString; force::Bool=false,
follow_symlinks::Bool=false,
remove_destination::Union{Bool,Nothing}=nothing)
# TODO: Remove after 0.7
if remove_destination !== nothing
Base.depwarn("The `remove_destination` keyword argument is deprecated; use " *
"`force` instead", :cptree)
force = remove_destination
end
isdir(src) || throw(ArgumentError("'$src' is not a directory. Use `cp(src, dst)`"))
checkfor_mv_cp_cptree(src, dst, "copying"; remove_destination=remove_destination)
checkfor_mv_cp_cptree(src, dst, "copying"; force=force)
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,
cptree(srcname, joinpath(dst, name); force=force,
follow_symlinks=follow_symlinks)
else
sendfile(srcname, joinpath(dst, name))
Expand All @@ -211,35 +218,49 @@ function cptree(src::AbstractString, dst::AbstractString; remove_destination::Bo
end

"""
cp(src::AbstractString, dst::AbstractString; remove_destination::Bool=false, follow_symlinks::Bool=false)
cp(src::AbstractString, dst::AbstractString; force::Bool=false, follow_symlinks::Bool=false)
Copy the file, link, or directory from `src` to `dest`.
`remove_destination=true` will first remove an existing `dst`.
`force=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 cp(src::AbstractString, dst::AbstractString; remove_destination::Bool=false,
follow_symlinks::Bool=false)
checkfor_mv_cp_cptree(src, dst, "copying"; remove_destination=remove_destination)
function cp(src::AbstractString, dst::AbstractString; force::Bool=false,
follow_symlinks::Bool=false,
remove_destination::Union{Bool,Nothing}=nothing)
# TODO: Remove after 0.7
if remove_destination !== nothing
Base.depwarn("The `remove_destination` keyword argument is deprecated; use " *
"`force` instead", :cp)
force = remove_destination
end
checkfor_mv_cp_cptree(src, dst, "copying"; force=force)
if !follow_symlinks && islink(src)
symlink(readlink(src), dst)
elseif isdir(src)
cptree(src, dst; remove_destination=remove_destination, follow_symlinks=follow_symlinks)
cptree(src, dst; force=force, follow_symlinks=follow_symlinks)
else
sendfile(src, dst)
end
end

"""
mv(src::AbstractString, dst::AbstractString; remove_destination::Bool=false)
mv(src::AbstractString, dst::AbstractString; force::Bool=false)
Move the file, link, or directory from `src` to `dst`.
`remove_destination=true` will first remove an existing `dst`.
"""
function mv(src::AbstractString, dst::AbstractString; remove_destination::Bool=false)
checkfor_mv_cp_cptree(src, dst, "moving"; remove_destination=remove_destination)
`force=true` will first remove an existing `dst`.
"""
function mv(src::AbstractString, dst::AbstractString; force::Bool=false,
remove_destination::Union{Bool,Nothing}=nothing)
# TODO: Remove after 0.7
if remove_destination !== nothing
Base.depwarn("The `remove_destination` keyword argument is deprecated; use " *
"`force` instead", :cp)
force = remove_destination
end
checkfor_mv_cp_cptree(src, dst, "moving"; force=force)
rename(src, dst)
end

Expand Down Expand Up @@ -532,8 +553,8 @@ function rename(src::AbstractString, dst::AbstractString)
err = ccall(:jl_fs_rename, Int32, (Cstring, Cstring), src, dst)
# on error, default to cp && rm
if err < 0
# remove_destination: is already done in the mv function
cp(src, dst; remove_destination=false, follow_symlinks=false)
# force: is already done in the mv function
cp(src, dst; force=false, follow_symlinks=false)
rm(src; recursive=true)
end
nothing
Expand Down
4 changes: 2 additions & 2 deletions contrib/build_sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ function link_sysimg(sysimg_path=nothing, cc=find_system_compiler(), debug=false
# Windows has difficulties overwriting a file in use so we first link to a temp file
if Sys.iswindows() && isfile(sysimg_file)
if success(pipeline(`$cc $FLAGS -o $sysimg_path.tmp $sysimg_path.o`; stdout=STDOUT, stderr=STDERR))
mv(sysimg_file, "$sysimg_file.old"; remove_destination=true)
mv("$sysimg_path.tmp", sysimg_file; remove_destination=true)
mv(sysimg_file, "$sysimg_file.old"; force=true)
mv("$sysimg_path.tmp", sysimg_file; force=true)
end
else
run(`$cc $FLAGS -o $sysimg_file $sysimg_path.o`)
Expand Down
2 changes: 1 addition & 1 deletion doc/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ENV["JULIA_PKGDIR"] = joinpath(@__DIR__, "deps")
using Pkg
Pkg.init()
cp(joinpath(@__DIR__, "REQUIRE"), Pkg.dir("REQUIRE"); remove_destination = true)
cp(joinpath(@__DIR__, "REQUIRE"), Pkg.dir("REQUIRE"); force = true)
Pkg.update()
Pkg.resolve()

Expand Down
Loading

0 comments on commit 17771b6

Please sign in to comment.