Skip to content

Commit

Permalink
Create dir in withfile if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDunnNZ committed Feb 27, 2019
1 parent 54e0ece commit 5c55402
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Documenter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ function gitrm_copy(src, dst)
end

function withfile(func, file::AbstractString, contents::AbstractString)
dir = dirname(file)
hasdir = isdir(dir)
hasdir || mkpath(dir)

hasfile = isfile(file)
original = hasfile ? read(file, String) : ""
open(file, "w") do stream
Expand All @@ -763,6 +767,11 @@ function withfile(func, file::AbstractString, contents::AbstractString)
else
rm(file)
end

if !hasdir
# dir should be empty now as the only file inside was deleted
rm(dir, recursive=true)
end
end
end

Expand Down

0 comments on commit 5c55402

Please sign in to comment.