Module: Melai::DirHelpers

Defined in:
lib/melai/dir_helpers.rb

Overview

This module provides some helper methods, specificlally pertaining to directory creation, removal, searching, et al.

Instance Method Summary collapse

Instance Method Details

#ensure_directory(directory) ⇒ Bool

Ensure a directory exists

Parameters:

  • a (String)

    directory to evaluate

Returns:

  • (Bool)

    true if the directory was created, false if already exists



20
21
22
23
24
25
26
# File 'lib/melai/dir_helpers.rb', line 20

def ensure_directory(directory)
  unless File.directory?(directory)
    FileUtils.mkdir_p(directory)
    return true
  end
  return false
end

Ensure a symlink exists

Parameters:

  • symlink_name: (String)

    /foo/bar/i-am-a-symlink.rpm

  • original_file: (String)

    /baz/i-am-a-real-file.rpm

Returns:

  • (Bool)

    true if the link was created, false if already exists



33
34
35
36
37
38
39
40
41
# File 'lib/melai/dir_helpers.rb', line 33

def ensure_symlink(symlink_name, original_file)
  unless File.symlink?(symlink_name)
    ensure_directory(File.dirname(symlink_name))
    target = File.absolute_path(original_file)
    File.symlink(target, symlink_name)
    return true
  end
  return false
end

#find_packages(packages_path) ⇒ Array

Get any files with a known package extension

Parameters:

  • a (String)

    directory to evaluate

Returns:

  • (Array)

    an array of filenmes



11
12
13
14
# File 'lib/melai/dir_helpers.rb', line 11

def find_packages(packages_path)
  packages = File.join(packages_path, "**", "*.{rpm,deb}")
  return Dir.glob(packages).sort()
end