# # # patch "paths.cc" # from [51e6ebc6e9079807485d8359c8e17726ed74619c] # to [31d036c73acc2e8580797e85cda1f41c70f4d80c] # # patch "paths.hh" # from [3c3ad14d890d72a47e359d698e687520d594c13c] # to [7cdacf2509ae5f46de2d98d009cc609ac901419a] # # patch "restrictions.cc" # from [9c67575a229df8b944b5da5a7a6721c40588f92d] # to [274328f9e9bfc21df9297e11023c3b1cd08ecdf9] # # patch "restrictions.hh" # from [a65df1d2fc5748b5c235663b4fed9d4b05c3a976] # to [d588f4ba6876b51d61d3f37f4836bf2272434310] # ============================================================ --- paths.cc 51e6ebc6e9079807485d8359c8e17726ed74619c +++ paths.cc 31d036c73acc2e8580797e85cda1f41c70f4d80c @@ -647,10 +647,9 @@ bool /////////////////////////////////////////////////////////////////////////// bool -workspace_root(split_path const & sp) +workspace_root(file_path const & path) { - I(null_name(idx(sp,0))); - return sp.size() == 1; + return path.empty(); } void ============================================================ --- paths.hh 3c3ad14d890d72a47e359d698e687520d594c13c +++ paths.hh 7cdacf2509ae5f46de2d98d009cc609ac901419a @@ -120,9 +120,6 @@ null_name(path_component pc) return pc == the_null_component; } -bool -workspace_root(split_path const & sp); - // It's possible this will become a proper virtual interface in the future, // but since the implementation is exactly the same in all cases, there isn't // much point ATM... @@ -254,6 +251,9 @@ template <> void dump(system_path const // utilities +bool +workspace_root(file_path const & path); + void dirname_basename(split_path const & sp, split_path & dirname, path_component & basename); ============================================================ --- restrictions.cc 9c67575a229df8b944b5da5a7a6721c40588f92d +++ restrictions.cc 274328f9e9bfc21df9297e11023c3b1cd08ecdf9 @@ -31,29 +31,20 @@ static void // include these nodes. static void -make_path_set(vector const & paths, path_set & split_paths) -{ - for (vector::const_iterator i = paths.begin(); i != paths.end(); ++i) - { - split_path sp; - i->split(sp); - split_paths.insert(sp); - } -} - -static void map_nodes(map & node_map, roster_t const & roster, - path_set const & paths, - path_set & known_paths, + set const & paths, + set & known_paths, restricted_path::status const status) { - for (path_set::const_iterator i = paths.begin(); i != paths.end(); ++i) + for (set::const_iterator i = paths.begin(); i != paths.end(); ++i) { - if (roster.has_node(*i)) + split_path s; + i->split(s); + if (roster.has_node(s)) { known_paths.insert(*i); - node_id nid = roster.get_node(*i)->self; + node_id nid = roster.get_node(s)->self; map::iterator n = node_map.find(nid); if (n != node_map.end()) @@ -66,13 +57,13 @@ static void } static void -map_paths(map & path_map, - path_set const & paths, +map_paths(map & path_map, + set const & paths, restricted_path::status const status) { - for (path_set::const_iterator i = paths.begin(); i != paths.end(); ++i) + for (set::const_iterator i = paths.begin(); i != paths.end(); ++i) { - map::iterator p = path_map.find(*i); + map::iterator p = path_map.find(*i); if (p != path_map.end()) N(p->second == status, F("conflicting include/exclude on path '%s'") % *i); @@ -82,14 +73,14 @@ static void } static void -validate_roster_paths(path_set const & included_paths, - path_set const & excluded_paths, - path_set const & known_paths, +validate_roster_paths(set const & included_paths, + set const & excluded_paths, + set const & known_paths, app_state & app) { int bad = 0; - for (path_set::const_iterator i = included_paths.begin(); + for (set::const_iterator i = included_paths.begin(); i != included_paths.end(); ++i) { // ignored paths are allowed into the restriction but are not @@ -97,8 +88,7 @@ validate_roster_paths(path_set const & i // rosters if (known_paths.find(*i) == known_paths.end()) { - file_path fp(*i); - if (!app.lua.hook_ignore_file(fp)) + if (!app.lua.hook_ignore_file(*i)) { bad++; W(F("restriction includes unknown path '%s'") % *i); @@ -106,7 +96,7 @@ validate_roster_paths(path_set const & i } } - for (path_set::const_iterator i = excluded_paths.begin(); + for (set::const_iterator i = excluded_paths.begin(); i != excluded_paths.end(); ++i) { if (known_paths.find(*i) == known_paths.end()) @@ -120,13 +110,13 @@ void } void -validate_workspace_paths(path_set const & included_paths, - path_set const & excluded_paths, +validate_workspace_paths(set const & included_paths, + set const & excluded_paths, app_state & app) { int bad = 0; - for (path_set::const_iterator i = included_paths.begin(); + for (set::const_iterator i = included_paths.begin(); i != included_paths.end(); ++i) { if (workspace_root(*i)) @@ -135,22 +125,20 @@ validate_workspace_paths(path_set const // ignored paths are allowed into the restriction but are not // considered invalid if they are found in none of the restriction's // rosters - file_path fp(*i); - if (!path_exists(fp) && !app.lua.hook_ignore_file(fp)) + if (!path_exists(*i) && !app.lua.hook_ignore_file(*i)) { bad++; W(F("restriction includes unknown path '%s'") % *i); } } - for (path_set::const_iterator i = excluded_paths.begin(); + for (set::const_iterator i = excluded_paths.begin(); i != excluded_paths.end(); ++i) { if (workspace_root(*i)) continue; - file_path fp(*i); - if (!path_exists(fp)) + if (!path_exists(*i)) { bad++; W(F("restriction excludes unknown path '%s'") % *i); @@ -163,11 +151,10 @@ restriction::restriction(std::vector const & includes, std::vector const & excludes, long depth) - : depth(depth) -{ - make_path_set(includes, included_paths); - make_path_set(excludes, excluded_paths); -} + : included_paths(includes.begin(), includes.end()), + excluded_paths(excludes.begin(), excludes.end()), + depth(depth) +{} node_restriction::node_restriction(std::vector const & includes, std::vector const & excludes, @@ -331,8 +318,10 @@ bool } bool -path_restriction::includes(split_path const & sp) const +path_restriction::includes(file_path const & pth) const { + split_path sp; + pth.split(sp); if (empty()) { if (depth != -1) @@ -356,50 +345,44 @@ path_restriction::includes(split_path co } } - split_path current(sp); - int path_depth = 0; - // FIXME: this uses depth+1 because the old semantics of depth=0 were // something like "the current directory and its immediate children". it // seems somewhat more reasonable here to use depth=0 to mean "exactly // this directory" and depth=1 to mean "this directory and its immediate // children" - while (!current.empty() && (depth == -1 || path_depth <= depth + 1)) + int path_depth = 0; + while (!sp.empty() && (depth == -1 || path_depth <= depth + 1)) { - map::const_iterator - r = path_map.find(current); + map::const_iterator + r = path_map.find(file_path(sp)); if (r != path_map.end()) { switch (r->second) { case restricted_path::included: - L(FL("explicit include of path '%s'") - % file_path(sp)); + L(FL("explicit include of path '%s'") % pth); return true; case restricted_path::excluded: - L(FL("explicit exclude of path '%s'") - % file_path(sp)); + L(FL("explicit exclude of path '%s'") % pth); return false; } } - current.pop_back(); + sp.pop_back(); path_depth++; } if (included_paths.empty()) { - L(FL("default include of path '%s'") - % file_path(sp)); + L(FL("default include of path '%s'") % pth); return true; } else { - L(FL("default exclude of path '%s'") - % file_path(sp)); + L(FL("default exclude of path '%s'") % pth); return false; } } ============================================================ --- restrictions.hh a65df1d2fc5748b5c235663b4fed9d4b05c3a976 +++ restrictions.hh d588f4ba6876b51d61d3f37f4836bf2272434310 @@ -68,7 +68,7 @@ class restriction std::vector const & excludes, long depth); - path_set included_paths, excluded_paths; + std::set included_paths, excluded_paths; long depth; }; @@ -110,7 +110,7 @@ class node_restriction : public restrict } private: - path_set known_paths; + std::set known_paths; std::map node_map; }; @@ -124,10 +124,10 @@ class path_restriction : public restrict long depth, app_state & a); - bool includes(split_path const & sp) const; + bool includes(file_path const & sp) const; private: - std::map path_map; + std::map path_map; }; // Local Variables: