Puppet Function: wmflib::dir::split

Defined in:
modules/wmflib/functions/dir/split.pp
Function type:
Puppet Language

Overview

wmflib::dir::split(Variant[Stdlib::Unixpath, Array[Stdlib::Unixpath]] $dirs)Array[Stdlib::Unixpath]

Use this function when you need to split a absolute path into multiple absolute paths that all descend from the given path.

Examples:

calling the function

wmflib::dir::split('/opt/puppetlabs') => ['/opt', '/opt/puppetlabs']

Parameters:

  • dirs (Variant[Stdlib::Unixpath, Array[Stdlib::Unixpath]])

    either an absolute path or a array of absolute paths.

Returns:

  • (Array[Stdlib::Unixpath])

    an array of absolute paths after being cut into individual paths.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'modules/wmflib/functions/dir/split.pp', line 10

function wmflib::dir::split(
    Variant[Stdlib::Unixpath, Array[Stdlib::Unixpath]] $dirs
) >> Array[Stdlib::Unixpath] {
    [$dirs].flatten.unique.map |$dir| {
        $dir.split('/').reduce([]) |$memo, $value| {
            $value.empty ? {
                true    => $memo,
                default => $memo + "${memo[-1]}/${value}",
            }
        }
    }.flatten.unique
}