Class: Sprout::System::UnixSystem

Inherits:
BaseSystem show all
Defined in:
lib/sprout/system/unix_system.rb

Direct Known Subclasses

OSXSystem

Instance Method Summary (collapse)

Methods inherited from BaseSystem

#alt_separator?, #application_home, #env_home, #env_homedrive, #env_homedrive_and_homepath, #env_homepath, #env_userprofile, #execute_silent, #execute_thread, #find_home, #get_and_execute_process_runner, #get_process_runner, #home, #home=, #library, #tilde_home, #worst_case_home

Instance Method Details

- (Object) attempt_to_repair_executable(path)

Repair Windows Line endings found in non-windows executables (Flex SDK is regularly published with broken CRLFs)

path String path to the executable file.



46
47
48
# File 'lib/sprout/system/unix_system.rb', line 46

def attempt_to_repair_executable path
  repair_executable(path) if should_repair_executable(path)
end

- (Boolean) can_execute?(platform)

Returns:

  • (Boolean)


34
35
36
# File 'lib/sprout/system/unix_system.rb', line 34

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

- (Object) clean_path(path)



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/sprout/system/unix_system.rb', line 6

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

- (Object) execute(tool, options = '')



18
19
20
21
# File 'lib/sprout/system/unix_system.rb', line 18

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

- (Object) format_application_name(name)

Ensure Application name String begins with a dot (.), and does not include spaces.



27
28
29
30
31
32
# File 'lib/sprout/system/unix_system.rb', line 27

def format_application_name(name)
  if(name.index('.') != 0)
    name = '.' + name
  end
  return name.split(" ").join("_").downcase
end

- (Object) repair_executable(path)



50
51
52
53
54
55
56
57
58
59
# File 'lib/sprout/system/unix_system.rb', line 50

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

- (Object) should_repair_executable(path)

Determine if we should call repair_executable for the file at the provided path String.

Will this corrupt binaries? Yes... Yes. it. will.

This also fails on UTF-8 files since Ruby's regex appears to choke on UTF-8??



69
70
71
# File 'lib/sprout/system/unix_system.rb', line 69

def should_repair_executable path
  return (File.exists?(path) && !File.directory?(path) && File.read(path).match(/^\#\!\/bin\/sh/))
end