Skip to content

Commit

Permalink
Copy symbolic links in the assets as actual files (#1967)
Browse files Browse the repository at this point in the history
  • Loading branch information
aYukiSekiguchi authored Nov 21, 2024
1 parent 5ab94c8 commit 36adbeb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/ex_doc/formatter/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ defmodule ExDoc.Formatter.HTML do

is_binary(dir_or_files) and File.dir?(dir_or_files) ->
dir_or_files
|> File.cp_r!(target_dir)
|> File.cp_r!(target_dir, dereference_symlinks: true)
|> Enum.map(&Path.relative_to(&1, output))

is_binary(dir_or_files) ->
Expand Down
3 changes: 1 addition & 2 deletions lib/ex_doc/formatter/html/templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ defmodule ExDoc.Formatter.HTML.Templates do
end

def module_summary(module_node) do
entries =
docs_groups(module_node.docs_groups, module_node.docs ++ module_node.typespecs)
entries = docs_groups(module_node.docs_groups, module_node.docs ++ module_node.typespecs)

Enum.reject(entries, fn {_type, nodes} -> nodes == [] end)
end
Expand Down
12 changes: 4 additions & 8 deletions lib/ex_doc/retriever.ex
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ defmodule ExDoc.Retriever do
metadata
)

source_url =
source_link(function_data[:source_file], source, function_data.source_line)
source_url = source_link(function_data[:source_file], source, function_data.source_line)

annotations =
annotations_for_docs.(metadata) ++
Expand All @@ -260,8 +259,7 @@ defmodule ExDoc.Retriever do
(source_doc && doc_ast(content_type, source_doc, file: doc_file, line: doc_line + 1)) ||
function_data.doc_fallback.()

group =
GroupMatcher.match_function(groups_for_docs, metadata)
group = GroupMatcher.match_function(groups_for_docs, metadata)

%ExDoc.FunctionNode{
id: nil_or_name(name, arity),
Expand Down Expand Up @@ -325,8 +323,7 @@ defmodule ExDoc.Retriever do
doc_file = anno_file(anno, source)
doc_line = anno_line(anno)

source_url =
source_link(callback_data[:source_file], source, callback_data.source_line)
source_url = source_link(callback_data[:source_file], source, callback_data.source_line)

metadata =
Map.merge(
Expand Down Expand Up @@ -393,8 +390,7 @@ defmodule ExDoc.Retriever do
metadata
)

source_url =
source_link(type_data[:source_file], source, type_data.source_line)
source_url = source_link(type_data[:source_file], source, type_data.source_line)

signature = signature(type_data.signature)

Expand Down
20 changes: 20 additions & 0 deletions test/ex_doc/formatter/html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -816,4 +816,24 @@ defmodule ExDoc.Formatter.HTMLTest do
after
File.rm_rf!("test/tmp/html_assets")
end

test "symbolic links in the assets should be resolved and copied as actual files",
%{tmp_dir: tmp_dir} = context do
File.mkdir_p!("test/tmp/html_assets/hello")
File.touch!("test/tmp/html_assets/hello/world")

File.ln_s("world", "test/tmp/html_assets/hello/symlink_world")

generate_docs(
doc_config(context,
assets: %{"test/tmp/html_assets" => "assets"}
)
)

assert File.regular?(tmp_dir <> "/html/assets/hello/world")
assert File.exists?(tmp_dir <> "/html/assets/hello/symlink_world")
assert File.read_link(tmp_dir <> "/html/assets/hello/symlink_world") == {:error, :einval}
after
File.rm_rf!("test/tmp/html_assets")
end
end

0 comments on commit 36adbeb

Please sign in to comment.