From c31473777035e7250a42bc0c02b91937d0d64189 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Tue, 21 Feb 2012 20:09:59 -0500 Subject: [PATCH] lib: added Restore::GetDBList() Returns a DBListType list of databased names, from the given tarball. --- src/configfile.cc | 13 +++++++++++++ src/configfile.h | 3 +++ src/restore.cc | 30 +++++++++++++++++++++++++++++- src/restore.h | 9 +++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/configfile.cc b/src/configfile.cc index 29ef5650..35a88c31 100644 --- a/src/configfile.cc +++ b/src/configfile.cc @@ -86,6 +86,19 @@ bool ConfigFile::DBListType::IsSelected(const std::string &dbname) const return false; } +std::ostream& operator<< (std::ostream &os, const ConfigFile::DBListType &list) +{ + os << "DBListType dump:\n"; + + for( ConfigFile::DBListType::const_iterator i = list.begin(); + i != list.end(); + ++i ) + { + os << " " << *i << "\n"; + } + return os; +} + ////////////////////////////////////////////////////////////////////////////// // ConfigFile class members diff --git a/src/configfile.h b/src/configfile.h index eabdb120..43c7246d 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -26,6 +26,7 @@ #include "record.h" #include "pin.h" #include +#include namespace Barry { @@ -214,6 +215,8 @@ public: void SetVerboseLogging(bool verbose = true); }; +BXEXPORT std::ostream& operator<< (std::ostream &os, const ConfigFile::DBListType &list); + } // namespace Barry #endif diff --git a/src/restore.cc b/src/restore.cc index f9993dc1..686a83e4 100644 --- a/src/restore.cc +++ b/src/restore.cc @@ -36,6 +36,7 @@ namespace { int CountFiles(reuse::TarFile &tar, const Barry::Restore::DBListType &restoreList, + Barry::Restore::DBListType *available, bool default_all_db) { int count = 0; @@ -52,6 +53,9 @@ namespace { last_name = dbname; good = (default_all_db && restoreList.size() == 0) || restoreList.IsSelected(dbname); + + if( good && available ) + available->push_back(dbname); } if( good ) count++; @@ -210,7 +214,7 @@ unsigned int Restore::GetRecordTotal(const std::string &tarpath, // do a scan through the tar file tar.reset( new reuse::TarFile(tarpath.c_str(), false, &reuse::gztar_ops_nonthread, true) ); - count = CountFiles(*tar, dbList, default_all_db); + count = CountFiles(*tar, dbList, 0, default_all_db); } catch( reuse::TarFile::TarError &te ) { throw Barry::RestoreError(te.what()); @@ -218,6 +222,30 @@ unsigned int Restore::GetRecordTotal(const std::string &tarpath, return count; } +Barry::Restore::DBListType Restore::GetDBList() const +{ + return GetDBList(m_tarpath); +} + +Barry::Restore::DBListType Restore::GetDBList(const std::string &tarpath) +{ + unsigned int count = 0; + + std::auto_ptr tar; + DBListType available, empty; + + try { + // do a scan through the tar file + tar.reset( new reuse::TarFile(tarpath.c_str(), false, + &reuse::gztar_ops_nonthread, true) ); + count = CountFiles(*tar, empty, &available, true); + return available; + } + catch( reuse::TarFile::TarError &te ) { + throw Barry::RestoreError(te.what()); + } +} + bool Restore::GetNextMeta(DBData &data) { // always use m_record_data here, so that we don't lose access diff --git a/src/restore.h b/src/restore.h index d67e5858..6c3e3e3b 100644 --- a/src/restore.h +++ b/src/restore.h @@ -141,6 +141,15 @@ public: static unsigned int GetRecordTotal(const std::string &tarpath, const DBListType &dbList, bool default_all_db); + /// Loads the given file, and creates a DBListType list of + /// all database names available in the tarball, using no filters. + /// Does not use the main Restore file, but opens the file separately. + /// It is safe to call this function as often as needed. + DBListType GetDBList() const; + + /// Static version of GetDBList() + static DBListType GetDBList(const std::string &tarpath); + /// If this function returns true, it fills data with the /// meta data that the next call to BuildRecord() will retrieve. /// This is useful for applications that need to setup a manual -- 2.11.4.GIT