Puppet Function: extlib::path_join

Defined in:
functions/path_join.pp
Function type:
Puppet Language

Summary

Take one or more paths and join them together

Overview

extlib::path_join(Variant[String, Array[String]] $dirs)Stdlib::Absolutepath

This function will format a windows paths into equivalent unix like paths. This type of unix like path should work on windows.

Examples:

Joining Unix paths to return ‘/tmp/test/libs`

extlib::path_join(['/tmp', 'test', 'libs'])

Joining Windows paths to return ‘/c/test/libs`

extlib::path_join(['c:', 'test', 'libs'])

Parameters:

  • dirs (Variant[String, Array[String]])

    Joins two or more directories by file separator.

Returns:

  • (Stdlib::Absolutepath)

    The joined path



11
12
13
14
15
16
17
18
19
# File 'functions/path_join.pp', line 11

function extlib::path_join(Variant[String, Array[String]] *$dirs) >> Stdlib::Absolutepath {
  [$dirs].flatten.map |$index, $dir| {
    $index ? {
      # only allow paths in the first element (should we enforce this more strictly?)
      0       => extlib::dir_clean($dir),
      default => $dir,
    }
  }.join('/')
}