Sha256: fb07803b58863e1c4162bb783ecc2ba8cbe6983ec98d1b1f09d6250665ce943f
Contents?: true
Size: 1.49 KB
Versions: 10
Compression:
Stored size: 1.49 KB
Contents
module Roger class Release::Cleaner def initialize(pattern) @pattern = [pattern].flatten end def call(release, options = {}) # 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 Dir.chdir(release.build_path.to_s) do @pattern.each do |pattern| Dir.glob(pattern).each do |file| self.clean_path(release, file) end end end end def clean_path(release, file) path = File.join(release.build_path.to_s, file) if is_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 def is_inside_build_path(build_path, path) begin build_path = Pathname.new(build_path).realpath.to_s path = Pathname.new(path) if(path.absolute?) path = path.realpath.to_s else path = Pathname.new(File.join(build_path.to_s, path)).realpath.to_s end rescue Errno::ENOENT # Real path does not exist return false end if path[build_path] return true else raise RuntimeError, "Cleaning pattern is not inside build directory" end end end end
Version data entries
10 entries across 10 versions & 1 rubygems