From 062f78118afc40887a65f316e47984ebeb483636 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Sun, 17 Mar 2013 16:03:11 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20(re)scan=20when=20creating=20fs?= =?UTF-8?q?::node=5Ft?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also make it optional to provide a map pointer (for collecting changes) when rescanning. --- Frameworks/bundles/src/fsevents/fs_controller.cc | 6 +++--- Frameworks/bundles/src/fsevents/fs_tree.cc | 7 ++----- Frameworks/bundles/src/fsevents/fs_tree.h | 4 ++-- Frameworks/bundles/tests/t_fs_tree_serializing.cc | 9 ++++++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Frameworks/bundles/src/fsevents/fs_controller.cc b/Frameworks/bundles/src/fsevents/fs_controller.cc index 0e98e3d1..958e97b4 100644 --- a/Frameworks/bundles/src/fsevents/fs_controller.cc +++ b/Frameworks/bundles/src/fsevents/fs_controller.cc @@ -89,7 +89,7 @@ namespace fs } _event_ids.insert(std::make_pair(*path, dirInfo)); - newHeads.insert(std::make_pair(*path, node_t(*path, false).rescan(path::parent(*path), _dir_glob, _file_glob, NULL))); + newHeads.insert(std::make_pair(*path, node_t(*path).rescan(path::parent(*path), _dir_glob, _file_glob))); } rootPaths.clear(); @@ -156,7 +156,7 @@ namespace fs directory_info_t dirInfo(*link, FSEventsGetCurrentEventId()); _event_ids.insert(std::make_pair(*link, dirInfo)); - _heads.insert(std::make_pair(*link, node_t(*link, false).rescan(path::parent(*link), _dir_glob, _file_glob, NULL))); + _heads.insert(std::make_pair(*link, node_t(*link).rescan(path::parent(*link), _dir_glob, _file_glob))); fs::watch(*link, this, dirInfo._event_id); } @@ -233,7 +233,7 @@ namespace fs cwd = node.path(cwd); if(cwd == path) { - fs::node_t newNode(cwd, false); + fs::node_t newNode(cwd); if(node._type != newNode._type || node._modified != newNode._modified) { if(node._type == fs::node_t::kNodeTypeMissing) _changes["created"].push_back(cwd); diff --git a/Frameworks/bundles/src/fsevents/fs_tree.cc b/Frameworks/bundles/src/fsevents/fs_tree.cc index da77184d..b05de70f 100644 --- a/Frameworks/bundles/src/fsevents/fs_tree.cc +++ b/Frameworks/bundles/src/fsevents/fs_tree.cc @@ -7,7 +7,7 @@ OAK_DEBUG_VAR(FS_Tree); namespace fs { - node_t::node_t (std::string const& path, bool scan) : _name(path::name(path)), _resolved(NULL_STR), _modified(0) + node_t::node_t (std::string const& path) : _name(path::name(path)), _resolved(NULL_STR), _modified(0) { struct stat buf; if(lstat(path.c_str(), &buf) == 0) @@ -17,9 +17,6 @@ namespace fs { _type = kNodeTypeDirectory; _entries.reset(new std::vector); - - if(scan) - rescan(path::parent(path), "*", "*", NULL); } else if(S_ISREG(buf.st_mode)) { @@ -71,7 +68,7 @@ namespace fs int type = (*entry)->d_type; if(type == DT_DIR && dirGlob.does_match(path) || type == DT_REG && fileGlob.does_match(path) || type == DT_LNK) { - node_t node(path, false); + node_t node(path); key_t key(node._name, node._resolved, node._type); std::map::iterator it = entries.find(key); if(it != entries.end()) diff --git a/Frameworks/bundles/src/fsevents/fs_tree.h b/Frameworks/bundles/src/fsevents/fs_tree.h index 03a8ad8d..f4232092 100644 --- a/Frameworks/bundles/src/fsevents/fs_tree.h +++ b/Frameworks/bundles/src/fsevents/fs_tree.h @@ -15,7 +15,7 @@ namespace fs { enum node_type_t { kNodeTypeDirectory, kNodeTypeLink, kNodeTypeFile, kNodeTypeMissing }; - explicit node_t (std::string const& path, bool scan = true); + explicit node_t (std::string const& path); std::string name () const { return _name; } std::string path (std::string const& cwd) const { return path::join(cwd, _name); } @@ -27,7 +27,7 @@ namespace fs bool operator!= (node_t const& rhs) const { return !(*this == rhs); } node_t (std::string const& name, std::string const& resolved, node_type_t type, time_t modified = 0, nodes_ptr const& entries = nodes_ptr()) : _name(name), _resolved(resolved), _type(type), _modified(modified), _entries(entries) { } - node_t& rescan (std::string const& cwd, path::glob_t const& dirGlob, path::glob_t const& fileGlob, std::map< std::string, std::vector >* changes); + node_t& rescan (std::string const& cwd, path::glob_t const& dirGlob, path::glob_t const& fileGlob, std::map< std::string, std::vector >* changes = NULL); std::string _name; std::string _resolved; diff --git a/Frameworks/bundles/tests/t_fs_tree_serializing.cc b/Frameworks/bundles/tests/t_fs_tree_serializing.cc index d4228e0a..f24052c3 100644 --- a/Frameworks/bundles/tests/t_fs_tree_serializing.cc +++ b/Frameworks/bundles/tests/t_fs_tree_serializing.cc @@ -22,10 +22,13 @@ public: void test_fs_tree_serializing () { test::jail_t jail; - setup_test_folder(jail.path()); + std::string const path = jail.path(); - fs::node_t lhs(jail.path()); - TS_ASSERT_EQUALS(lhs, fs::node_t(jail.path())); + setup_test_folder(path); + + fs::node_t lhs(path); + fs::node_t rhs(path); + TS_ASSERT_EQUALS(lhs.rescan(path, "*", "*"), rhs.rescan(path, "*", "*")); std::string const& plistFile = jail.path("tree.plist"); plist::save(plistFile, to_plist(lhs));