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

ENT-11959: Fixed modules_presence bundle for Windows agents #2923

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cfe_internal/update/update_policy.cf
Original file line number Diff line number Diff line change
Expand Up @@ -795,14 +795,15 @@ bundle agent modules_presence
# be updated in $(sys.workdir)/modules, including any sub-directories.
{
vars:
"_vendored_dir" string => "$(this.promise_dirname)/../../modules/packages/vendored/";
"_override_dir" string => "$(this.promise_dirname)/../../modules/packages/";
"_custom_template_dir" string => "$(this.promise_dirname)/../../modules/mustache/";
"_vendored_dir" string => "$(this.promise_dirname)$(const.dirsep)..$(const.dirsep)..$(const.dirsep)modules$(const.dirsep)packages$(const.dirsep)vendored$(const.dirsep)";
"_override_dir" string => "$(this.promise_dirname)$(const.dirsep)..$(const.dirsep)..$(const.dirsep)modules$(const.dirsep)packages$(const.dirsep)";
"_custom_template_dir" string => "$(this.promise_dirname)$(const.dirsep)..$(const.dirsep)..$(const.dirsep)modules$(const.dirsep)mustache$(const.dirsep)";
"_vendored_paths" slist => findfiles("$(_vendored_dir)*.mustache");
"_custom_template_paths" slist => findfiles("$(_custom_template_dir)*.mustache"), if => isdir( "$(_custom_template_dir)" );
"_package_paths" slist => filter("$(_override_dir)vendored", _package_paths_tmp, "false", "true", 999);

windows::
"_package_paths_tmp" slist => findfiles("\Q$(_override_dir)\E*");
"_package_paths_tmp" slist => findfiles("$(_override_dir)*");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the treatment as literal string?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, because this.promise_dirname on windows contains backslashes. SO this change switches to using only backslashes on windows. but what were we protecting against with \Q \E?. findfiles() is glob, but \Q\E is pcre right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because findfiles doesn't work with those in there.

If I leave these out I get

R: _override_dir: C:\Program Files\Cfengine\inputs\cfe_internal\update\..\..\modules\packages\
R: _package_paths_tmp: [
  "C:\\Program Files\\Cfengine\\inputs\\cfe_internal\\update\\..\\..\\modules\\packages\\craig.mustache",
  "C:\\Program Files\\Cfengine\\inputs\\cfe_internal\\update\\..\\..\\modules\\packages\\vendored"
]

If I leave them in I get

R: _override_dir: C:\Program Files\Cfengine\inputs\cfe_internal\update\..\..\modules\packages\
R: _package_paths_tmp: []

I guess that new findfiles() handles windows paths with back-slashes in a different way which "just works" now?

Maybe because it uses true/fixed globbing where before it used PCRE?

@larsewi would know for sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notice the acceptance tests for findfiles on windows...

https://github.com/cfengine/core/blob/305ea57c670a49ec6e8025c89359e9cc093d4e93/tests/acceptance/01_vars/02_functions/findfiles.cf#L87-L96

All back-slashes

    windows::
      "expected[a]" string => "$(G.testdir)\\a,$(G.testdir)\\d,$(G.testdir)\\g";
      "expected[b]" string => "$(G.testdir)\\a,$(G.testdir)\\bc,$(G.testdir)\\d,$(G.testdir)\\g,$(G.testdir)\\klm";

      "expected[c]" string => "$(G.testdir)\\d\\e,$(G.testdir)\\g\\h";
      "expected[d]" string => "$(G.testdir)\\a,$(G.testdir)\\bc";
      "expected[e]" string => "";

      "expected[g]" string => "$(G.testdir)\\a,$(G.testdir)\\bc,$(G.testdir)\\d,$(G.testdir)\\g,$(G.testdir)\\klm,$(G.testdir)\\d\\e,$(G.testdir)\\g\\h,$(G.testdir)\\klm\\nop,$(G.testdir)\\d\\e\\f,$(G.testdir)\\g\\h\\i,$(G.testdir)\\klm\\nop\\qrs,$(G.testdir)\\g\\h\\i\\j";
      "expected[h]" string => "$(G.testdir)\\g\\h\\i\\j";

"_vendored_modules" slist => maplist(regex_replace("$(this)", "\Q$(_vendored_dir)\E(.*).mustache", "$1", "g"), @(_vendored_paths));
"_override_modules" slist => maplist(regex_replace("$(this)", "\Q$(_override_dir)\E(.*)", "$1", "g"), @(_package_paths));
# replace single backslashes in a windows path with double-backslashes
Expand Down Expand Up @@ -860,6 +861,8 @@ bundle agent modules_presence

reports:
DEBUG::
"_override_dir: $(_override_dir)";
"_package_paths_tmp: $(with)" with => storejson(_package_paths_tmp);
Copy link
Contributor Author

@craigcomstock craigcomstock Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added _override_dir and _package_paths_tmp for debugging on windows.

"_not_vendored_modules_pathname_regex: $(_not_vendored_modules_pathname_regex)";
"_vendored_modules: $(_vendored_modules)";
"_override_modules: $(_override_modules)";
Expand Down
Loading