Forum: Cfengine Help Subject: Edit selected files Author: Beto Link to topic: https://cfengine.com/forum/read.php?3,17747,17747#msg-17747
I have a simple requirement: edit selected hidden (i.e., "dot") files in home directories. The limitation that "depth search is not allowed with edit_line promises" seems to make solving this problem unnecessarily difficult. I would really like to see the arbitrary design constraint removed. I have tried multiple solutions including a pattern in the promiser (works but produces useless error messages) and a file_select (which seems to not work at all). This is with community 3.0.5p1. For example: body common control { bundlesequence => { "check_user_files" }; inputs => { "cfengine_stdlib.cf", "library.cf" }; } bundle agent check_user_files { vars: "HomeDirn" int => readstringarray( "HomeDir", "/etc/passwd", ".*:[*x]:([1-9]|\d{2}|1\d{1,2}|-2|204|205|430|65534|4294967294|1000):.*", ":", "300", "12000" ); "HomeUsr" slist => getindices("HomeDir"); files: any:: "$(HomeDir[$(HomeUsr)][5])/\..*" edit_line => user_update, edit_defaults => no_edit_backup; } bundle edit_line user_update { replace_patterns: "oldvalue" replace_with => value("newvalue"); } body edit_defaults no_edit_backup { edit_backup => "false"; } This above example works but generates numerous errors/warnings I don't want to see: Directory /home/admin/usera in search path /home/admin/usera/\..* is controlled by another user (uid 10292) - trus ting its content is potentially risky (possible race) Promise (version not specified) belongs to bundle 'check_user_files' in file './check_user_files.cf' near line 30 -> Need to edit file /home/admin/usera/.profile but only a warning promised I: Report relates to a promise with handle "" I: Made in version 'not specified' of './check_user_files.cf' near line 30 /home/admin/usera/.dt is not a plain file File /home/admin/usera/.dt was marked for editing but could not be opened /home/admin/usera/.gnome is not a plain file File /home/admin/usera/.gnome was marked for editing but could not be opened /home/admin/usera/.gnome_private is not a plain file File /home/admin/usera/.gnome_private was marked for editing but could not be opened /home/admin/usera/.ssh is not a plain file When I try using file_select files: any:: "$(HomeDir[$(HomeUsr)][5])" edit_line => umask_update, edit_defaults => no_edit_backup, file_select => by_path("\..*","/.*"); } bundle edit_line umask_update { replace_patterns: "oldvalue" replace_with => value("newvalue"); } body file_select by_path(leaf,path) { file_types => { "plain" }; leaf_name => { "$(leaf)" }; path_name => { "$(path)" }; file_result => "file_types.path_name.leaf_name"; } it seems to be completely ignored, producing only the following message: File /home/admin/usera was marked for editing but could not be opened Anyone have any ideas? There's gotta be a way to do this. Thanks in advance! _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine