Sha256: 4274b0957b64e877c02d93e0991b42daa872776501148955425a440b8cb605dd

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

module Sprout::System

  class UnixSystem < BaseSystem

    def clean_path path
      return if path.nil?
      if(path.include? '../')
        path = File.expand_path path
      end

      if(path.index(' '))
        return path.split(' ').join('\ ')
      end
      return path
    end

    def execute(tool, options='')
      attempt_to_repair_executable tool
      super(tool, options)
    end

    ##
    # Ensure Application +name+ String begins with a dot (.), and does
    # not include spaces.
    #
    def format_application_name(name)
      if(name.index('.') != 0)
        name = '.' + name
      end
      return name.split(" ").join("_").downcase
    end

    def can_execute? platform
      [:unix, :linux].include?(platform) || super
    end

    ##
    # Repair Windows Line endings
    # found in non-windows executables
    # (Flex SDK is regularly published
    # with broken CRLFs)
    #
    # +path+ String path to the executable file.
    #
    def attempt_to_repair_executable path
      repair_executable(path) if should_repair_executable(path)
    end

    def repair_executable path
      content = File.read(path)
      if(content.match(/\r\n/))
        Sprout::Log.puts "[WARNING] Sprouts is about to replace invalid Windows line endings on an executable at: (#{path})"
        content.gsub!(/\r\n/, "\n")
        File.open(path, 'w+') do |f|
          f.write content
        end
      end
    end

    ##
    # Determine if we should call +repair_executable+
    # for the file at the provided +path+ String.
    #
    # Will this corrupt binaries? Yes... Yes. it. will.
    def should_repair_executable path
      return (File.exists?(path) && !File.directory?(path) && File.read(path).match(/^\#\!\/bin\/sh/))
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sprout-1.0.26.pre lib/sprout/system/unix_system.rb
sprout-1.0.25.pre lib/sprout/system/unix_system.rb
sprout-1.0.24.pre lib/sprout/system/unix_system.rb