class Roger::Release::Cleaner
The cleaner safely cleans up paths
Public Class Methods
new(pattern)
click to toggle source
# File lib/roger/release/cleaner.rb, line 4 def initialize(pattern) @pattern = [pattern].flatten end
Public Instance Methods
call(release, _options = {})
click to toggle source
We switch to the build path and append the globbed files for safety, so even if you manage to sneak in a pattern like “/*/” it won't do you any good as it will be reappended to the path
# File lib/roger/release/cleaner.rb, line 11 def call(release, _options = {}) Dir.chdir(release.build_path.to_s) do @pattern.each do |pattern| Dir.glob(pattern).each do |file| clean_path(release, file) end end end end
clean_path(release, file)
click to toggle source
# File lib/roger/release/cleaner.rb, line 21 def clean_path(release, file) path = File.join(release.build_path.to_s, file) if inside_build_path?(release.build_path, path) release.log(self, "Cleaning up \"#{path}\" in build") rm_rf(path) true else release.log(self, "FAILED cleaning up \"#{path}\" in build") false end end
Protected Instance Methods
inside_build_path?(build_path, path)
click to toggle source
# File lib/roger/release/cleaner.rb, line 35 def inside_build_path?(build_path, path) begin build_path = Pathname.new(build_path).realpath.to_s path = Pathname.new(path) path = if path.absolute? path.realpath.to_s else Pathname.new(File.join(build_path.to_s, path)).realpath.to_s end rescue Errno::ENOENT # Real path does not exist return false end raise "Cleaning pattern is not inside build directory" unless path[build_path] true end