# # # patch "automate.cc" # from [dd511cb884e0db7622d6a94df97793211df4e59e] # to [b1f53aae5921c30444b8671a07c5c55ae3ee0a0b] # ============================================================ --- automate.cc dd511cb884e0db7622d6a94df97793211df4e59e +++ automate.cc b1f53aae5921c30444b8671a07c5c55ae3ee0a0b @@ -802,20 +802,11 @@ namespace } } -// Set state information for fs_path in 'st', 'ignored', 'unknown', and -// 'unchanged'. static void -inventory_print_states(app_state & app, file_path const & fs_path, - inventory_item const & item, roster_t const & old_roster, - roster_t const & new_roster, basic_io::stanza & st, - bool & ignored, bool & unknown, bool & unchanged) +inventory_determine_states(app_state & app, file_path const & fs_path, + inventory_item const & item, roster_t const & old_roster, + roster_t const & new_roster, vector & states) { - std::vector states; - - ignored = false; - unknown = false; - unchanged = false; - // if both nodes exist, the only interesting case is // when the node ids aren't equal (so we have different nodes // with one and the same path in the old and the new roster) @@ -865,38 +856,32 @@ inventory_print_states(app_state & app, if (app.lua.hook_ignore_file(fs_path)) { states.push_back("ignored"); - ignored = true; } else { states.push_back("unknown"); - unknown = true; } } else if (item.new_node.type != item.fs_type) - states.push_back("invalid"); + { + states.push_back("invalid"); + } else { states.push_back("known"); - unchanged = true; } } - - st.push_str_multi(syms::status, states); } -// Update state information for item in 'st' and 'unchanged'. static void -inventory_print_changes(inventory_item const & item, roster_t const & old_roster, - basic_io::stanza & st, bool & unchanged) +inventory_determine_changes(inventory_item const & item, roster_t const & old_roster, + vector & changes) { // old nodes do not have any recorded content changes and attributes, // so we can't print anything for them here if (!item.new_node.exists) return; - std::vector changes; - // this is an existing item if (old_roster.has_node(item.new_node.id)) { @@ -941,12 +926,6 @@ inventory_print_changes(inventory_item c if (item.new_node.attrs.size() > 0) changes.push_back("attrs"); } - - if (!changes.empty()) - { - st.push_str_multi(syms::changes, changes); - unchanged = false; - } } // Name: inventory @@ -1008,12 +987,36 @@ CMD_AUTOMATE(inventory, N_("[PATH]...") for (inventory_map::const_iterator i = inventory.begin(); i != inventory.end(); ++i) { - bool ignored, unknown, unchanged; - basic_io::stanza st; + file_path const & fp = i->first; inventory_item const & item = i->second; - st.push_file_pair(syms::path, i->first); + // + // check if we should output this element at all + // + vector states; + inventory_determine_states(app, fp, item, old_roster, new_roster, states); + if (find(states.begin(), states.end(), "ignored") != states.end() && + app.opts.no_ignored) + continue; + + if (find(states.begin(), states.end(), "unknown") != states.end() && + app.opts.no_unknown) + continue; + + vector changes; + inventory_determine_changes(item, old_roster, changes); + + bool is_known = find(states.begin(), states.end(), "known") != states.end(); + if (is_known && changes.empty() && app.opts.no_unchanged) + continue; + + // + // begin building the output stanza + // + basic_io::stanza st; + st.push_file_pair(syms::path, fp); + if (item.old_node.exists) { switch (item.old_node.type) @@ -1024,8 +1027,9 @@ CMD_AUTOMATE(inventory, N_("[PATH]...") } if (item.new_path.as_internal().length() > 0) - // new_path is only present if different from either inventory map path or old_path - st.push_file_pair(syms::new_path, item.new_path); + { + st.push_file_pair(syms::new_path, item.new_path); + } } if (item.new_node.exists) @@ -1038,7 +1042,9 @@ CMD_AUTOMATE(inventory, N_("[PATH]...") } if (item.old_path.as_internal().length() > 0) - st.push_file_pair(syms::old_path, item.old_path); + { + st.push_file_pair(syms::old_path, item.old_path); + } } switch (item.fs_type) @@ -1048,19 +1054,15 @@ CMD_AUTOMATE(inventory, N_("[PATH]...") case path::nonexistent: st.push_str_pair(syms::fs_type, "none"); break; } - inventory_print_states(app, i->first, item, old_roster, new_roster, st, ignored, unknown, unchanged); + // + // finally output the previously recorded states and changes + // + I(!states.empty()); + st.push_str_multi(syms::status, states); - if (ignored && app.opts.no_ignored) - continue; + if (!changes.empty()) + st.push_str_multi(syms::changes, changes); - if (unknown && app.opts.no_unknown) - continue; - - inventory_print_changes(item, old_roster, st, unchanged); - - if (unchanged && app.opts.no_unchanged) - continue; - pr.print_stanza(st); }