Module: Nanoc::Extra::FilesystemTools Private
- Defined in:
- lib/nanoc/extra/filesystem_tools.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Contains useful functions for managing the filesystem.
Defined Under Namespace
Classes: MaxSymlinkDepthExceededError, UnsupportedFileTypeError
Class Method Summary (collapse)
-
+ (Array<String>) all_files_and_dirs_in(dir_name, extra_files)
private
Returns all files and directories in the given directory and directories below it.
-
+ (Array<String>) all_files_in(dir_name, extra_files, recursion_limit = 10)
private
Returns all files in the given directory and directories below it, following symlinks up to a maximum of
recursion_limit
times. -
+ (String) resolve_symlink(filename, recursion_limit = 5)
private
Resolves the given symlink into an absolute path.
Class Method Details
+ (Array<String>) all_files_and_dirs_in(dir_name, extra_files)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns all files and directories in the given directory and directories below it.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/nanoc/extra/filesystem_tools.rb', line 100 def all_files_and_dirs_in(dir_name, extra_files) patterns = ["#{dir_name}/**/*"] case extra_files when nil when String patterns << "#{dir_name}/#{extra_files}" when Array patterns.concat(extra_files.map { |extra_file| "#{dir_name}/#{extra_file}" }) else raise Nanoc::Errors::GenericTrivial, "Do not know how to handle extra_files: #{extra_files.inspect}" end Dir.glob(patterns) end |
+ (Array<String>) all_files_in(dir_name, extra_files, recursion_limit = 10)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns all files in the given directory and directories below it,
following symlinks up to a maximum of recursion_limit
times.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/nanoc/extra/filesystem_tools.rb', line 60 def all_files_in(dir_name, extra_files, recursion_limit = 10) all_files_and_dirs_in(dir_name, extra_files).map do |fn| case File.ftype(fn) when 'link' if 0 == recursion_limit raise MaxSymlinkDepthExceededError.new(fn) else absolute_target = resolve_symlink(fn) if File.file?(absolute_target) fn else all_files_in(absolute_target, extra_files, recursion_limit - 1).map do |sfn| fn + sfn[absolute_target.size..-1] end end end when 'file' fn when 'directory' nil else raise UnsupportedFileTypeError.new(fn) end end.compact.flatten end |
+ (String) resolve_symlink(filename, recursion_limit = 5)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolves the given symlink into an absolute path.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/nanoc/extra/filesystem_tools.rb', line 130 def resolve_symlink(filename, recursion_limit = 5) target = File.readlink(filename) absolute_target = File.(target, File.dirname(filename)) case File.ftype(absolute_target) when 'link' if 0 == recursion_limit raise MaxSymlinkDepthExceededError.new(absolute_target) else resolve_symlink(absolute_target, recursion_limit - 1) end when 'file', 'directory' absolute_target else raise UnsupportedFileTypeError.new(absolute_target) end end |