Puppet Function: wmflib::dir::normalise

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

Overview

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

Currently all this means is that we ensure all directories have the trailing slash removed Further we ensure strings are converted to one element arrays

Examples:

calling the function

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

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 normalised



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'modules/wmflib/functions/dir/normalise.pp', line 12

function wmflib::dir::normalise(
    Variant[Stdlib::Unixpath, Array[Stdlib::Unixpath]] $dirs
) >> Array[Stdlib::Unixpath] {
    [$dirs].flatten.unique.map |$dir| {
        # special case for root dir
        if $dir == '/' {
            $dir
        } elsif $dir.stdlib::end_with('/') {
            $dir[0,-2]
        } else {
            $dir
        }

    }.flatten.unique
}