# # # patch "Makefile.am" # from [f7c6d1d42c5f574e1326e019a855de305fa5b558] # to [a3c168f353f4b8067559dbf136b7eee3928d6e13] # # patch "restrictions.cc" # from [a4bb673571007d154c6f40c87305348acc2b6fb4] # to [30b68aafe5e7549052e8fdf53164264f615a8cae] # # patch "restrictions.hh" # from [0b2c8a2c94abcc8d9d84e6684430f4324ce29f7a] # to [20265e8afcdb9edc9e070a21e791f4ca7517b968] # ============================================================ --- Makefile.am f7c6d1d42c5f574e1326e019a855de305fa5b558 +++ Makefile.am a3c168f353f4b8067559dbf136b7eee3928d6e13 @@ -321,21 +321,20 @@ UNIT_TEST_OBJ_SUPPORT = \ UNIT_TEST_OBJ_SUPPORT = \ mtn-app_state.$(OBJEXT) mtn-cert.$(OBJEXT) \ mtn-constants.$(OBJEXT) mtn-database.$(OBJEXT) \ - mtn-epoch.$(OBJEXT) mtn-file_io.$(OBJEXT) mtn-hmac.$(OBJEXT) \ - mtn-inodeprint.$(OBJEXT) mtn-key_store.$(OBJEXT) \ - mtn-keys.$(OBJEXT) \ - mtn-lcs.$(OBJEXT) mtn-legacy.$(OBJEXT) mtn-lua.$(OBJEXT) \ - mtn-lua_hooks.$(OBJEXT) mtn-merkle_tree.$(OBJEXT) \ - mtn-mt_version.$(OBJEXT) mtn-mtn-sanity.$(OBJEXT) \ - mtn-options.$(OBJEXT) mtn-package_full_revision.$(OBJEXT) \ - mtn-package_revision.$(OBJEXT) mtn-project.$(OBJEXT) \ - mtn-randomizer.$(OBJEXT) mtn-sanity.$(OBJEXT) \ - mtn-schema.$(OBJEXT) mtn-schema_migration.$(OBJEXT) \ - mtn-selectors.$(OBJEXT) mtn-specialized_lexical_cast.$(OBJEXT) \ - mtn-ssh_agent.$(OBJEXT) mtn-std_hooks.$(OBJEXT) \ - mtn-ui.$(OBJEXT) mtn-work.$(OBJEXT) \ - mtn-work_migration.$(OBJEXT) mtn-pcrewrap.$(OBJEXT) \ - mtn-gzip.$(OBJEXT) + mtn-epoch.$(OBJEXT) mtn-file_io.$(OBJEXT) mtn-gzip.$(OBJEXT) \ + mtn-hmac.$(OBJEXT) mtn-inodeprint.$(OBJEXT) \ + mtn-key_store.$(OBJEXT) mtn-keys.$(OBJEXT) mtn-lcs.$(OBJEXT) \ + mtn-legacy.$(OBJEXT) mtn-lua.$(OBJEXT) mtn-lua_hooks.$(OBJEXT) \ + mtn-merkle_tree.$(OBJEXT) mtn-mt_version.$(OBJEXT) \ + mtn-mtn-sanity.$(OBJEXT) mtn-options.$(OBJEXT) \ + mtn-package_full_revision.$(OBJEXT) \ + mtn-package_revision.$(OBJEXT) mtn-pcrewrap.$(OBJEXT) \ + mtn-project.$(OBJEXT) mtn-randomizer.$(OBJEXT) \ + mtn-sanity.$(OBJEXT) mtn-schema.$(OBJEXT) \ + mtn-schema_migration.$(OBJEXT) \ + mtn-specialized_lexical_cast.$(OBJEXT) mtn-ssh_agent.$(OBJEXT) \ + mtn-std_hooks.$(OBJEXT) mtn-ui.$(OBJEXT) mtn-work.$(OBJEXT) \ + mtn-work_migration.$(OBJEXT) # primaries ============================================================ --- restrictions.cc a4bb673571007d154c6f40c87305348acc2b6fb4 +++ restrictions.cc 30b68aafe5e7549052e8fdf53164264f615a8cae @@ -8,23 +8,29 @@ // PURPOSE. #include "base.hh" -#include +#include "safe_map.hh" #include "vector.hh" #include "restrictions.hh" -#include "revision.hh" -#include "safe_map.hh" -#include "transforms.hh" -#include "work.hh" #include "file_io.hh" #ifdef BUILD_UNIT_TESTS -// This must appear above the using-declarations, or we get errors deep -// within botan because "set" doesn't mean what botan thinks it means. -#include "app_state.hh" + #include "unit_tests.hh" #include "roster.hh" #include "sanity.hh" +// see comments in restriction.hh +#define WORK_ARGDECL // nothing +#define WORK_ARG // nothing +#define WORK_IGNORE_FILE(f) false + +#else + +#include "work.hh" +#define WORK_ARGDECL workspace & work, +#define WORK_ARG work, +#define WORK_IGNORE_FILE(f) work.ignore_file(f) + #endif using std::make_pair; @@ -82,7 +88,7 @@ static void } static void -validate_roster_paths(workspace & work, +validate_roster_paths(WORK_ARGDECL set const & included_paths, set const & excluded_paths, set const & known_paths) @@ -97,7 +103,7 @@ validate_roster_paths(workspace & work, // rosters if (known_paths.find(*i) == known_paths.end()) { - if (!work.ignore_file(*i)) + if (!WORK_IGNORE_FILE(*i)) { bad++; W(F("restriction includes unknown path '%s'") % *i); @@ -119,7 +125,7 @@ void } void -validate_workspace_paths(workspace & work, +validate_workspace_paths(WORK_ARGDECL set const & included_paths, set const & excluded_paths) { @@ -134,7 +140,7 @@ validate_workspace_paths(workspace & wor // ignored paths are allowed into the restriction but are not // considered invalid if they are found in none of the restriction's // rosters - if (!path_exists(*i) && !work.ignore_file(*i)) + if (!path_exists(*i) && !WORK_IGNORE_FILE(*i)) { bad++; W(F("restriction includes unknown path '%s'") % *i); @@ -165,7 +171,7 @@ restriction::restriction(std::vector const & includes, std::vector const & excludes, long depth, @@ -177,10 +183,10 @@ node_restriction::node_restriction(works map_nodes(node_map, roster, excluded_paths, known_paths, restricted_path::excluded); - validate_roster_paths(w, included_paths, excluded_paths, known_paths); + validate_roster_paths(WORK_ARG included_paths, excluded_paths, known_paths); } -node_restriction::node_restriction(workspace & w, +node_restriction::node_restriction(WORK_ARGDECL std::vector const & includes, std::vector const & excludes, long depth, @@ -198,10 +204,10 @@ node_restriction::node_restriction(works map_nodes(node_map, roster2, excluded_paths, known_paths, restricted_path::excluded); - validate_roster_paths(w, included_paths, excluded_paths, known_paths); + validate_roster_paths(WORK_ARG included_paths, excluded_paths, known_paths); } -node_restriction::node_restriction(workspace & w, +node_restriction::node_restriction(WORK_ARGDECL std::vector const & includes, std::vector const & excludes, long depth, @@ -224,11 +230,11 @@ node_restriction::node_restriction(works map_nodes(node_map, roster2, excluded_paths, known_paths, restricted_path::excluded); - validate_roster_paths(w, included_paths, excluded_paths, known_paths); + validate_roster_paths(WORK_ARG included_paths, excluded_paths, known_paths); } -path_restriction::path_restriction(workspace & w, +path_restriction::path_restriction(WORK_ARGDECL std::vector const & includes, std::vector const & excludes, long depth, @@ -239,9 +245,7 @@ path_restriction::path_restriction(works map_paths(path_map, excluded_paths, restricted_path::excluded); if (vc == check_paths) - { - validate_workspace_paths(w, included_paths, excluded_paths); - } + validate_workspace_paths(WORK_ARG included_paths, excluded_paths); } bool @@ -616,11 +620,9 @@ UNIT_TEST(restrictions, simple_include) includes.push_back(file_path_internal("x/x")); includes.push_back(file_path_internal("y/y")); - app_state app; - // check restricted nodes - node_restriction nmask(app.work, includes, excludes, -1, roster); + node_restriction nmask(includes, excludes, -1, roster); UNIT_TEST_CHECK(!nmask.empty()); @@ -650,7 +652,7 @@ UNIT_TEST(restrictions, simple_include) // check restricted paths - path_restriction pmask(app.work, includes, excludes, -1); + path_restriction pmask(includes, excludes, -1); UNIT_TEST_CHECK(!pmask.empty()); @@ -688,11 +690,9 @@ UNIT_TEST(restrictions, simple_exclude) excludes.push_back(file_path_internal("x/x")); excludes.push_back(file_path_internal("y/y")); - app_state app; - // check restricted nodes - node_restriction nmask(app.work, includes, excludes, -1, roster); + node_restriction nmask(includes, excludes, -1, roster); UNIT_TEST_CHECK(!nmask.empty()); @@ -722,7 +722,7 @@ UNIT_TEST(restrictions, simple_exclude) // check restricted paths - path_restriction pmask(app.work, includes, excludes, -1); + path_restriction pmask(includes, excludes, -1); UNIT_TEST_CHECK(!pmask.empty()); @@ -762,11 +762,9 @@ UNIT_TEST(restrictions, include_exclude) excludes.push_back(file_path_internal("x/x")); excludes.push_back(file_path_internal("y/y")); - app_state app; - // check restricted nodes - node_restriction nmask(app.work, includes, excludes, -1, roster); + node_restriction nmask(includes, excludes, -1, roster); UNIT_TEST_CHECK(!nmask.empty()); @@ -796,7 +794,7 @@ UNIT_TEST(restrictions, include_exclude) // check restricted paths - path_restriction pmask(app.work, includes, excludes, -1); + path_restriction pmask(includes, excludes, -1); UNIT_TEST_CHECK(!pmask.empty()); @@ -839,11 +837,9 @@ UNIT_TEST(restrictions, exclude_include) includes.push_back(file_path_internal("x/x")); includes.push_back(file_path_internal("y/y")); - app_state app; - // check restricted nodes - node_restriction nmask(app.work, includes, excludes, -1, roster); + node_restriction nmask(includes, excludes, -1, roster); UNIT_TEST_CHECK(!nmask.empty()); @@ -873,7 +869,7 @@ UNIT_TEST(restrictions, exclude_include) // check restricted paths - path_restriction pmask(app.work, includes, excludes, -1); + path_restriction pmask(includes, excludes, -1); UNIT_TEST_CHECK(!pmask.empty()); @@ -911,8 +907,7 @@ UNIT_TEST(restrictions, invalid_roster_p includes.push_back(file_path_internal("foo")); excludes.push_back(file_path_internal("bar")); - app_state app; - UNIT_TEST_CHECK_THROW(node_restriction(app.work, includes, excludes, -1, roster), + UNIT_TEST_CHECK_THROW(node_restriction(includes, excludes, -1, roster), informative_failure); } @@ -925,8 +920,7 @@ UNIT_TEST(restrictions, invalid_workspac includes.push_back(file_path_internal("foo")); excludes.push_back(file_path_internal("bar")); - app_state app; - UNIT_TEST_CHECK_THROW(path_restriction(app.work, includes, excludes, -1), + UNIT_TEST_CHECK_THROW(path_restriction(includes, excludes, -1), informative_failure); } @@ -939,8 +933,7 @@ UNIT_TEST(restrictions, ignored_invalid_ includes.push_back(file_path_internal("foo")); excludes.push_back(file_path_internal("bar")); - app_state app; - path_restriction pmask(app.work, includes, excludes, -1, + path_restriction pmask(includes, excludes, -1, path_restriction::skip_check); UNIT_TEST_CHECK( pmask.includes(file_path_internal("foo"))); @@ -956,7 +949,6 @@ UNIT_TEST(restrictions, include_depth_0) includes.push_back(file_path_internal("x")); includes.push_back(file_path_internal("y")); - app_state app; // FIXME: depth == 0 currently means directory + immediate children // this should be changed to mean just the named directory but for // compatibility with old restrictions this behaviour has been preserved @@ -964,7 +956,7 @@ UNIT_TEST(restrictions, include_depth_0) // check restricted nodes - node_restriction nmask(app.work, includes, excludes, depth, roster); + node_restriction nmask(includes, excludes, depth, roster); UNIT_TEST_CHECK(!nmask.empty()); @@ -994,7 +986,7 @@ UNIT_TEST(restrictions, include_depth_0) // check restricted paths - path_restriction pmask(app.work, includes, excludes, depth); + path_restriction pmask(includes, excludes, depth); UNIT_TEST_CHECK(!pmask.empty()); @@ -1030,7 +1022,6 @@ UNIT_TEST(restrictions, include_depth_0_ vector includes, excludes; - app_state app; // FIXME: depth == 0 currently means directory + immediate children // this should be changed to mean just the named directory but for // compatibility with old restrictions this behaviour has been preserved @@ -1038,7 +1029,7 @@ UNIT_TEST(restrictions, include_depth_0_ // check restricted nodes - node_restriction nmask(app.work, includes, excludes, depth, roster); + node_restriction nmask(includes, excludes, depth, roster); UNIT_TEST_CHECK( nmask.empty()); @@ -1068,7 +1059,7 @@ UNIT_TEST(restrictions, include_depth_0_ // check restricted paths - path_restriction pmask(app.work, includes, excludes, depth); + path_restriction pmask(includes, excludes, depth); UNIT_TEST_CHECK( pmask.empty()); @@ -1106,7 +1097,6 @@ UNIT_TEST(restrictions, include_depth_1) includes.push_back(file_path_internal("x")); includes.push_back(file_path_internal("y")); - app_state app; // FIXME: depth == 1 currently means directory + children + grand children // this should be changed to mean directory + immediate children but for // compatibility with old restrictions this behaviour has been preserved @@ -1114,7 +1104,7 @@ UNIT_TEST(restrictions, include_depth_1) // check restricted nodes - node_restriction nmask(app.work, includes, excludes, depth, roster); + node_restriction nmask(includes, excludes, depth, roster); UNIT_TEST_CHECK(!nmask.empty()); @@ -1144,7 +1134,7 @@ UNIT_TEST(restrictions, include_depth_1) // check restricted paths - path_restriction pmask(app.work, includes, excludes, depth); + path_restriction pmask(includes, excludes, depth); UNIT_TEST_CHECK(!pmask.empty()); ============================================================ --- restrictions.hh 0b2c8a2c94abcc8d9d84e6684430f4324ce29f7a +++ restrictions.hh 20265e8afcdb9edc9e070a21e791f4ca7517b968 @@ -72,25 +72,37 @@ class restriction long depth; }; +// When used from the main program, restrictions are always created in a +// context where it's meaningful to provide a workspace object. However, +// restrictions.cc's own unit test harness creates them in a context where +// it is _not_ meaningful to do that. I see no good alternative to this +// little bit of ugliness. + +#ifdef BUILD_UNIT_TESTS +#define WORK_ARGDECL // nothing +#else +#define WORK_ARGDECL workspace & work, // note trailing comma +#endif + class node_restriction : public restriction { public: node_restriction() : restriction() {} - node_restriction(workspace & work, + node_restriction(WORK_ARGDECL std::vector const & includes, std::vector const & excludes, long depth, roster_t const & roster); - node_restriction(workspace & work, + node_restriction(WORK_ARGDECL std::vector const & includes, std::vector const & excludes, long depth, roster_t const & roster1, roster_t const & roster2); - node_restriction(workspace & work, + node_restriction(WORK_ARGDECL std::vector const & includes, std::vector const & excludes, long depth, @@ -121,7 +133,7 @@ class path_restriction : public restrict path_restriction() : restriction() {} - path_restriction(workspace & work, + path_restriction(WORK_ARGDECL std::vector const & includes, std::vector const & excludes, long depth, @@ -133,6 +145,8 @@ class path_restriction : public restrict std::map path_map; }; +#undef WORK_ARGDECL + // Local Variables: // mode: C++ // fill-column: 76