Don’t (re)scan when creating fs::node_t

Also make it optional to provide a map pointer (for collecting changes) when rescanning.
This commit is contained in:
Allan Odgaard
2013-03-17 16:03:11 +01:00
parent 04142cbf69
commit 062f78118a
4 changed files with 13 additions and 13 deletions

View File

@@ -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);

View File

@@ -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<node_t>);
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<key_t, value_t>::iterator it = entries.find(key);
if(it != entries.end())

View File

@@ -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<std::string> >* changes);
node_t& rescan (std::string const& cwd, path::glob_t const& dirGlob, path::glob_t const& fileGlob, std::map< std::string, std::vector<std::string> >* changes = NULL);
std::string _name;
std::string _resolved;

View File

@@ -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));