Module: Makitzo::SSH::Commands::FileSystem

Included in:
Makitzo::SSH::Context
Defined in:
lib/makitzo/ssh/commands/file_system.rb

Instance Method Summary collapse

Instance Method Details

#cd(dir) ⇒ Object



16
17
18
# File 'lib/makitzo/ssh/commands/file_system.rb', line 16

def cd(dir)
  exec("cd #{x(dir)}")
end

#dir_exists?(dir) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/makitzo/ssh/commands/file_system.rb', line 11

def dir_exists?(dir)
  exec("test -d #{dir}").success?
end

#find_or_create_dir!(directory, friendly_name = nil) ⇒ Object

Check that a directory exists and attempt to create it if missing Log and raise CommandFailed if can’t create dir



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/makitzo/ssh/commands/file_system.rb', line 36

def find_or_create_dir!(directory, friendly_name = nil)
  friendly_name ||= directory
  if !dir_exists?(directory)
    mkdir = exec("mkdir -p #{directory}")
    if mkdir.error?
      logger.error "Failed to create #{friendly_name} (#{directory})"
      raise CommandFailed
    else
      logger.success "#{friendly_name} directory created"
    end
  else
    logger.success "#{friendly_name} directory located"
  end
end

#mv(source, destination) ⇒ Object



20
21
22
# File 'lib/makitzo/ssh/commands/file_system.rb', line 20

def mv(source, destination)
  exec("mv #{x(source)} #{x(destination)}").success?
end

#require_dir!(dir, friendly_name = nil) ⇒ Object

Ensure a directory exists. Log and raise CommandFailed otherwise



26
27
28
29
30
31
32
# File 'lib/makitzo/ssh/commands/file_system.rb', line 26

def require_dir!(dir, friendly_name = nil)
  friendly_name ||= dir
  unless dir_exists?(dir)
    logger.error "#{friendly_name} (#{dir}) is not a directory"
    raise CommandFailed
  end
end

#rm_rf!(directory, friendly_name = nil) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/makitzo/ssh/commands/file_system.rb', line 51

def rm_rf!(directory, friendly_name = nil)
  friendly_name ||= directory
  if exec("rm -rf #{directory}").error?
    logger.error "could not delete #{friendly_name} (#{directory})"
    raise CommandFailed
  end
end

#which?(executable) ⇒ Boolean

Predicates… these never log extra info

Returns:

  • (Boolean)


7
8
9
# File 'lib/makitzo/ssh/commands/file_system.rb', line 7

def which?(executable)
  exec("which #{executable}").success?
end