1 # Nick's web site: Workarounds for Nanoc's busted handling of broken symlinks.
3 # Copyright © 2020 Nick Bowler
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 # Monkey patch the filesystem data source to adjust some strange behavoiur.
19 class Nanoc::DataSources::Filesystem < Nanoc::DataSource
20 # The filesystem mtime_of crashes on broken symlinks. Let's not do that,
21 # instead we'll fall back to the link mtime for broken links.
23 mtimes = args.compact.map do |f|
32 @dummy_file = Tempfile.new('dummy')
34 # The original resolve_symlink helper uses a readlink loop which
35 # crashes on broken links. I'm also fairly sure symlinks in path
36 # components are not correctly resolved. Let's just use realpath
37 # instead and hope ruby itself doesn't have these bugs.
38 def resolve_symlink(filename, recursion_limit = nil)
39 File.realpath(filename)
41 # Dead link. Return a valid filename otherwise the filesystem
42 # source does bizarre things. The actual items are created with
43 # the original filename so this dummy file does not appear to
44 # leak outside of the filesystem data source implementation.
47 module_function :resolve_symlink