From 43699d039fa51d5813ce9818a27509fed33eb8e5 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 19 Jan 2020 14:33:01 +0000 Subject: [PATCH] Track package install status persistently. --- simgear/package/CatalogTest.cxx | 55 +++++++++++++++++++++--- simgear/package/Install.cxx | 12 ++++++ simgear/package/Install.hxx | 3 ++ simgear/package/catalogTest1/catalog.xml | 26 +++++++++++ 4 files changed, 90 insertions(+), 6 deletions(-) diff --git a/simgear/package/CatalogTest.cxx b/simgear/package/CatalogTest.cxx index 8b9f3435..d901c68f 100644 --- a/simgear/package/CatalogTest.cxx +++ b/simgear/package/CatalogTest.cxx @@ -15,9 +15,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include @@ -98,6 +96,11 @@ public: path = "/catalogTest1/movies-data.zip"; } + if (path == "/catalogTest1/b747.tar.gz") { + sendErrorResponse(403, false, "Bad URL"); + return; + } + localPath.append(path); // SG_LOG(SG_IO, SG_INFO, "local path is:" << localPath.str()); @@ -158,7 +161,7 @@ int parseTest() SG_CHECK_EQUAL(cat->description(), "First test catalog"); // check the packages too - SG_CHECK_EQUAL(cat->packages().size(), 5); + SG_CHECK_EQUAL(cat->packages().size(), 6); pkg::PackageRef p1 = cat->packages().front(); SG_CHECK_EQUAL(p1->catalog(), cat.ptr()); @@ -349,7 +352,7 @@ void testAddCatalog(HTTP::Client* cl) p.append("org.flightgear.test.catalog1"); p.append("catalog.xml"); SG_VERIFY(p.exists()); - SG_CHECK_EQUAL(root->allPackages().size(), 5); + SG_CHECK_EQUAL(root->allPackages().size(), 6); SG_CHECK_EQUAL(root->catalogs().size(), 1); pkg::PackageRef p1 = root->getPackageById("alpha"); @@ -383,6 +386,7 @@ void testInstallPackage(HTTP::Client* cl) waitForUpdateComplete(cl, root); SG_VERIFY(p1->isInstalled()); SG_VERIFY(p1->existingInstall() == ins); + SG_CHECK_EQUAL(ins->status(), pkg::Delegate::STATUS_SUCCESS); pkg::PackageRef commonDeps = root->getPackageById("common-sounds"); SG_VERIFY(commonDeps->existingInstall()); @@ -428,6 +432,7 @@ void testUninstall(HTTP::Client* cl) ins->uninstall(); + SG_CHECK_EQUAL(ins->status(), pkg::Delegate::STATUS_SUCCESS); SG_VERIFY(!ins->path().exists()); } @@ -1075,9 +1080,45 @@ void updateInvalidToInvalid(HTTP::Client* cl) } +void testInstallBadPackage(HTTP::Client* cl) +{ + global_catalogVersion = 0; + + SGPath rootPath(simgear::Dir::current().path()); + rootPath.append("pkg_install_bad_pkg"); + simgear::Dir pd(rootPath); + pd.removeChildren(); + + pkg::RootRef root(new pkg::Root(rootPath, "8.1.2")); + // specify a test dir + root->setHTTPClient(cl); + + pkg::CatalogRef c = pkg::Catalog::createFromUrl(root.ptr(), "http://localhost:2000/catalogTest1/catalog.xml"); + waitForUpdateComplete(cl, root); + + pkg::PackageRef p1 = root->getPackageById("org.flightgear.test.catalog1.b747-400"); + pkg::InstallRef ins = p1->install(); + + bool didFail = false; + ins->fail([&didFail, &ins](pkg::Install* ourInstall) { + SG_CHECK_EQUAL(ins, ourInstall); + didFail = true; + }); + + SG_VERIFY(ins->isQueued()); + + waitForUpdateComplete(cl, root); + SG_VERIFY(!p1->isInstalled()); + SG_VERIFY(didFail); + SG_VERIFY(p1->existingInstall() == ins); + SG_CHECK_EQUAL(ins->status(), pkg::Delegate::FAIL_DOWNLOAD); + SG_CHECK_EQUAL(ins->path(), rootPath / "org.flightgear.test.catalog1" / "Aircraft" / "b744"); +} + + int main(int argc, char* argv[]) { - sglog().setLogLevels( SG_ALL, SG_DEBUG ); + // sglog().setLogLevels( SG_ALL, SG_DEBUG ); HTTP::Client cl; cl.setMaxConnections(1); @@ -1116,6 +1157,8 @@ int main(int argc, char* argv[]) testVersionMigrateToId(&cl); + testInstallBadPackage(&cl); + SG_LOG(SG_GENERAL, SG_INFO, "Successfully passed all tests!"); return EXIT_SUCCESS; } diff --git a/simgear/package/Install.cxx b/simgear/package/Install.cxx index 85f8b708..8ab574c9 100644 --- a/simgear/package/Install.cxx +++ b/simgear/package/Install.cxx @@ -108,6 +108,8 @@ protected: m_extractor.reset(new ArchiveExtractor(m_extractPath)); memset(&m_md5, 0, sizeof(SG_MD5_CTX)); SG_MD5Init(&m_md5); + + m_owner->startDownload(); } virtual void gotBodyData(const char* s, int n) @@ -395,6 +397,7 @@ Install* Install::progress(const ProgressCallback& cb) //------------------------------------------------------------------------------ void Install::installResult(Delegate::StatusCode aReason) { + m_status = aReason; m_package->catalog()->root()->finishInstall(this, aReason); if (aReason == Delegate::STATUS_SUCCESS) { _cb_done(this); @@ -412,6 +415,15 @@ void Install::installProgress(unsigned int aBytes, unsigned int aTotal) _cb_progress(this, aBytes, aTotal); } +void Install::startDownload() +{ + m_status = Delegate::STATUS_IN_PROGRESS; +} + +Delegate::StatusCode Install::status() const +{ + return m_status; +} } // of namespace pkg diff --git a/simgear/package/Install.hxx b/simgear/package/Install.hxx index fd4e5d8c..268564eb 100644 --- a/simgear/package/Install.hxx +++ b/simgear/package/Install.hxx @@ -86,6 +86,8 @@ public: size_t downloadedBytes() const; + Delegate::StatusCode status() const; + /** * full path to the primary -set.xml file for this install */ @@ -169,6 +171,7 @@ private: void installResult(Delegate::StatusCode aReason); void installProgress(unsigned int aBytes, unsigned int aTotal); + void startDownload(); PackageRef m_package; unsigned int m_revision; ///< revision on disk diff --git a/simgear/package/catalogTest1/catalog.xml b/simgear/package/catalogTest1/catalog.xml index e16b3ec2..97d03aec 100644 --- a/simgear/package/catalogTest1/catalog.xml +++ b/simgear/package/catalogTest1/catalog.xml @@ -194,6 +194,32 @@ http://localhost:2000/catalogTest1/b737.tar.gz + + b747-400 + Boeing 747-400 + b744 + A popular four-engined wide-body jet + 111 + 860 + + boeing + jet + ifr + + + + + 5 + 5 + 4 + 4 + + + a94ca5704f305b90767f40617d194ed6 + + http://localhost:2000/catalogTest1/b747.tar.gz + + common-sounds Common sound files for test catalog aircraft