Skip to content

Commit

Permalink
add onBeforeScanDir hook to FileScanner
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Sep 7, 2011
1 parent cb072e9 commit 409011f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
39 changes: 37 additions & 2 deletions src/cpp/core/include/core/system/FileScanner.hpp
Expand Up @@ -17,6 +17,7 @@

#include <boost/function.hpp>

#include <core/Error.hpp>
#include <core/FileInfo.hpp>

#include <core/collection/Tree.hpp>
Expand All @@ -34,15 +35,49 @@ class Error;

namespace system {

Error scanFiles(const FileInfo& fromRoot,
Error scanFiles(const tree<FileInfo>::iterator_base& fromNode,
bool recursive,
const boost::function<bool(const FileInfo&)>& filter,
const boost::function<void(const FileInfo&)>& onBeforeScanDir,
tree<FileInfo>* pTree);

Error scanFiles(const FileInfo& fromRoot,
bool recursive,
const boost::function<bool(const FileInfo&)>& filter,
const boost::function<void(const FileInfo&)>& onBeforeScanDir,
tree<FileInfo>* pTree)
{
return scanFiles(pTree->set_head(fromRoot),
recursive,
filter,
onBeforeScanDir,
pTree);
}


Error scanFiles(const FileInfo& fromRoot,
bool recursive,
const boost::function<bool(const FileInfo&)>& filter,
tree<FileInfo>* pTree)
{
return scanFiles(fromRoot,
recursive,
filter,
boost::function<void(const FileInfo&)>(),
pTree);
}

Error scanFiles(const tree<FileInfo>::iterator_base& fromNode,
bool recursive,
const boost::function<bool(const FileInfo&)>& filter,
tree<FileInfo>* pTree);
tree<FileInfo>* pTree)
{
return scanFiles(fromNode,
recursive,
filter,
boost::function<void(const FileInfo&)>(),
pTree);
}

} // namespace system
} // namespace core
Expand Down
13 changes: 5 additions & 8 deletions src/cpp/core/system/PosixFileScanner.cpp
Expand Up @@ -38,17 +38,10 @@ int entryFilter(const struct dirent *entry)

} // anonymous namespace

Error scanFiles(const FileInfo& fromRoot,
bool recursive,
const boost::function<bool(const FileInfo&)>& filter,
tree<FileInfo>* pTree)
{
return scanFiles(pTree->set_head(fromRoot), recursive, filter, pTree);
}

Error scanFiles(const tree<FileInfo>::iterator_base& fromNode,
bool recursive,
const boost::function<bool(const FileInfo&)>& filter,
const boost::function<void(const FileInfo&)>& onBeforeScanDir,
tree<FileInfo>* pTree)
{
// clear all existing
Expand All @@ -57,6 +50,10 @@ Error scanFiles(const tree<FileInfo>::iterator_base& fromNode,
// create FilePath for root
FilePath rootPath(fromNode->absolutePath());

// call onBeforeScanDir hook
if (onBeforeScanDir)
onBeforeScanDir(*fromNode);

// read directory contents
struct dirent **namelist;
int entries = ::scandir(fromNode->absolutePath().c_str(),
Expand Down
12 changes: 5 additions & 7 deletions src/cpp/core/system/Win32FileScanner.cpp
Expand Up @@ -46,13 +46,6 @@ FileInfo toFileInfo(const FilePath& filePath)

} // anonymous namespace

Error scanFiles(const FileInfo& fromRoot,
bool recursive,
const boost::function<bool(const FileInfo&)>& filter,
tree<FileInfo>* pTree)
{
return scanFiles(pTree->set_head(fromRoot), recursive, filter, pTree);
}

// NOTE: we bail with an error if the top level directory can't be
// enumerated however we merely log errors for children. this reflects
Expand All @@ -65,6 +58,7 @@ Error scanFiles(const FileInfo& fromRoot,
Error scanFiles(const tree<FileInfo>::iterator_base& fromNode,
bool recursive,
const boost::function<bool(const FileInfo&)>& filter,
const boost::function<void(const FileInfo&)>& onBeforeScanDir,
tree<FileInfo>* pTree)
{
// clear all existing
Expand All @@ -73,6 +67,10 @@ Error scanFiles(const tree<FileInfo>::iterator_base& fromNode,
// create FilePath for root
FilePath rootPath(fromNode->absolutePath());

// call onBeforeScanDir hook
if (onBeforeScanDir)
onBeforeScanDir(*fromNode);

// read directory entries
std::vector<FilePath> children;
Error error = rootPath.children(&children);
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/core/system/file_monitor/LinuxFileMonitor.cpp
Expand Up @@ -31,6 +31,8 @@

#include "FileMonitorImpl.hpp"

// TODO: what happens if a symlink is the root entry

// TODO: investigate parallel package (multicore) interactions with file monitor

namespace core {
Expand Down

0 comments on commit 409011f

Please sign in to comment.