Skip to content

Commit

Permalink
updates cp to keep the previous behavour
Browse files Browse the repository at this point in the history
my new implementation of the `cp` function got merged
JuliaLang/julia#10888

sets `remove_destination=true` otherwise if you rerun you get an:

```
ERROR: ArgumentError: 'static/custom.css' exists.
`remove_destination=true` is required to remove
'static/custom.css' before copying.
```
  • Loading branch information
peter1000 committed Apr 25, 2015
1 parent 79aca74 commit e2edba8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,49 @@ if VERSION < v"0.4.0-dev+4393"
return isempty(relpath_) ? curdir : relpath_
end
end

if VERSION < v"0.4.0-dev+4499"
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
Base.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
Base.FS.sendfile(src, dst)
end
end
end
2 changes: 1 addition & 1 deletion src/render/html.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function save(file::AbstractString, mime::MIME"text/html", doc::Metadata, config
isdir(dst) || mkpath(dst)
for file in readdir(src)
info("copying $(file) to $(dst)")
cp(joinpath(src, file), joinpath(dst, file))
cp(joinpath(src, file), joinpath(dst, file); remove_destination=true)
end
end

Expand Down

0 comments on commit e2edba8

Please sign in to comment.