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
-
.all_files_and_dirs_in(dir_name, extra_files) ⇒ Array<String>
private
Returns all files and directories in the given directory and directories below it.
-
.all_files_in(dir_name, extra_files, recursion_limit = 10) ⇒ Array<String>
private
Returns all files in the given directory and directories below it, following symlinks up to a maximum of ‘recursion_limit` times.
-
.resolve_symlink(filename, recursion_limit = 5) ⇒ String
private
Resolves the given symlink into an absolute path.
Class Method Details
.all_files_and_dirs_in(dir_name, extra_files) ⇒ Array<String>
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.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/nanoc/extra/filesystem_tools.rb', line 94 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::Int::Errors::GenericTrivial, "Do not know how to handle extra_files: #{extra_files.inspect}", ) end Dir.glob(patterns) end |
.all_files_in(dir_name, extra_files, recursion_limit = 10) ⇒ Array<String>
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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/nanoc/extra/filesystem_tools.rb', line 54 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 |
.resolve_symlink(filename, recursion_limit = 5) ⇒ String
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.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/nanoc/extra/filesystem_tools.rb', line 126 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 |