diff options
author | Enrico Zini <enrico@enricozini.org> | 2013-10-22 01:23:36 +0200 |
---|---|---|
committer | Enrico Zini <enrico@enricozini.org> | 2013-10-22 01:23:36 +0200 |
commit | 77f22831a80ccf3d42898a655d049fb4c90fdf6a (patch) | |
tree | bf6f61d9773e7f5db4b03dc8560894c095074ac4 | |
parent | 43c376aa91c31dbd519451235d0effb995a2b1a7 (diff) | |
download | libept-77f22831a80ccf3d42898a655d049fb4c90fdf6a.tar.gz |
Ported to libwibble 1.0
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | ept/debtags/maint/sourcedir.cc | 114 | ||||
-rw-r--r-- | ept/debtags/maint/sourcedir.h | 8 | ||||
-rw-r--r-- | ept/debtags/maint/sourcedir.tcc | 27 | ||||
-rw-r--r-- | ept/popcon/maint/sourcedir.cc | 62 | ||||
-rw-r--r-- | ept/popcon/maint/sourcedir.h | 8 |
6 files changed, 145 insertions, 76 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d18a2f4..0c21139 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ if( INTERNAL_WIBBLE ) set( WIBBLE_LIBRARIES "wibble" ) set( WIBBLE_TEST_CMAKE "${wibble_SOURCE_DIR}/test.cmake" ) else( INTERNAL_WIBBLE ) - pkg_check_modules( WIBBLE REQUIRED "libwibble >= 0.1.22" ) + pkg_check_modules( WIBBLE REQUIRED "libwibble >= 1.0" ) find_program( WIBBLE_TEST_GENRUNNER wibble-test-genrunner ) set( WIBBLE_TEST_CMAKE "${WIBBLE_PREFIX}/share/wibble/test.cmake" ) endif( INTERNAL_WIBBLE ) diff --git a/ept/debtags/maint/sourcedir.cc b/ept/debtags/maint/sourcedir.cc index 9b008fb..67ca7d7 100644 --- a/ept/debtags/maint/sourcedir.cc +++ b/ept/debtags/maint/sourcedir.cc @@ -3,15 +3,25 @@ #include <ept/debtags/maint/path.h> #include <wibble/string.h> +#include <wibble/sys/fs.h> #include <tagcoll/input/zlib.h> #include <tagcoll/input/stdio.h> +using namespace std; using namespace wibble; namespace ept { namespace debtags { +SourceDir::SourceDir(const std::string& path) + : path(path) +{ +} +SourceDir::~SourceDir() +{ +} + SourceDir::FileType SourceDir::fileType(const std::string& name) { if (name[0] == '.') return SKIP; @@ -42,16 +52,22 @@ SourceDir::FileType SourceDir::fileType(const std::string& name) time_t SourceDir::timestamp() { - if (!valid()) return 0; - - time_t max = 0; - for (const_iterator d = begin(); d != end(); ++d) - { - FileType type = fileType(d->d_name); - if (type == SKIP) continue; - - time_t ts = Path::timestamp(str::joinpath(path(), d->d_name)); - if (ts > max) max = ts; + auto_ptr<sys::fs::Directory> dir; + try { + dir.reset(new sys::fs::Directory(path)); + } catch (wibble::exception::System& e) { + return 0; + } + + time_t max = 0; + for (sys::fs::Directory::const_iterator d = dir->begin(); d != dir->end(); ++d) + { + string name = *d; + FileType type = fileType(name); + if (type == SKIP) continue; + + time_t ts = Path::timestamp(str::joinpath(path, name)); + if (ts > max) max = ts; } return max; @@ -59,16 +75,22 @@ time_t SourceDir::timestamp() time_t SourceDir::vocTimestamp() { - if (!valid()) return 0; - - time_t max = 0; - for (const_iterator d = begin(); d != end(); ++d) - { - FileType type = fileType(d->d_name); - if (type != VOC and type != VOCGZ) continue; - - time_t ts = Path::timestamp(str::joinpath(path(), d->d_name)); - if (ts > max) max = ts; + auto_ptr<sys::fs::Directory> dir; + try { + dir.reset(new sys::fs::Directory(path)); + } catch (wibble::exception::System& e) { + return 0; + } + + time_t max = 0; + for (sys::fs::Directory::const_iterator d = dir->begin(); d != dir->end(); ++d) + { + string name = *d; + FileType type = fileType(name); + if (type != VOC and type != VOCGZ) continue; + + time_t ts = Path::timestamp(str::joinpath(path, name)); + if (ts > max) max = ts; } return max; @@ -76,16 +98,22 @@ time_t SourceDir::vocTimestamp() time_t SourceDir::tagTimestamp() { - if (!valid()) return 0; - - time_t max = 0; - for (const_iterator d = begin(); d != end(); ++d) - { - FileType type = fileType(d->d_name); - if (type != TAG and type != TAGGZ) continue; - - time_t ts = Path::timestamp(str::joinpath(path(), d->d_name)); - if (ts > max) max = ts; + auto_ptr<sys::fs::Directory> dir; + try { + dir.reset(new sys::fs::Directory(path)); + } catch (wibble::exception::System& e) { + return 0; + } + + time_t max = 0; + for (sys::fs::Directory::const_iterator d = dir->begin(); d != dir->end(); ++d) + { + string name = *d; + FileType type = fileType(name); + if (type != TAG and type != TAGGZ) continue; + + time_t ts = Path::timestamp(str::joinpath(path, name)); + if (ts > max) max = ts; } return max; @@ -93,24 +121,30 @@ time_t SourceDir::tagTimestamp() void SourceDir::readVocabularies(Vocabulary& out) { - if (!valid()) return; - - for (const_iterator d = begin(); d != end(); ++d) - { - if (d->d_name[0] == '.') continue; - FileType type = fileType(d->d_name); + auto_ptr<sys::fs::Directory> dir; + try { + dir.reset(new sys::fs::Directory(path)); + } catch (wibble::exception::System& e) { + return; + } + + for (sys::fs::Directory::const_iterator d = dir->begin(); d != dir->end(); ++d) + { + string name = *d; + if (name[0] == '.') continue; + FileType type = fileType(name); if (type == VOC) { - // Read uncompressed data - tagcoll::input::Stdio in(str::joinpath(path(), d->d_name)); + // Read uncompressed data + tagcoll::input::Stdio in(str::joinpath(path, name)); // Read the vocabulary out.read(in); } else if (type == VOCGZ) { - // Read compressed data - tagcoll::input::Zlib in(str::joinpath(path(), d->d_name)); + // Read compressed data + tagcoll::input::Zlib in(str::joinpath(path, name)); // Read the vocabulary out.read(in); diff --git a/ept/debtags/maint/sourcedir.h b/ept/debtags/maint/sourcedir.h index 988ae24..3357c04 100644 --- a/ept/debtags/maint/sourcedir.h +++ b/ept/debtags/maint/sourcedir.h @@ -24,7 +24,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <wibble/sys/fs.h> #include <string> namespace ept { @@ -35,17 +34,20 @@ class Vocabulary; /** * Access a directory containing Debtags data files */ -class SourceDir : public wibble::sys::fs::Directory +class SourceDir { protected: enum FileType { SKIP, TAG, VOC, TAGGZ, VOCGZ }; + std::string path; + // Check if a file name is a tag file, a vocabulary file or a file to skip. // Please notice that it works on file names, not paths. FileType fileType(const std::string& name); public: - SourceDir(const std::string& path) : Directory(path) {} + SourceDir(const std::string& path); + ~SourceDir(); /// Return the time of the newest file in the source directory time_t timestamp(); diff --git a/ept/debtags/maint/sourcedir.tcc b/ept/debtags/maint/sourcedir.tcc index b834f51..1d1c7f0 100644 --- a/ept/debtags/maint/sourcedir.tcc +++ b/ept/debtags/maint/sourcedir.tcc @@ -9,6 +9,9 @@ #include <tagcoll/input/zlib.h> #include <tagcoll/input/stdio.h> +#include <wibble/sys/fs.h> + +using namespace wibble; namespace ept { namespace debtags { @@ -16,23 +19,29 @@ namespace debtags { template<typename OUT> void SourceDir::readTags(OUT out) { - if (!valid()) return; - - for (const_iterator d = begin(); d != end(); ++d) - { - FileType type = fileType(d->d_name); + auto_ptr<sys::fs::Directory> dir; + try { + dir.reset(new sys::fs::Directory(path)); + } catch (wibble::exception::System& e) { + return; + } + + for (sys::fs::Directory::const_iterator d = dir->begin(); d != dir->end(); ++d) + { + string name = *d; + FileType type = fileType(name); if (type == TAG) { - // Read uncompressed data - tagcoll::input::Stdio in(path() + "/" + d->d_name); + // Read uncompressed data + tagcoll::input::Stdio in(path + "/" + name); // Read the collection tagcoll::textformat::parse(in, out); } else if (type == TAGGZ) { - // Read compressed data - tagcoll::input::Zlib in(path() + "/" + d->d_name); + // Read compressed data + tagcoll::input::Zlib in(path + "/" + name); // Read the collection tagcoll::textformat::parse(in, out); diff --git a/ept/popcon/maint/sourcedir.cc b/ept/popcon/maint/sourcedir.cc index 44afa4e..471a9f7 100644 --- a/ept/popcon/maint/sourcedir.cc +++ b/ept/popcon/maint/sourcedir.cc @@ -2,6 +2,7 @@ #include <ept/popcon/maint/path.h> #include <wibble/string.h> +#include <wibble/sys/fs.h> #include <tagcoll/input/zlib.h> #include <tagcoll/input/stdio.h> @@ -14,6 +15,14 @@ using namespace wibble; namespace ept { namespace popcon { +SourceDir::SourceDir(const std::string& path) + : path(path) +{ +} +SourceDir::~SourceDir() +{ +} + SourceDir::FileType SourceDir::fileType(const std::string& name) { if (name[0] == '.') return SKIP; @@ -26,16 +35,22 @@ SourceDir::FileType SourceDir::fileType(const std::string& name) time_t SourceDir::timestamp() { - if (!valid()) return 0; - - time_t max = 0; - for (const_iterator d = begin(); d != end(); ++d) - { - FileType type = fileType(d->d_name); - if (type == SKIP) continue; - - time_t ts = Path::timestamp(str::joinpath(path(), d->d_name)); - if (ts > max) max = ts; + auto_ptr<sys::fs::Directory> dir; + try { + dir.reset(new sys::fs::Directory(path)); + } catch (wibble::exception::System& e) { + return 0; + } + + time_t max = 0; + for (sys::fs::Directory::const_iterator d = dir->begin(); d != dir->end(); ++d) + { + string name = *d; + FileType type = fileType(name); + if (type == SKIP) continue; + + time_t ts = Path::timestamp(str::joinpath(path, name)); + if (ts > max) max = ts; } return max; @@ -109,16 +124,23 @@ static void parseScores(tagcoll::input::Input& in, map<std::string, Score>& out, bool SourceDir::readScores(map<std::string, Score>& out, size_t& submissions) { - if (!valid()) return false; - bool done = false; - - for (const_iterator d = begin(); d != end(); ++d) - { - FileType type = fileType(d->d_name); + auto_ptr<sys::fs::Directory> dir; + try { + dir.reset(new sys::fs::Directory(path)); + } catch (wibble::exception::System& e) { + return false; + } + + bool done = false; + + for (sys::fs::Directory::const_iterator d = dir->begin(); d != dir->end(); ++d) + { + string name = *d; + FileType type = fileType(name); if (type == RAW) { - // Read uncompressed data - tagcoll::input::Stdio in(str::joinpath(path(), d->d_name)); + // Read uncompressed data + tagcoll::input::Stdio in(str::joinpath(path, name)); // Read the scores parseScores(in, out, submissions); @@ -126,8 +148,8 @@ bool SourceDir::readScores(map<std::string, Score>& out, size_t& submissions) } else if (type == RAWGZ) { - // Read compressed data - tagcoll::input::Zlib in(str::joinpath(path(), d->d_name)); + // Read compressed data + tagcoll::input::Zlib in(str::joinpath(path, name)); // Read the scores parseScores(in, out, submissions); diff --git a/ept/popcon/maint/sourcedir.h b/ept/popcon/maint/sourcedir.h index fb8911f..9217fd1 100644 --- a/ept/popcon/maint/sourcedir.h +++ b/ept/popcon/maint/sourcedir.h @@ -25,7 +25,6 @@ */ #include <ept/popcon/popcon.h> -#include <wibble/sys/fs.h> #include <string> #include <map> @@ -35,17 +34,20 @@ namespace popcon { /** * Access a directory containing Debtags data files */ -class SourceDir : public wibble::sys::fs::Directory +class SourceDir { protected: enum FileType { SKIP, RAW, RAWGZ }; + std::string path; + // Check if a file name is a tag file, a vocabulary file or a file to skip. // Please notice that it works on file names, not paths. FileType fileType(const std::string& name); public: - SourceDir(const std::string& path) : Directory(path) {} + SourceDir(const std::string& path); + ~SourceDir(); /// Return the time of the newest file in the source directory time_t timestamp(); |