Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving conflicting resources in mkdir_p #202

Open
FOTempel opened this issue Aug 8, 2022 · 2 comments
Open

Solving conflicting resources in mkdir_p #202

FOTempel opened this issue Aug 8, 2022 · 2 comments

Comments

@FOTempel
Copy link

FOTempel commented Aug 8, 2022

The mkdir_p function can be quite useful but it doesn't take much to make it unusable in the catalog due to double resource definitions. I basically recreated mkdir_p as a defined resource before finding extlib and solved this issue by adding a filter to the resulting array. Add:

.filter|$_dir| {!defined(File[$_dir])} # filter out File resources already defined in the catalog

to

}.flatten.unique.sort

I've tested it and it works, it filters out already elsewhere defined resources (in my case some root directories which are created as mount points).

@b4ldr
Copy link
Member

b4ldr commented Aug 8, 2022

We also have a version of this function as well, it uses create_resources to achieve a similar result. however we have a slightly different signature

function wmflib::dir::mkdir_p(
    Variant[Stdlib::Unixpath, Array[Stdlib::Unixpath]] $dirs,
    Hash                                               $params = {}, 
) {
    $_dirs = wmflib::dir::normalise($dirs)
    $parents = wmflib::dir::split($_dirs) - $_dirs
    # ensure all parent directories exist
    ensure_resource('file', $parents, {'ensure' => 'directory'})
    # Apply params only to the actual directories
    ensure_resource('file', $dirs, {'ensure' => 'directory'} + $params)
}
# usage
wmflib::dir::mkdir_p('/usr/local/share/foobar/www', {'owner' => 'www', 'mode' => '0700'})

Im personally not a fan of using defined due to its reliance on parse order, however it would be good to agree a way forward for this function and send it to stdlib

@FOTempel
Copy link
Author

This thing also exists. https://forge.puppet.com/modules/pltraining/dirtree. Seems there are a lot of people with the same desires and a lot of homebrew solutions. I don't know what the best way to solve this is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants