Skip to content

Commit

Permalink
Optimize the handling of binary items
Browse files Browse the repository at this point in the history
When writing large binary items (e.g. audio or video files), creating a
hard links pointing to the original file makes the build a lot faster,
and does not duplicate the data on disk.

Hard linking will fail when the source file is not on the same device as
the output directory (e.g. when /tmp is a tmpfs). In that case, fallback
to the previous behavior which is slower, but should always work.
  • Loading branch information
terceiro committed Feb 23, 2018
1 parent d12be32 commit 9d505ca
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nanoc/lib/nanoc/base/services/item_rep_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ def write_single(item_rep, snapshot_repo, snapshot_name, raw_path, written_paths
is_modified = is_created || !FileUtils.identical?(raw_path, temp_path)

# Write
FileUtils.cp(temp_path, raw_path) if is_modified
if is_modified
begin
FileUtils.ln(temp_path, raw_path, force: true)
rescue Errno::EXDEV
FileUtils.cp(temp_path, raw_path)
end
end

item_rep.modified = is_modified

Expand Down

0 comments on commit 9d505ca

Please sign in to comment.