diff --git a/spec/internal/filemode/embed_filemode.cr b/spec/internal/filemode/embed_filemode.cr index f221877..a45d318 100644 --- a/spec/internal/filemode/embed_filemode.cr +++ b/spec/internal/filemode/embed_filemode.cr @@ -1,6 +1,6 @@ -perm1 = File.stat(File.join(__DIR__, "template", "file1.ecr")).perm -perm2 = File.stat(File.join(__DIR__, "template", "file2")).perm +perm1 = File.info(File.join(__DIR__, "template", "file1.ecr")).permissions +perm2 = File.info(File.join(__DIR__, "template", "file2")).permissions puts <<-EOS -FILE1_PERM = #{perm1} -FILE2_PERM = #{perm2} +FILE1_PERM = File::Permissions.from_value(#{perm1.value}) +FILE2_PERM = File::Permissions.from_value(#{perm2.value}) EOS diff --git a/spec/internal/filemode_spec.cr b/spec/internal/filemode_spec.cr index 7d83522..e970a2b 100644 --- a/spec/internal/filemode_spec.cr +++ b/spec/internal/filemode_spec.cr @@ -16,8 +16,8 @@ module TeeplateInternalSpecs::Executable file1 = File.join(tmp, "file1") file2 = File.join(tmp, "file2") Template.new.render tmp, force: true - File.stat(file1).perm.should eq FILE1_PERM - File.stat(file2).perm.should eq FILE2_PERM + File.info(file1).permissions.should eq FILE1_PERM + File.info(file2).permissions.should eq FILE2_PERM end end @@ -30,8 +30,8 @@ module TeeplateInternalSpecs::Executable File.write file2, "" File.chmod file2, 0o666 Template.new.render tmp, force: true - File.stat(file1).perm.should eq FILE1_PERM - File.stat(file2).perm.should eq FILE2_PERM + File.info(file1).permissions.should eq FILE1_PERM + File.info(file2).permissions.should eq FILE2_PERM end end end diff --git a/src/lib/base64_data.cr b/src/lib/base64_data.cr index 673915b..375ec94 100644 --- a/src/lib/base64_data.cr +++ b/src/lib/base64_data.cr @@ -5,11 +5,11 @@ module Teeplate getter path : String getter size : UInt64 getter encoded : String - getter perm : UInt32 + getter perm : File::Permissions getter? forces : Bool - def initialize(@path, @size, @encoded, perm : Int::Primitive = 0o644, force = false) - @perm = perm.to_u32 + def initialize(@path, @size, @encoded, perm : File::Permissions = File::Permissions.from_value(0o644), force = false) + @perm = perm @forces = force end diff --git a/src/lib/file_data.cr b/src/lib/file_data.cr index 6ca4594..8ac781d 100644 --- a/src/lib/file_data.cr +++ b/src/lib/file_data.cr @@ -5,16 +5,12 @@ module Teeplate getter absolute_path : String getter path : String getter size : UInt64 - getter perm : UInt32 + getter perm : File::Permissions getter? forces : Bool - def initialize(@absolute_path, @path, size : UInt64? = nil, perm : Int::Primitive? = nil, force = false) + def initialize(@absolute_path, @path, size : UInt64? = nil, perm : File::Permissions? = nil, force = false) @size = size || File.size(@absolute_path) - @perm = if perm - perm.to_u32 - else - File.stat(@absolute_path).perm.to_u32 - end + @perm = perm || File.info(@absolute_path).permissions @forces = force end diff --git a/src/lib/file_entry_collector.cr b/src/lib/file_entry_collector.cr index 9d59a72..478aefc 100644 --- a/src/lib/file_entry_collector.cr +++ b/src/lib/file_entry_collector.cr @@ -8,10 +8,8 @@ module Teeplate def each_file(abs, rel, &block : String, String ->) Dir.open(abs) do |d| - d.each do |entry| - if entry != "." && entry != ".." - each_file abs, rel, entry, &block - end + d.each_child do |entry| + each_file abs, rel, entry, &block end end end @@ -27,6 +25,7 @@ module Teeplate end @entries : Array(AsDataEntry)? + def entries @entries ||= begin a = [] of AsDataEntry diff --git a/src/lib/file_tree/macros/directory.cr b/src/lib/file_tree/macros/directory.cr index 8991867..3068330 100644 --- a/src/lib/file_tree/macros/directory.cr +++ b/src/lib/file_tree/macros/directory.cr @@ -2,10 +2,8 @@ require "base64" def each_file(abs, rel, &block : String, String ->) Dir.open(abs) do |d| - d.each do |entry| - if entry != "." && entry != ".." - each_file abs, rel, entry, &block - end + d.each_child do |entry| + each_file abs, rel, entry, &block end end end @@ -32,14 +30,14 @@ def pack_ecr(i, sb, abs, rel) STDOUT << <<-EOS \nio = IO::Memory.new __ecr#{i} io - ____files << ::Teeplate::StringData.new("#{rel}", io.to_s, #{File.stat(abs).perm}) + ____files << ::Teeplate::StringData.new("#{rel}", io.to_s, File::Permissions.from_value(#{File.info(abs).permissions.value})) EOS end def pack_blob(sb, abs, rel) STDOUT << "\n____files << ::Teeplate::Base64Data.new(\"#{rel}\", " io = IO::Memory.new - File.open(abs){|f| IO.copy(f, io)} + File.open(abs) { |f| IO.copy(f, io) } if io.size > 0 STDOUT << "#{io.size}_u64, <<-EOS\n" Base64.encode io, STDOUT @@ -47,7 +45,7 @@ def pack_blob(sb, abs, rel) else STDOUT << "0_u64, \"\"" end - STDOUT << ", #{File.stat(abs).perm})" + STDOUT << ", File::Permissions.from_value(#{File.info(abs).permissions.value}))" end STDOUT << "def ____collect_files(____files)" diff --git a/src/lib/rendering_entry.cr b/src/lib/rendering_entry.cr index a569ccc..a84885b 100644 --- a/src/lib/rendering_entry.cr +++ b/src/lib/rendering_entry.cr @@ -20,6 +20,7 @@ module Teeplate end @out_path : String? + # Returns an output location. # # It makes an absolute location with the renderer's setting and this entry's local path. @@ -30,16 +31,17 @@ module Teeplate end @local_path : String? + # Returns an output path relative to the base location. # # It returns the data entry's path by default. # Override this method if this path should be different from the data entry's path. def local_path @local_path ||= if appends? - @data.path[1..-1] - else - @data.path - end + @data.path[1..-1] + else + @data.path + end end # :nodoc: @@ -112,6 +114,7 @@ module Teeplate end @action : Symbol? + # :nodoc: def action @action ||= get_action @@ -200,9 +203,9 @@ module Teeplate end begin if !GIT.empty? - Process.new(GIT, ["diff", "--no-index", "--", out_path, "-"], shell: true, input: r, output: true, error: true).wait + Process.new(GIT, ["diff", "--no-index", "--", out_path, "-"], shell: true, input: r, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit).wait elsif !DIFF.empty? - Process.new(DIFF, ["-u", out_path, "-"], shell: true, input: r, output: true, error: true).wait + Process.new(DIFF, ["-u", out_path, "-"], shell: true, input: r, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit).wait else STDOUT.puts "No diff command is installed." end diff --git a/src/lib/string_data.cr b/src/lib/string_data.cr index 098e7d2..9fce632 100644 --- a/src/lib/string_data.cr +++ b/src/lib/string_data.cr @@ -4,11 +4,11 @@ module Teeplate getter path : String getter string : String - getter perm : UInt32 + getter perm : File::Permissions getter? forces : Bool - def initialize(@path, @string, perm : Int::Primitive = 0o644, force = false) - @perm = perm.to_u32 + def initialize(@path, @string, perm : File::Permissions = File::Permissions.from_value(0o644), force = false) + @perm = perm @forces = force end