diff --git a/src/filesearcher.cpp b/src/filesearcher.cpp index d9d7cf7..e56b74d 100644 --- a/src/filesearcher.cpp +++ b/src/filesearcher.cpp @@ -39,21 +39,28 @@ namespace fastf { __thread SearchOptions g_searchOptions; - bool print_def_callback (const char* parPath, int parLevel, bool parDir, bool parSymlink) { + bool print_def_callback (const char* parPath, const FileStats& parStats) { std::cout << parPath; - if (parDir) { + if (parStats.is_dir) { std::cout << '/'; } - if (parSymlink) { + if (parStats.is_symlink) { std::cout << " (symlink)"; } - std::cout << " (" << parLevel << ')'; + std::cout << " (" << parStats.level << ')'; std::cout << '\n'; return true; } - int HandleDir (const char* parPath, const struct stat*, FTW* parBuff, bool parCanBeRead, bool parSymlink) { - if (not (*g_searchOptions.callback)(parPath, parBuff->level, true, parSymlink)) + int HandleDir (const char* parPath, const struct stat* parStat, FTW* parBuff, bool parCanBeRead, bool parSymlink) { + FileStats st; + st.level = parBuff->level; + st.is_dir = true; + st.is_symlink = parSymlink; + st.atime = parStat->st_atime; + st.mtime = parStat->st_mtime; + + if (not (*g_searchOptions.callback)(parPath, st)) return FTW_STOP; if (!parCanBeRead) return FTW_SKIP_SUBTREE; @@ -66,10 +73,17 @@ namespace fastf { return FTW_CONTINUE; } - int HandleFile (const char* parPath, const struct stat*, FTW* parBuff, bool parSymlink) { + int HandleFile (const char* parPath, const struct stat* parStat, FTW* parBuff, bool parSymlink) { const FileSearcher::ConstCharVecType& extensions = *g_searchOptions.extensions; + FileStats st; + st.level = parBuff->level; + st.is_dir = false; + st.is_symlink = parSymlink; + st.atime = parStat->st_atime; + st.mtime = parStat->st_mtime; + if (extensions.empty()) { - if (not (*g_searchOptions.callback)(parPath, parBuff->level, false, parSymlink)) { + if (not (*g_searchOptions.callback)(parPath, st)) { return FTW_STOP; } } @@ -78,7 +92,7 @@ namespace fastf { const int& extLen = extensions[z].len; const int pathLen = parBuff->base + std::strlen(parPath + parBuff->base); if (std::strncmp(extensions[z].str, parPath + pathLen - extLen, extensions[z].len) == 0) { - if (not (*g_searchOptions.callback)(parPath, parBuff->level, false, parSymlink)) { + if (not (*g_searchOptions.callback)(parPath, st)) { return FTW_STOP; } break; diff --git a/src/filesearcher.hpp b/src/filesearcher.hpp index 93c137a..06b3546 100644 --- a/src/filesearcher.hpp +++ b/src/filesearcher.hpp @@ -18,6 +18,7 @@ #ifndef idB6D385B7779240308449D6081CB790F1 #define idB6D385B7779240308449D6081CB790F1 +#include "filestats.hpp" #include #include #include @@ -37,7 +38,7 @@ namespace fastf { class FileSearcher { public: typedef std::vector ConstCharVecType; - typedef std::function CallbackType; + typedef std::function CallbackType; explicit FileSearcher ( boost::string_ref parBaseDir ); ~FileSearcher ( void ) noexcept; diff --git a/src/filestats.hpp b/src/filestats.hpp new file mode 100644 index 0000000..931f59e --- /dev/null +++ b/src/filestats.hpp @@ -0,0 +1,33 @@ +/* Copyright 2015, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#ifndef id4A7D7AB671954418939FC0BDA19C5B3F +#define id4A7D7AB671954418939FC0BDA19C5B3F + +#include + +namespace fastf { + struct FileStats { + int level; + std::time_t atime; + std::time_t mtime; + bool is_dir; + bool is_symlink; + }; +} //namespace fastf + +#endif diff --git a/src/indexer.cpp b/src/indexer.cpp index 706ccf7..a983154 100644 --- a/src/indexer.cpp +++ b/src/indexer.cpp @@ -20,6 +20,7 @@ #include "tiger.hpp" #include "dbbackend.hpp" #include "settings.hpp" +#include "filestats.hpp" #include #include #include @@ -311,9 +312,10 @@ namespace din { return true; } - bool Indexer::add_path (const char* parPath, int parLevel, bool parIsDir, bool parIsSymLink) { - m_local_data->paths.push_back(FileEntry(parPath, parLevel, parIsDir, parIsSymLink)); - if (not parIsDir) { + bool Indexer::add_path (const char* parPath, const fastf::FileStats& parStats) { + m_local_data->paths.push_back( + FileEntry(parPath, parStats)); + if (not parStats.is_dir) { ++m_local_data->file_count; } return true; diff --git a/src/indexer.hpp b/src/indexer.hpp index 997f0d9..6f3a4f0 100644 --- a/src/indexer.hpp +++ b/src/indexer.hpp @@ -31,6 +31,10 @@ namespace std { } //namespace std #endif +namespace fastf { + struct FileStats; +} //namespace fastf + namespace din { struct DinDBSettings; @@ -41,7 +45,7 @@ namespace din { Indexer ( const Indexer& ) = delete; ~Indexer ( void ) noexcept; - bool add_path ( const char* parPath, int parLevel, bool parIsDir, bool parIsSymlink ); + bool add_path ( const char* parPath, const fastf::FileStats& parStats ); #if defined(INDEXER_VERBOSE) void dump ( void ) const; #endif diff --git a/src/main.cpp b/src/main.cpp index 0f9444f..eb5cf63 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,8 +45,6 @@ namespace { int main (int parArgc, char* parArgv[]) { using std::placeholders::_1; using std::placeholders::_2; - using std::placeholders::_3; - using std::placeholders::_4; using boost::program_options::variables_map; variables_map vm; @@ -79,7 +77,7 @@ int main (int parArgc, char* parArgv[]) { fastf::FileSearcher searcher(search_path); fastf::FileSearcher::ConstCharVecType ext, ignore; searcher.SetFollowSymlinks(true); - searcher.SetCallback(fastf::FileSearcher::CallbackType(std::bind(&din::Indexer::add_path, &indexer, _1, _2, _3, _4))); + searcher.SetCallback(fastf::FileSearcher::CallbackType(std::bind(&din::Indexer::add_path, &indexer, _1, _2))); searcher.Search(ext, ignore); if (verbose) { std::cout << "Fetching items list...\n";