Sha256: d93ea83728051faadd94a5700576b126c1de28a06c5fc4bce4dfc459614583d9

Contents?: true

Size: 1.35 KB

Versions: 14

Compression:

Stored size: 1.35 KB

Contents

module HtmlMockup
  class Release::Cleaner
    def initialize(pattern)
      @pattern = pattern
    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
        Dir.glob(@pattern).each do |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)
          else
            release.log(self, "FAILED cleaning up \"#{path}\" in build")
          end
        end
      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

14 entries across 14 versions & 1 rubygems

Version Path
html_mockup-0.9.0 lib/html_mockup/release/cleaner.rb
html_mockup-0.8.4 lib/html_mockup/release/cleaner.rb
html_mockup-0.8.3 lib/html_mockup/release/cleaner.rb
html_mockup-0.8.2 lib/html_mockup/release/cleaner.rb
html_mockup-0.8.1 lib/html_mockup/release/cleaner.rb
html_mockup-0.8.0 lib/html_mockup/release/cleaner.rb
html_mockup-0.7.4 lib/html_mockup/release/cleaner.rb
html_mockup-0.7.3 lib/html_mockup/release/cleaner.rb
html_mockup-0.7.2 lib/html_mockup/release/cleaner.rb
html_mockup-0.7.1 lib/html_mockup/release/cleaner.rb
html_mockup-0.7.0 lib/html_mockup/release/cleaner.rb
html_mockup-0.6.5 lib/html_mockup/release/cleaner.rb
html_mockup-0.6.4 lib/html_mockup/release/cleaner.rb
html_mockup-0.6.3 lib/html_mockup/release/cleaner.rb