From 0b9cd83642f297687989b0813a9dca83cc78cc15 Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Mon, 25 Oct 2010 14:53:58 -0700 Subject: CHOP-122 Adding stub background updater files to the build. Rev. by brad --- indra/viewer_components/CMakeLists.txt | 2 +- indra/viewer_components/updater/CMakeLists.txt | 51 +++++++++++++++++++ .../viewer_components/updater/llupdaterservice.cpp | 58 +++++++++++++++++++++ indra/viewer_components/updater/llupdaterservice.h | 46 +++++++++++++++++ .../updater/tests/llupdaterservice_test.cpp | 59 ++++++++++++++++++++++ 5 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 indra/viewer_components/updater/CMakeLists.txt create mode 100644 indra/viewer_components/updater/llupdaterservice.cpp create mode 100644 indra/viewer_components/updater/llupdaterservice.h create mode 100644 indra/viewer_components/updater/tests/llupdaterservice_test.cpp (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/CMakeLists.txt b/indra/viewer_components/CMakeLists.txt index 0993b64b14..74c9b4568d 100644 --- a/indra/viewer_components/CMakeLists.txt +++ b/indra/viewer_components/CMakeLists.txt @@ -1,4 +1,4 @@ # -*- cmake -*- add_subdirectory(login) - +add_subdirectory(updater) diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt new file mode 100644 index 0000000000..4dc5424142 --- /dev/null +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -0,0 +1,51 @@ +# -*- cmake -*- + +project(updater_service) + +include(00-Common) +if(LL_TESTS) + include(LLAddBuildTest) +endif(LL_TESTS) +include(LLCommon) + +include_directories( + ${LLCOMMON_INCLUDE_DIRS} + ) + +set(updater_service_SOURCE_FILES + llupdaterservice.cpp + ) + +set(updater_service_HEADER_FILES + llupdaterservice.h + ) + +set_source_files_properties(${updater_service_HEADER_FILES} + PROPERTIES HEADER_FILE_ONLY TRUE) + +list(APPEND + updater_service_SOURCE_FILES + ${updater_service_HEADER_FILES} + ) + +add_library(llupdaterservice + ${updater_service_SOURCE_FILES} + ) + +target_link_libraries(llupdaterservice + ${LLCOMMON_LIBRARIES} + ) + +if(LL_TESTS) + SET(llupdater_service_TEST_SOURCE_FILES + llupdaterservice.cpp + ) + +# set_source_files_properties( +# llupdaterservice.cpp +# PROPERTIES +# LL_TEST_ADDITIONAL_LIBRARIES "${PTH_LIBRARIES}" +# ) + + LL_ADD_PROJECT_UNIT_TESTS(llupdaterservice "${llupdater_service_TEST_SOURCE_FILES}") +endif(LL_TESTS) diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp new file mode 100644 index 0000000000..14906bcef8 --- /dev/null +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -0,0 +1,58 @@ +/** + * @file llupdaterservice.cpp + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +LLUpdaterService::LLUpdaterService() +{ +} + +LLUpdaterService::~LLUpdaterService() +{ +} + +void LLUpdaterService::setURL(const std::string& url) +{ +} + +void LLUpdaterService::setChannel(const std::string& channel) +{ +} + +void LLUpdaterService::setVersion(const std::string& version) +{ +} + +void LLUpdaterService::setUpdateCheckFrequency(unsigned int seconds) +{ +} + +void LLUpdaterService::startChecking() +{ +} + +void LLUpdaterService::stopChecking() +{ +} diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h new file mode 100644 index 0000000000..7836c2cf7f --- /dev/null +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -0,0 +1,46 @@ +/** + * @file llupdaterservice.h + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_UPDATERSERVICE_H +#define LL_UPDATERSERVICE_H + +class LLUpdaterService +{ + LLUpdaterService(); + ~LLUpdaterService(); + + // The base URL. + // *NOTE:Mani The grid, if any, would be embedded in the base URL. + void setURL(const std::string& url); + void setChannel(const std::string& channel); + void setVersion(const std::string& version); + + void setUpdateCheckFrequency(unsigned int seconds); + + void startChecking(); + void stopChecking(); +} + +#endif LL_UPDATERSERVICE_H diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp new file mode 100644 index 0000000000..37d1c8243e --- /dev/null +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -0,0 +1,59 @@ +/** + * @file llupdaterservice_test.cpp + * @brief Tests of llupdaterservice.cpp. + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// Precompiled header +#include "linden_common.h" +// associated header +#include "../llupdaterservice.h" + +#include "../../../test/lltut.h" +//#define DEBUG_ON +#include "../../../test/debug.h" + +/***************************************************************************** +* TUT +*****************************************************************************/ +namespace tut +{ + struct llupdaterservice_data + { + llupdaterservice_data() : + pumps(LLEventPumps::instance()) + {} + LLEventPumps& pumps; + }; + + typedef test_group llupdaterservice_group; + typedef llviewerlogin_group::object llupdaterservice_object; + llupdaterservice_group llupdaterservicegrp("LLUpdaterService"); + + template<> template<> + void llupdateservice_object::test<1>() + { + DEBUG; + ensure_equals("Dummy", "true", "true"); + } +} -- cgit v1.2.3 From 34db27c26f9a5627b733cc8a04265afed68d199c Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Tue, 26 Oct 2010 15:00:34 -0700 Subject: CHOP-122 Mowr work on the llupdater facade... Added LLPluginProcessParent, including mockery for unit tests. Re. by Jenn --- indra/viewer_components/updater/CMakeLists.txt | 6 ++ .../viewer_components/updater/llupdaterservice.cpp | 120 ++++++++++++++++++++- indra/viewer_components/updater/llupdaterservice.h | 10 +- .../updater/tests/llupdaterservice_test.cpp | 28 ++++- 4 files changed, 158 insertions(+), 6 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index 4dc5424142..df9404474c 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -7,9 +7,13 @@ if(LL_TESTS) include(LLAddBuildTest) endif(LL_TESTS) include(LLCommon) +include(LLMessage) +include(LLPlugin) include_directories( ${LLCOMMON_INCLUDE_DIRS} + ${LLMESSAGE_INCLUDE_DIRS} + ${LLPLUGIN_INCLUDE_DIRS} ) set(updater_service_SOURCE_FILES @@ -34,6 +38,8 @@ add_library(llupdaterservice target_link_libraries(llupdaterservice ${LLCOMMON_LIBRARIES} + ${LLMESSAGE_LIBRARIES} + ${LLPLUGIN_LIBRARIES} ) if(LL_TESTS) diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 14906bcef8..6c7619a2b9 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -25,6 +25,118 @@ #include "linden_common.h" +#include "llupdaterservice.h" + +#include "llsingleton.h" +#include "llpluginprocessparent.h" +#include + +class LLUpdaterServiceImpl : public LLPluginProcessParentOwner, + public LLSingleton +{ + std::string mUrl; + std::string mChannel; + std::string mVersion; + + unsigned int mUpdateCheckPeriod; + bool mIsChecking; + boost::scoped_ptr mPlugin; + +public: + LLUpdaterServiceImpl(); + virtual ~LLUpdaterServiceImpl() {} + + // LLPluginProcessParentOwner interfaces + virtual void receivePluginMessage(const LLPluginMessage &message); + virtual bool receivePluginMessageEarly(const LLPluginMessage &message); + virtual void pluginLaunchFailed(); + virtual void pluginDied(); + + void setURL(const std::string& url); + void setChannel(const std::string& channel); + void setVersion(const std::string& version); + void setUpdateCheckPeriod(unsigned int seconds); + void startChecking(); + void stopChecking(); +}; + +LLUpdaterServiceImpl::LLUpdaterServiceImpl() : + mIsChecking(false), + mUpdateCheckPeriod(0), + mPlugin(0) +{ + // Create the plugin parent, this is the owner. + mPlugin.reset(new LLPluginProcessParent(this)); +} + +// LLPluginProcessParentOwner interfaces +void LLUpdaterServiceImpl::receivePluginMessage(const LLPluginMessage &message) +{ +} + +bool LLUpdaterServiceImpl::receivePluginMessageEarly(const LLPluginMessage &message) +{ + return false; +}; + +void LLUpdaterServiceImpl::pluginLaunchFailed() +{ +}; + +void LLUpdaterServiceImpl::pluginDied() +{ +}; + +void LLUpdaterServiceImpl::setURL(const std::string& url) +{ + if(mUrl != url) + { + mUrl = url; + } +} + +void LLUpdaterServiceImpl::setChannel(const std::string& channel) +{ + if(mChannel != channel) + { + mChannel = channel; + } +} + +void LLUpdaterServiceImpl::setVersion(const std::string& version) +{ + if(mVersion != version) + { + mVersion = version; + } +} + +void LLUpdaterServiceImpl::setUpdateCheckPeriod(unsigned int seconds) +{ + if(mUpdateCheckPeriod != seconds) + { + mUpdateCheckPeriod = seconds; + } +} + +void LLUpdaterServiceImpl::startChecking() +{ + if(!mIsChecking) + { + mIsChecking = true; + } +} + +void LLUpdaterServiceImpl::stopChecking() +{ + if(mIsChecking) + { + mIsChecking = false; + } +} + +//----------------------------------------------------------------------- +// Facade interface LLUpdaterService::LLUpdaterService() { } @@ -35,24 +147,30 @@ LLUpdaterService::~LLUpdaterService() void LLUpdaterService::setURL(const std::string& url) { + LLUpdaterServiceImpl::getInstance()->setURL(url); } void LLUpdaterService::setChannel(const std::string& channel) { + LLUpdaterServiceImpl::getInstance()->setChannel(channel); } void LLUpdaterService::setVersion(const std::string& version) { + LLUpdaterServiceImpl::getInstance()->setVersion(version); } -void LLUpdaterService::setUpdateCheckFrequency(unsigned int seconds) +void LLUpdaterService::setUpdateCheckPeriod(unsigned int seconds) { + LLUpdaterServiceImpl::getInstance()->setUpdateCheckPeriod(seconds); } void LLUpdaterService::startChecking() { + LLUpdaterServiceImpl::getInstance()->startChecking(); } void LLUpdaterService::stopChecking() { + LLUpdaterServiceImpl::getInstance()->stopChecking(); } diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 7836c2cf7f..33d0dc0816 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -28,6 +28,12 @@ class LLUpdaterService { +public: + class UsageError: public std::runtime_error + { + UsageError(const std::string& msg) : std::runtime_error(msg) {} + }; + LLUpdaterService(); ~LLUpdaterService(); @@ -37,10 +43,10 @@ class LLUpdaterService void setChannel(const std::string& channel); void setVersion(const std::string& version); - void setUpdateCheckFrequency(unsigned int seconds); + void setUpdateCheckPeriod(unsigned int seconds); void startChecking(); void stopChecking(); -} +}; #endif LL_UPDATERSERVICE_H diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 37d1c8243e..9edf15ba11 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -33,6 +33,28 @@ //#define DEBUG_ON #include "../../../test/debug.h" +#include "llevents.h" +#include "llpluginprocessparent.h" + +/***************************************************************************** +* MOCK'd +*****************************************************************************/ +LLPluginProcessParentOwner::~LLPluginProcessParentOwner() {} +LLPluginProcessParent::LLPluginProcessParent(LLPluginProcessParentOwner *owner) +: mOwner(owner), + mIncomingQueueMutex(NULL) +{ +} + +LLPluginProcessParent::~LLPluginProcessParent() {} +LLPluginMessagePipeOwner::LLPluginMessagePipeOwner(){} +LLPluginMessagePipeOwner::~LLPluginMessagePipeOwner(){} +void LLPluginProcessParent::receiveMessageRaw(const std::string &message) {} +int LLPluginMessagePipeOwner::socketError(int) { return 0; } +void LLPluginProcessParent::setMessagePipe(LLPluginMessagePipe *message_pipe) {} +void LLPluginMessagePipeOwner::setMessagePipe(class LLPluginMessagePipe *) {} +LLPluginMessage::~LLPluginMessage() {} + /***************************************************************************** * TUT *****************************************************************************/ @@ -47,13 +69,13 @@ namespace tut }; typedef test_group llupdaterservice_group; - typedef llviewerlogin_group::object llupdaterservice_object; + typedef llupdaterservice_group::object llupdaterservice_object; llupdaterservice_group llupdaterservicegrp("LLUpdaterService"); template<> template<> - void llupdateservice_object::test<1>() + void llupdaterservice_object::test<1>() { DEBUG; - ensure_equals("Dummy", "true", "true"); + ensure_equals("Dummy", 0, 0); } } -- cgit v1.2.3 From be8c9fc21758bcbc1d9f3d565b221310344231bd Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Wed, 27 Oct 2010 17:07:31 -0700 Subject: CHOP-122 Initializing Facade service in the viewer. Rev. by Brad. --- indra/viewer_components/updater/CMakeLists.txt | 10 ++ .../viewer_components/updater/llupdaterservice.cpp | 107 +++++------ indra/viewer_components/updater/llupdaterservice.h | 19 +- .../updater/tests/llupdaterservice_test.cpp | 195 +++++++++++++-------- 4 files changed, 203 insertions(+), 128 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index df9404474c..a8a1d685f7 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -55,3 +55,13 @@ if(LL_TESTS) LL_ADD_PROJECT_UNIT_TESTS(llupdaterservice "${llupdater_service_TEST_SOURCE_FILES}") endif(LL_TESTS) + +set(UPDATER_INCLUDE_DIRS + ${LIBS_OPEN_DIR}/viewer_components/updater + CACHE INTERNAL "" +) + +set(UPDATER_LIBRARIES + llupdaterservice + CACHE INTERNAL "" +) diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 6c7619a2b9..28c942b5f2 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -27,18 +27,19 @@ #include "llupdaterservice.h" -#include "llsingleton.h" #include "llpluginprocessparent.h" #include +#include -class LLUpdaterServiceImpl : public LLPluginProcessParentOwner, - public LLSingleton +boost::weak_ptr gUpdater; + +class LLUpdaterServiceImpl : public LLPluginProcessParentOwner { std::string mUrl; std::string mChannel; std::string mVersion; - unsigned int mUpdateCheckPeriod; + unsigned int mCheckPeriod; bool mIsChecking; boost::scoped_ptr mPlugin; @@ -52,17 +53,20 @@ public: virtual void pluginLaunchFailed(); virtual void pluginDied(); - void setURL(const std::string& url); - void setChannel(const std::string& channel); - void setVersion(const std::string& version); - void setUpdateCheckPeriod(unsigned int seconds); + void setParams(const std::string& url, + const std::string& channel, + const std::string& version); + + void setCheckPeriod(unsigned int seconds); + void startChecking(); void stopChecking(); + bool isChecking(); }; LLUpdaterServiceImpl::LLUpdaterServiceImpl() : mIsChecking(false), - mUpdateCheckPeriod(0), + mCheckPeriod(0), mPlugin(0) { // Create the plugin parent, this is the owner. @@ -87,42 +91,35 @@ void LLUpdaterServiceImpl::pluginDied() { }; -void LLUpdaterServiceImpl::setURL(const std::string& url) -{ - if(mUrl != url) - { - mUrl = url; - } -} - -void LLUpdaterServiceImpl::setChannel(const std::string& channel) +void LLUpdaterServiceImpl::setParams(const std::string& url, + const std::string& channel, + const std::string& version) { - if(mChannel != channel) - { - mChannel = channel; - } -} - -void LLUpdaterServiceImpl::setVersion(const std::string& version) -{ - if(mVersion != version) + if(mIsChecking) { - mVersion = version; + throw LLUpdaterService::UsageError("Call LLUpdaterService::stopCheck()" + " before setting params."); } + + mUrl = url; + mChannel = channel; + mVersion = version; } -void LLUpdaterServiceImpl::setUpdateCheckPeriod(unsigned int seconds) +void LLUpdaterServiceImpl::setCheckPeriod(unsigned int seconds) { - if(mUpdateCheckPeriod != seconds) - { - mUpdateCheckPeriod = seconds; - } + mCheckPeriod = seconds; } void LLUpdaterServiceImpl::startChecking() { if(!mIsChecking) { + if(mUrl.empty() || mChannel.empty() || mVersion.empty()) + { + throw LLUpdaterService::UsageError("Set params before call to " + "LLUpdaterService::startCheck()."); + } mIsChecking = true; } } @@ -135,42 +132,54 @@ void LLUpdaterServiceImpl::stopChecking() } } +bool LLUpdaterServiceImpl::isChecking() +{ + return mIsChecking; +} + //----------------------------------------------------------------------- // Facade interface LLUpdaterService::LLUpdaterService() { + if(gUpdater.expired()) + { + mImpl = + boost::shared_ptr(new LLUpdaterServiceImpl()); + gUpdater = mImpl; + } + else + { + mImpl = gUpdater.lock(); + } } LLUpdaterService::~LLUpdaterService() { } -void LLUpdaterService::setURL(const std::string& url) -{ - LLUpdaterServiceImpl::getInstance()->setURL(url); -} - -void LLUpdaterService::setChannel(const std::string& channel) +void LLUpdaterService::setParams(const std::string& url, + const std::string& chan, + const std::string& vers) { - LLUpdaterServiceImpl::getInstance()->setChannel(channel); + mImpl->setParams(url, chan, vers); } -void LLUpdaterService::setVersion(const std::string& version) -{ - LLUpdaterServiceImpl::getInstance()->setVersion(version); -} - -void LLUpdaterService::setUpdateCheckPeriod(unsigned int seconds) +void LLUpdaterService::setCheckPeriod(unsigned int seconds) { - LLUpdaterServiceImpl::getInstance()->setUpdateCheckPeriod(seconds); + mImpl->setCheckPeriod(seconds); } void LLUpdaterService::startChecking() { - LLUpdaterServiceImpl::getInstance()->startChecking(); + mImpl->startChecking(); } void LLUpdaterService::stopChecking() { - LLUpdaterServiceImpl::getInstance()->stopChecking(); + mImpl->stopChecking(); +} + +bool LLUpdaterService::isChecking() +{ + return mImpl->isChecking(); } diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 33d0dc0816..6459ca49f8 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -26,11 +26,16 @@ #ifndef LL_UPDATERSERVICE_H #define LL_UPDATERSERVICE_H +#include + +class LLUpdaterServiceImpl; + class LLUpdaterService { public: class UsageError: public std::runtime_error { + public: UsageError(const std::string& msg) : std::runtime_error(msg) {} }; @@ -39,14 +44,18 @@ public: // The base URL. // *NOTE:Mani The grid, if any, would be embedded in the base URL. - void setURL(const std::string& url); - void setChannel(const std::string& channel); - void setVersion(const std::string& version); - - void setUpdateCheckPeriod(unsigned int seconds); + void setParams(const std::string& url, + const std::string& channel, + const std::string& version); + + void setCheckPeriod(unsigned int seconds); void startChecking(); void stopChecking(); + bool isChecking(); + +private: + boost::shared_ptr mImpl; }; #endif LL_UPDATERSERVICE_H diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 9edf15ba11..73cf6ea6eb 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -1,50 +1,50 @@ -/** - * @file llupdaterservice_test.cpp - * @brief Tests of llupdaterservice.cpp. - * - * $LicenseInfo:firstyear=2010&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -// Precompiled header -#include "linden_common.h" -// associated header -#include "../llupdaterservice.h" - -#include "../../../test/lltut.h" -//#define DEBUG_ON -#include "../../../test/debug.h" - -#include "llevents.h" -#include "llpluginprocessparent.h" - -/***************************************************************************** -* MOCK'd -*****************************************************************************/ -LLPluginProcessParentOwner::~LLPluginProcessParentOwner() {} -LLPluginProcessParent::LLPluginProcessParent(LLPluginProcessParentOwner *owner) -: mOwner(owner), - mIncomingQueueMutex(NULL) -{ -} +/** + * @file llupdaterservice_test.cpp + * @brief Tests of llupdaterservice.cpp. + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// Precompiled header +#include "linden_common.h" +// associated header +#include "../llupdaterservice.h" + +#include "../../../test/lltut.h" +//#define DEBUG_ON +#include "../../../test/debug.h" + +#include "llevents.h" +#include "llpluginprocessparent.h" + +/***************************************************************************** +* MOCK'd +*****************************************************************************/ +LLPluginProcessParentOwner::~LLPluginProcessParentOwner() {} +LLPluginProcessParent::LLPluginProcessParent(LLPluginProcessParentOwner *owner) +: mOwner(owner), + mIncomingQueueMutex(gAPRPoolp) +{ +} LLPluginProcessParent::~LLPluginProcessParent() {} LLPluginMessagePipeOwner::LLPluginMessagePipeOwner(){} @@ -52,30 +52,77 @@ LLPluginMessagePipeOwner::~LLPluginMessagePipeOwner(){} void LLPluginProcessParent::receiveMessageRaw(const std::string &message) {} int LLPluginMessagePipeOwner::socketError(int) { return 0; } void LLPluginProcessParent::setMessagePipe(LLPluginMessagePipe *message_pipe) {} -void LLPluginMessagePipeOwner::setMessagePipe(class LLPluginMessagePipe *) {} -LLPluginMessage::~LLPluginMessage() {} - -/***************************************************************************** -* TUT -*****************************************************************************/ -namespace tut -{ - struct llupdaterservice_data - { - llupdaterservice_data() : - pumps(LLEventPumps::instance()) - {} - LLEventPumps& pumps; - }; - - typedef test_group llupdaterservice_group; - typedef llupdaterservice_group::object llupdaterservice_object; - llupdaterservice_group llupdaterservicegrp("LLUpdaterService"); - - template<> template<> - void llupdaterservice_object::test<1>() - { - DEBUG; - ensure_equals("Dummy", 0, 0); - } -} +void LLPluginMessagePipeOwner::setMessagePipe(class LLPluginMessagePipe *) {} +LLPluginMessage::~LLPluginMessage() {} + +/***************************************************************************** +* TUT +*****************************************************************************/ +namespace tut +{ + struct llupdaterservice_data + { + llupdaterservice_data() : + pumps(LLEventPumps::instance()), + test_url("dummy_url"), + test_channel("dummy_channel"), + test_version("dummy_version") + {} + LLEventPumps& pumps; + std::string test_url; + std::string test_channel; + std::string test_version; + }; + + typedef test_group llupdaterservice_group; + typedef llupdaterservice_group::object llupdaterservice_object; + llupdaterservice_group llupdaterservicegrp("LLUpdaterService"); + + template<> template<> + void llupdaterservice_object::test<1>() + { + DEBUG; + LLUpdaterService updater; + bool got_usage_error = false; + try + { + updater.startChecking(); + } + catch(LLUpdaterService::UsageError) + { + got_usage_error = true; + } + ensure("Caught start before params", got_usage_error); + } + + template<> template<> + void llupdaterservice_object::test<2>() + { + DEBUG; + LLUpdaterService updater; + bool got_usage_error = false; + try + { + updater.setParams(test_url, test_channel, test_version); + updater.startChecking(); + updater.setParams("other_url", test_channel, test_version); + } + catch(LLUpdaterService::UsageError) + { + got_usage_error = true; + } + ensure("Caught params while running", got_usage_error); + } + + template<> template<> + void llupdaterservice_object::test<3>() + { + DEBUG; + LLUpdaterService updater; + updater.setParams(test_url, test_channel, test_version); + updater.startChecking(); + ensure(updater.isChecking()); + updater.stopChecking(); + ensure(!updater.isChecking()); + } +} -- cgit v1.2.3 From ca9594af28ce2e1cc8bb333a0fa7384dae718a9a Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 28 Oct 2010 16:47:05 -0700 Subject: shell of the update checker; it will just print a message to the log depending on the result of the check one time. --- indra/viewer_components/updater/CMakeLists.txt | 2 + .../viewer_components/updater/llupdatechecker.cpp | 131 +++++++++++++++++++++ indra/viewer_components/updater/llupdatechecker.h | 69 +++++++++++ .../viewer_components/updater/llupdaterservice.cpp | 31 ++++- .../updater/tests/llupdaterservice_test.cpp | 6 + 5 files changed, 236 insertions(+), 3 deletions(-) create mode 100644 indra/viewer_components/updater/llupdatechecker.cpp create mode 100644 indra/viewer_components/updater/llupdatechecker.h (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index a8a1d685f7..2e77a7140a 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -18,10 +18,12 @@ include_directories( set(updater_service_SOURCE_FILES llupdaterservice.cpp + llupdatechecker.cpp ) set(updater_service_HEADER_FILES llupdaterservice.h + llupdatechecker.h ) set_source_files_properties(${updater_service_HEADER_FILES} diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp new file mode 100644 index 0000000000..a19b8be607 --- /dev/null +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -0,0 +1,131 @@ +/** + * @file llupdaterservice.cpp + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" +#include +#include "llhttpclient.h" +#include "llupdatechecker.h" + + +class LLUpdateChecker::Implementation: + public LLHTTPClient::Responder +{ +public: + + Implementation(Client & client); + void check(std::string const & host, std::string channel, std::string version); + + // Responder: + virtual void completed(U32 status, + const std::string & reason, + const LLSD& content); + virtual void error(U32 status, const std::string & reason); + +private: + std::string buildUrl(std::string const & host, std::string channel, std::string version); + + Client & mClient; + LLHTTPClient mHttpClient; + bool mInProgress; + std::string mVersion; + + LOG_CLASS(LLUpdateChecker::Implementation); +}; + + + +// LLUpdateChecker +//----------------------------------------------------------------------------- + + +LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client): + mImplementation(new LLUpdateChecker::Implementation(client)) +{ + ; // No op. +} + + +void LLUpdateChecker::check(std::string const & host, std::string channel, std::string version) +{ + mImplementation->check(host, channel, version); +} + + + +// LLUpdateChecker::Implementation +//----------------------------------------------------------------------------- + + +LLUpdateChecker::Implementation::Implementation(LLUpdateChecker::Client & client): + mClient(client), + mInProgress(false) +{ + ; // No op. +} + + +void LLUpdateChecker::Implementation::check(std::string const & host, std::string channel, std::string version) +{ + llassert(!mInProgress); + + mInProgress = true; + mVersion = version; + std::string checkUrl = buildUrl(host, channel, version); + LL_INFOS("UpdateCheck") << "checking for updates at " << checkUrl << llendl; + mHttpClient.get(checkUrl, this); +} + +void LLUpdateChecker::Implementation::completed(U32 status, + const std::string & reason, + const LLSD & content) +{ + mInProgress = false; + + if(status != 200) { + LL_WARNS("UpdateCheck") << "html error " << status << " (" << reason << ")" << llendl; + } else if(!content["valid"].asBoolean()) { + LL_INFOS("UpdateCheck") << "version invalid" << llendl; + } else if(content["latest_version"].asString() != mVersion) { + LL_INFOS("UpdateCheck") << "newer version " << content["latest_version"].asString() << " available" << llendl; + } else { + LL_INFOS("UpdateCheck") << "up to date" << llendl; + } +} + + +void LLUpdateChecker::Implementation::error(U32 status, const std::string & reason) +{ + mInProgress = false; + LL_WARNS("UpdateCheck") << "update check failed; " << reason << llendl; +} + + +std::string LLUpdateChecker::Implementation::buildUrl(std::string const & host, std::string channel, std::string version) +{ + static boost::format urlFormat("%s/version/%s/%s"); + urlFormat % host % channel % version; + return urlFormat.str(); +} + diff --git a/indra/viewer_components/updater/llupdatechecker.h b/indra/viewer_components/updater/llupdatechecker.h new file mode 100644 index 0000000000..d2ec848e14 --- /dev/null +++ b/indra/viewer_components/updater/llupdatechecker.h @@ -0,0 +1,69 @@ +/** + * @file llupdatechecker.h + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_UPDATERCHECKER_H +#define LL_UPDATERCHECKER_H + + +#include + + +// +// Implements asynchronous checking for updates. +// +class LLUpdateChecker { +public: + class Client; + class Implementation; + + LLUpdateChecker(Client & client); + + // Check status of current app on the given host for the channel and version provided. + void check(std::string const & hostUrl, std::string channel, std::string version); +private: + boost::shared_ptr mImplementation; +}; + + +// +// The client interface implemented by a requestor checking for an update. +// +class LLUpdateChecker::Client +{ + // An error occurred while checking for an update. + virtual void error(std::string const & message) = 0; + + // A newer version is available, but the current version may still be used. + virtual void optionalUpdate(std::string const & newVersion) = 0; + + // A newer version is available, and the current version is no longer valid. + virtual void requiredUpdate(std::string const & newVersion) = 0; + + // The checked version is up to date; no newer version exists. + virtual void upToDate(void) = 0; +}; + + +#endif diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 28c942b5f2..e0f23722dd 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -26,6 +26,7 @@ #include "linden_common.h" #include "llupdaterservice.h" +#include "llupdatechecker.h" #include "llpluginprocessparent.h" #include @@ -33,7 +34,9 @@ boost::weak_ptr gUpdater; -class LLUpdaterServiceImpl : public LLPluginProcessParentOwner +class LLUpdaterServiceImpl : + public LLPluginProcessParentOwner, + public LLUpdateChecker::Client { std::string mUrl; std::string mChannel; @@ -42,7 +45,9 @@ class LLUpdaterServiceImpl : public LLPluginProcessParentOwner unsigned int mCheckPeriod; bool mIsChecking; boost::scoped_ptr mPlugin; - + + LLUpdateChecker mUpdateChecker; + public: LLUpdaterServiceImpl(); virtual ~LLUpdaterServiceImpl() {} @@ -62,12 +67,21 @@ public: void startChecking(); void stopChecking(); bool isChecking(); + + // LLUpdateChecker::Client: + virtual void error(std::string const & message); + virtual void optionalUpdate(std::string const & newVersion); + virtual void requiredUpdate(std::string const & newVersion); + virtual void upToDate(void); + }; + LLUpdaterServiceImpl::LLUpdaterServiceImpl() : mIsChecking(false), mCheckPeriod(0), - mPlugin(0) + mPlugin(0), + mUpdateChecker(*this) { // Create the plugin parent, this is the owner. mPlugin.reset(new LLPluginProcessParent(this)); @@ -121,6 +135,8 @@ void LLUpdaterServiceImpl::startChecking() "LLUpdaterService::startCheck()."); } mIsChecking = true; + + mUpdateChecker.check(mUrl, mChannel, mVersion); } } @@ -137,6 +153,15 @@ bool LLUpdaterServiceImpl::isChecking() return mIsChecking; } +void LLUpdaterServiceImpl::error(std::string const & message) {} + +void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion) {} + +void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion) {} + +void LLUpdaterServiceImpl::upToDate(void) {} + + //----------------------------------------------------------------------- // Facade interface LLUpdaterService::LLUpdaterService() diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 73cf6ea6eb..d93a85cf7d 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -28,6 +28,7 @@ #include "linden_common.h" // associated header #include "../llupdaterservice.h" +#include "../llupdatechecker.h" #include "../../../test/lltut.h" //#define DEBUG_ON @@ -54,6 +55,11 @@ int LLPluginMessagePipeOwner::socketError(int) { return 0; } void LLPluginProcessParent::setMessagePipe(LLPluginMessagePipe *message_pipe) {} void LLPluginMessagePipeOwner::setMessagePipe(class LLPluginMessagePipe *) {} LLPluginMessage::~LLPluginMessage() {} +LLPluginMessage::LLPluginMessage(LLPluginMessage const&) {} + +LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client) +{} +void LLUpdateChecker::check(std::string const & host, std::string channel, std::string version){} /***************************************************************************** * TUT -- cgit v1.2.3 From 609f5bd6810ca16a409f209610e6fac972348cba Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Fri, 29 Oct 2010 11:20:54 -0700 Subject: added periodic retry to look for updates --- .../viewer_components/updater/llupdatechecker.cpp | 19 +++++-- indra/viewer_components/updater/llupdatechecker.h | 2 + .../viewer_components/updater/llupdaterservice.cpp | 63 ++++++++++++++++++++-- 3 files changed, 76 insertions(+), 8 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index a19b8be607..ca2959a4ac 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -35,6 +35,7 @@ class LLUpdateChecker::Implementation: public: Implementation(Client & client); + ~Implementation(); void check(std::string const & host, std::string channel, std::string version); // Responder: @@ -49,6 +50,7 @@ private: Client & mClient; LLHTTPClient mHttpClient; bool mInProgress; + LLHTTPClient::ResponderPtr mMe; std::string mVersion; LOG_CLASS(LLUpdateChecker::Implementation); @@ -80,21 +82,28 @@ void LLUpdateChecker::check(std::string const & host, std::string channel, std:: LLUpdateChecker::Implementation::Implementation(LLUpdateChecker::Client & client): mClient(client), - mInProgress(false) + mInProgress(false), + mMe(this) { ; // No op. } +LLUpdateChecker::Implementation::~Implementation() +{ + mMe.reset(0); +} + + void LLUpdateChecker::Implementation::check(std::string const & host, std::string channel, std::string version) { - llassert(!mInProgress); + // llassert(!mInProgress); mInProgress = true; mVersion = version; std::string checkUrl = buildUrl(host, channel, version); LL_INFOS("UpdateCheck") << "checking for updates at " << checkUrl << llendl; - mHttpClient.get(checkUrl, this); + mHttpClient.get(checkUrl, mMe); } void LLUpdateChecker::Implementation::completed(U32 status, @@ -105,12 +114,16 @@ void LLUpdateChecker::Implementation::completed(U32 status, if(status != 200) { LL_WARNS("UpdateCheck") << "html error " << status << " (" << reason << ")" << llendl; + mClient.error(reason); } else if(!content["valid"].asBoolean()) { LL_INFOS("UpdateCheck") << "version invalid" << llendl; + mClient.requiredUpdate(content["latest_version"].asString()); } else if(content["latest_version"].asString() != mVersion) { LL_INFOS("UpdateCheck") << "newer version " << content["latest_version"].asString() << " available" << llendl; + mClient.optionalUpdate(content["latest_version"].asString()); } else { LL_INFOS("UpdateCheck") << "up to date" << llendl; + mClient.upToDate(); } } diff --git a/indra/viewer_components/updater/llupdatechecker.h b/indra/viewer_components/updater/llupdatechecker.h index d2ec848e14..b630c4d8a6 100644 --- a/indra/viewer_components/updater/llupdatechecker.h +++ b/indra/viewer_components/updater/llupdatechecker.h @@ -42,6 +42,7 @@ public: // Check status of current app on the given host for the channel and version provided. void check(std::string const & hostUrl, std::string channel, std::string version); + private: boost::shared_ptr mImplementation; }; @@ -52,6 +53,7 @@ private: // class LLUpdateChecker::Client { +public: // An error occurred while checking for an update. virtual void error(std::string const & message) = 0; diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index e0f23722dd..2633dbc015 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -25,6 +25,8 @@ #include "linden_common.h" +#include "llevents.h" +#include "lltimer.h" #include "llupdaterservice.h" #include "llupdatechecker.h" @@ -38,6 +40,8 @@ class LLUpdaterServiceImpl : public LLPluginProcessParentOwner, public LLUpdateChecker::Client { + static const std::string ListenerName; + std::string mUrl; std::string mChannel; std::string mVersion; @@ -47,10 +51,15 @@ class LLUpdaterServiceImpl : boost::scoped_ptr mPlugin; LLUpdateChecker mUpdateChecker; + LLTimer mTimer; + + void retry(void); + + LOG_CLASS(LLUpdaterServiceImpl); public: LLUpdaterServiceImpl(); - virtual ~LLUpdaterServiceImpl() {} + virtual ~LLUpdaterServiceImpl(); // LLPluginProcessParentOwner interfaces virtual void receivePluginMessage(const LLPluginMessage &message); @@ -74,8 +83,10 @@ public: virtual void requiredUpdate(std::string const & newVersion); virtual void upToDate(void); + bool onMainLoop(LLSD const & event); }; +const std::string LLUpdaterServiceImpl::ListenerName = "LLUpdaterServiceImpl"; LLUpdaterServiceImpl::LLUpdaterServiceImpl() : mIsChecking(false), @@ -87,6 +98,12 @@ LLUpdaterServiceImpl::LLUpdaterServiceImpl() : mPlugin.reset(new LLPluginProcessParent(this)); } +LLUpdaterServiceImpl::~LLUpdaterServiceImpl() +{ + LL_INFOS("UpdaterService") << "shutting down updater service" << LL_ENDL; + LLEventPumps::instance().obtain("mainloop").stopListening(ListenerName); +} + // LLPluginProcessParentOwner interfaces void LLUpdaterServiceImpl::receivePluginMessage(const LLPluginMessage &message) { @@ -153,13 +170,49 @@ bool LLUpdaterServiceImpl::isChecking() return mIsChecking; } -void LLUpdaterServiceImpl::error(std::string const & message) {} +void LLUpdaterServiceImpl::error(std::string const & message) +{ + retry(); +} -void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion) {} +void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion) +{ + retry(); +} -void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion) {} +void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion) +{ + retry(); +} -void LLUpdaterServiceImpl::upToDate(void) {} +void LLUpdaterServiceImpl::upToDate(void) +{ + retry(); +} + +void LLUpdaterServiceImpl::retry(void) +{ + LL_INFOS("UpdaterService") << "will check for update again in " << + mCheckPeriod << " seconds" << LL_ENDL; + mTimer.start(); + mTimer.setTimerExpirySec(mCheckPeriod); + LLEventPumps::instance().obtain("mainloop").listen( + ListenerName, boost::bind(&LLUpdaterServiceImpl::onMainLoop, this, _1)); +} + +bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) +{ + if(mTimer.hasExpired()) + { + mTimer.stop(); + LLEventPumps::instance().obtain("mainloop").stopListening(ListenerName); + mUpdateChecker.check(mUrl, mChannel, mVersion); + } else { + // Keep on waiting... + } + + return false; +} //----------------------------------------------------------------------- -- cgit v1.2.3 From a2a9161e1b2d369689d76668dcad2c0ed7752960 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Fri, 29 Oct 2010 11:39:07 -0700 Subject: fix quoting of url in version check. --- indra/viewer_components/updater/llupdatechecker.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index ca2959a4ac..941210d35b 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -26,7 +26,9 @@ #include "linden_common.h" #include #include "llhttpclient.h" +#include "llsd.h" #include "llupdatechecker.h" +#include "lluri.h" class LLUpdateChecker::Implementation: @@ -137,8 +139,10 @@ void LLUpdateChecker::Implementation::error(U32 status, const std::string & reas std::string LLUpdateChecker::Implementation::buildUrl(std::string const & host, std::string channel, std::string version) { - static boost::format urlFormat("%s/version/%s/%s"); - urlFormat % host % channel % version; - return urlFormat.str(); + LLSD path; + path.append("version"); + path.append(channel); + path.append(version); + return LLURI::buildHTTP(host, path).asString(); } -- cgit v1.2.3 From 8bdd99436580772b825a1e99ae5cf37d20163a8c Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 29 Oct 2010 15:26:33 -0400 Subject: Fix #endif SYMBOL (breaks Linux build) --- indra/viewer_components/updater/llupdaterservice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 6459ca49f8..313ae8ada3 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -58,4 +58,4 @@ private: boost::shared_ptr mImpl; }; -#endif LL_UPDATERSERVICE_H +#endif // LL_UPDATERSERVICE_H -- cgit v1.2.3 From 36b8b88153180f637c24709dc94739b5f4c4367e Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Mon, 1 Nov 2010 09:33:30 -0700 Subject: changes in respone to review comments. --- indra/viewer_components/updater/llupdatechecker.cpp | 7 ++++++- indra/viewer_components/updater/llupdaterservice.cpp | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index 941210d35b..8733bb7ac0 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -52,7 +52,7 @@ private: Client & mClient; LLHTTPClient mHttpClient; bool mInProgress; - LLHTTPClient::ResponderPtr mMe; + LLHTTPClient::ResponderPtr mMe; std::string mVersion; LOG_CLASS(LLUpdateChecker::Implementation); @@ -105,6 +105,11 @@ void LLUpdateChecker::Implementation::check(std::string const & host, std::strin mVersion = version; std::string checkUrl = buildUrl(host, channel, version); LL_INFOS("UpdateCheck") << "checking for updates at " << checkUrl << llendl; + + // The HTTP client will wrap a raw pointer in a boost::intrusive_ptr causing the + // passed object to be silently and automatically deleted. We pass a self- + // referential intrusive pointer stored as an attribute of this class to keep + // the client from deletig the update checker implementation instance. mHttpClient.get(checkUrl, mMe); } diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 2633dbc015..62c909e57b 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -40,7 +40,7 @@ class LLUpdaterServiceImpl : public LLPluginProcessParentOwner, public LLUpdateChecker::Client { - static const std::string ListenerName; + static const std::string sListenerName; std::string mUrl; std::string mChannel; @@ -86,7 +86,7 @@ public: bool onMainLoop(LLSD const & event); }; -const std::string LLUpdaterServiceImpl::ListenerName = "LLUpdaterServiceImpl"; +const std::string LLUpdaterServiceImpl::sListenerName = "LLUpdaterServiceImpl"; LLUpdaterServiceImpl::LLUpdaterServiceImpl() : mIsChecking(false), @@ -101,7 +101,7 @@ LLUpdaterServiceImpl::LLUpdaterServiceImpl() : LLUpdaterServiceImpl::~LLUpdaterServiceImpl() { LL_INFOS("UpdaterService") << "shutting down updater service" << LL_ENDL; - LLEventPumps::instance().obtain("mainloop").stopListening(ListenerName); + LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); } // LLPluginProcessParentOwner interfaces @@ -197,7 +197,7 @@ void LLUpdaterServiceImpl::retry(void) mTimer.start(); mTimer.setTimerExpirySec(mCheckPeriod); LLEventPumps::instance().obtain("mainloop").listen( - ListenerName, boost::bind(&LLUpdaterServiceImpl::onMainLoop, this, _1)); + sListenerName, boost::bind(&LLUpdaterServiceImpl::onMainLoop, this, _1)); } bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) @@ -205,7 +205,7 @@ bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) if(mTimer.hasExpired()) { mTimer.stop(); - LLEventPumps::instance().obtain("mainloop").stopListening(ListenerName); + LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); mUpdateChecker.check(mUrl, mChannel, mVersion); } else { // Keep on waiting... -- cgit v1.2.3 From 2125bc0bbb3a5493b0b96bf68889b1f44b2db011 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 1 Nov 2010 15:49:04 -0400 Subject: On Windows, disable this-used-in-initializer warning. --- indra/viewer_components/updater/llupdatechecker.cpp | 3 +++ indra/viewer_components/updater/llupdaterservice.cpp | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index 941210d35b..331d0269d4 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -30,6 +30,9 @@ #include "llupdatechecker.h" #include "lluri.h" +#if LL_WINDOWS +#pragma warning (disable : 4355) // 'this' used in initializer list: yes, intentionally +#endif class LLUpdateChecker::Implementation: public LLHTTPClient::Responder diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 2633dbc015..1d0ead3cd4 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -34,6 +34,10 @@ #include #include +#if LL_WINDOWS +#pragma warning (disable : 4355) // 'this' used in initializer list: yes, intentionally +#endif + boost::weak_ptr gUpdater; class LLUpdaterServiceImpl : -- cgit v1.2.3 From be151807222ffa5972256aa9a392e8a319eae5ee Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Tue, 2 Nov 2010 15:59:10 -0700 Subject: start of the downloader service. --- indra/viewer_components/updater/CMakeLists.txt | 8 + .../updater/llupdatedownloader.cpp | 168 +++++++++++++++++++++ .../viewer_components/updater/llupdatedownloader.h | 73 +++++++++ 3 files changed, 249 insertions(+) create mode 100644 indra/viewer_components/updater/llupdatedownloader.cpp create mode 100644 indra/viewer_components/updater/llupdatedownloader.h (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index 2e77a7140a..64a0f98c2a 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -6,24 +6,30 @@ include(00-Common) if(LL_TESTS) include(LLAddBuildTest) endif(LL_TESTS) +include(CURL) include(LLCommon) include(LLMessage) include(LLPlugin) +include(LLVFS) include_directories( ${LLCOMMON_INCLUDE_DIRS} ${LLMESSAGE_INCLUDE_DIRS} ${LLPLUGIN_INCLUDE_DIRS} + ${LLVFS_INCLUDE_DIRS} + ${CURL_INCLUDE_DIRS} ) set(updater_service_SOURCE_FILES llupdaterservice.cpp llupdatechecker.cpp + llupdatedownloader.cpp ) set(updater_service_HEADER_FILES llupdaterservice.h llupdatechecker.h + llupdatedownloader.h ) set_source_files_properties(${updater_service_HEADER_FILES} @@ -42,6 +48,8 @@ target_link_libraries(llupdaterservice ${LLCOMMON_LIBRARIES} ${LLMESSAGE_LIBRARIES} ${LLPLUGIN_LIBRARIES} + ${LLVFS_LIBRARIES} + ${CURL_LIBRARIES} ) if(LL_TESTS) diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp new file mode 100644 index 0000000000..4adf9c42b1 --- /dev/null +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -0,0 +1,168 @@ +/** + * @file llupdatedownloader.cpp + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" +#include "lldir.h" +#include "llfile.h" +#include "llsd.h" +#include "llsdserialize.h" +#include "llthread.h" +#include "llupdatedownloader.h" + + +class LLUpdateDownloader::Implementation: + public LLThread +{ +public: + Implementation(LLUpdateDownloader::Client & client); + void cancel(void); + void download(LLURI const & uri); + bool isDownloading(void); + +private: + static const char * sSecondLifeUpdateRecord; + + LLUpdateDownloader::Client & mClient; + std::string mDownloadRecordPath; + + void resumeDownloading(LLSD const & downloadData); + void run(void); + bool shouldResumeOngoingDownload(LLURI const & uri, LLSD & downloadData); + void startDownloading(LLURI const & uri); +}; + + + +// LLUpdateDownloader +//----------------------------------------------------------------------------- + + +LLUpdateDownloader::LLUpdateDownloader(Client & client): + mImplementation(new LLUpdateDownloader::Implementation(client)) +{ + ; // No op. +} + + +void LLUpdateDownloader::cancel(void) +{ + mImplementation->cancel(); +} + + +void LLUpdateDownloader::download(LLURI const & uri) +{ + mImplementation->download(uri); +} + + +bool LLUpdateDownloader::isDownloading(void) +{ + return mImplementation->isDownloading(); +} + + + +// LLUpdateDownloader::Implementation +//----------------------------------------------------------------------------- + + +const char * LLUpdateDownloader::Implementation::sSecondLifeUpdateRecord = + "SecondLifeUpdateDownload.xml"; + + +LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & client): + LLThread("LLUpdateDownloader"), + mClient(client), + mDownloadRecordPath(gDirUtilp->getExpandedFilename(LL_PATH_LOGS, sSecondLifeUpdateRecord)) +{ + ; // No op. +} + + +void LLUpdateDownloader::Implementation::cancel(void) +{ +} + + +void LLUpdateDownloader::Implementation::download(LLURI const & uri) +{ + LLSD downloadData; + if(shouldResumeOngoingDownload(uri, downloadData)){ + + } else { + + } +} + + +bool LLUpdateDownloader::Implementation::isDownloading(void) +{ + return false; +} + + +void resumeDownloading(LLSD const & downloadData) +{ +} + + +bool LLUpdateDownloader::Implementation::shouldResumeOngoingDownload(LLURI const & uri, LLSD & downloadData) +{ + if(!LLFile::isfile(mDownloadRecordPath)) return false; + + llifstream dataStream(mDownloadRecordPath); + LLSDSerialize parser; + parser.fromXMLDocument(downloadData, dataStream); + + if(downloadData["url"].asString() != uri.asString()) return false; + + std::string downloadedFilePath = downloadData["path"].asString(); + if(LLFile::isfile(downloadedFilePath)) { + llstat fileStatus; + LLFile::stat(downloadedFilePath, &fileStatus); + downloadData["bytes_downloaded"] = LLSD(LLSD::Integer(fileStatus.st_size)); + return true; + } else { + return false; + } + + return true; +} + + +void LLUpdateDownloader::Implementation::startDownloading(LLURI const & uri) +{ + LLSD downloadData; + downloadData["url"] = uri.asString(); + LLSD path = uri.pathArray(); + std::string fileName = path[path.size() - 1].asString(); + std::string filePath = gDirUtilp->getExpandedFilename(LL_PATH_TEMP, fileName); + llofstream dataStream(mDownloadRecordPath); + LLSDSerialize parser; + parser.toPrettyXML(downloadData, dataStream); + + llofstream downloadStream(filePath); +} diff --git a/indra/viewer_components/updater/llupdatedownloader.h b/indra/viewer_components/updater/llupdatedownloader.h new file mode 100644 index 0000000000..9dc5d789ce --- /dev/null +++ b/indra/viewer_components/updater/llupdatedownloader.h @@ -0,0 +1,73 @@ +/** + * @file llupdatedownloader.h + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_UPDATE_DOWNLOADER_H +#define LL_UPDATE_DOWNLOADER_H + + +#include +#include +#include "lluri.h" + + +// +// An asynchronous download service for fetching updates. +// +class LLUpdateDownloader +{ +public: + class Client; + class Implementation; + + LLUpdateDownloader(Client & client); + + // Cancel any in progress download. + void cancel(void); + + // Start a new download. + void download(LLURI const & uri); + + // Returns true if a download is in progress. + bool isDownloading(void); + +private: + boost::shared_ptr mImplementation; +}; + + +// +// An interface to be implemented by clients initiating a update download. +// +class LLUpdateDownloader::Client { + + // The download has completed successfully. + void downloadComplete(void); + + // The download failed. + void downloadError(std::string const & message); +}; + + +#endif \ No newline at end of file -- cgit v1.2.3 From 7622ab9249506539894d0e33d4c2a8fd9fb3e3ac Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 4 Nov 2010 11:33:02 -0700 Subject: just barely working udate downloading service; missing little nicities like error checking and sill stuff like that. --- .../viewer_components/updater/llupdatechecker.cpp | 9 +- indra/viewer_components/updater/llupdatechecker.h | 7 +- .../updater/llupdatedownloader.cpp | 128 +++++++++++++++++++-- .../viewer_components/updater/llupdatedownloader.h | 12 +- .../viewer_components/updater/llupdaterservice.cpp | 24 ++-- .../updater/tests/llupdaterservice_test.cpp | 4 + 6 files changed, 159 insertions(+), 25 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index 9cfa919b39..596b122a25 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -120,17 +120,19 @@ void LLUpdateChecker::Implementation::completed(U32 status, const std::string & reason, const LLSD & content) { - mInProgress = false; + mInProgress = false; if(status != 200) { LL_WARNS("UpdateCheck") << "html error " << status << " (" << reason << ")" << llendl; mClient.error(reason); } else if(!content["valid"].asBoolean()) { LL_INFOS("UpdateCheck") << "version invalid" << llendl; - mClient.requiredUpdate(content["latest_version"].asString()); + LLURI uri(content["download_url"].asString()); + mClient.requiredUpdate(content["latest_version"].asString(), uri); } else if(content["latest_version"].asString() != mVersion) { LL_INFOS("UpdateCheck") << "newer version " << content["latest_version"].asString() << " available" << llendl; - mClient.optionalUpdate(content["latest_version"].asString()); + LLURI uri(content["download_url"].asString()); + mClient.optionalUpdate(content["latest_version"].asString(), uri); } else { LL_INFOS("UpdateCheck") << "up to date" << llendl; mClient.upToDate(); @@ -153,4 +155,3 @@ std::string LLUpdateChecker::Implementation::buildUrl(std::string const & host, path.append(version); return LLURI::buildHTTP(host, path).asString(); } - diff --git a/indra/viewer_components/updater/llupdatechecker.h b/indra/viewer_components/updater/llupdatechecker.h index b630c4d8a6..1f8c6d8a91 100644 --- a/indra/viewer_components/updater/llupdatechecker.h +++ b/indra/viewer_components/updater/llupdatechecker.h @@ -48,6 +48,9 @@ private: }; +class LLURI; // From lluri.h + + // // The client interface implemented by a requestor checking for an update. // @@ -58,10 +61,10 @@ public: virtual void error(std::string const & message) = 0; // A newer version is available, but the current version may still be used. - virtual void optionalUpdate(std::string const & newVersion) = 0; + virtual void optionalUpdate(std::string const & newVersion, LLURI const & uri) = 0; // A newer version is available, and the current version is no longer valid. - virtual void requiredUpdate(std::string const & newVersion) = 0; + virtual void requiredUpdate(std::string const & newVersion, LLURI const & uri) = 0; // The checked version is up to date; no newer version exists. virtual void upToDate(void) = 0; diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 4adf9c42b1..21e4ce94cc 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -24,6 +24,8 @@ */ #include "linden_common.h" +#include +#include #include "lldir.h" #include "llfile.h" #include "llsd.h" @@ -37,20 +39,27 @@ class LLUpdateDownloader::Implementation: { public: Implementation(LLUpdateDownloader::Client & client); + ~Implementation(); void cancel(void); void download(LLURI const & uri); bool isDownloading(void); - + void onHeader(void * header, size_t size); + void onBody(void * header, size_t size); private: static const char * sSecondLifeUpdateRecord; LLUpdateDownloader::Client & mClient; + CURL * mCurl; + llofstream mDownloadStream; std::string mDownloadRecordPath; + void initializeCurlGet(std::string const & url); void resumeDownloading(LLSD const & downloadData); void run(void); bool shouldResumeOngoingDownload(LLURI const & uri, LLSD & downloadData); void startDownloading(LLURI const & uri); + + LOG_CLASS(LLUpdateDownloader::Implementation); }; @@ -89,6 +98,23 @@ bool LLUpdateDownloader::isDownloading(void) //----------------------------------------------------------------------------- +namespace { + size_t write_function(void * data, size_t blockSize, size_t blocks, void * downloader) + { + size_t bytes = blockSize * blocks; + reinterpret_cast(downloader)->onBody(data, bytes); + return bytes; + } + + size_t header_function(void * data, size_t blockSize, size_t blocks, void * downloader) + { + size_t bytes = blockSize * blocks; + reinterpret_cast(downloader)->onHeader(data, bytes); + return bytes; + } +} + + const char * LLUpdateDownloader::Implementation::sSecondLifeUpdateRecord = "SecondLifeUpdateDownload.xml"; @@ -96,35 +122,116 @@ const char * LLUpdateDownloader::Implementation::sSecondLifeUpdateRecord = LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & client): LLThread("LLUpdateDownloader"), mClient(client), + mCurl(0), mDownloadRecordPath(gDirUtilp->getExpandedFilename(LL_PATH_LOGS, sSecondLifeUpdateRecord)) { - ; // No op. + CURLcode code = curl_global_init(CURL_GLOBAL_ALL); // Just in case. + llassert(code = CURLE_OK); // TODO: real error handling here. } -void LLUpdateDownloader::Implementation::cancel(void) +LLUpdateDownloader::Implementation::~Implementation() { + if(mCurl) curl_easy_cleanup(mCurl); } +void LLUpdateDownloader::Implementation::cancel(void) +{ + llassert(!"not implemented"); +} + + void LLUpdateDownloader::Implementation::download(LLURI const & uri) { LLSD downloadData; if(shouldResumeOngoingDownload(uri, downloadData)){ - + startDownloading(uri); // TODO: Implement resume. } else { - + startDownloading(uri); } } bool LLUpdateDownloader::Implementation::isDownloading(void) { - return false; + return !isStopped(); +} + +void LLUpdateDownloader::Implementation::onHeader(void * buffer, size_t size) +{ + char const * headerPtr = reinterpret_cast (buffer); + std::string header(headerPtr, headerPtr + size); + size_t colonPosition = header.find(':'); + if(colonPosition == std::string::npos) return; // HTML response; ignore. + + if(header.substr(0, colonPosition) == "Content-Length") { + try { + size_t firstDigitPos = header.find_first_of("0123456789", colonPosition); + size_t lastDigitPos = header.find_last_of("0123456789"); + std::string contentLength = header.substr(firstDigitPos, lastDigitPos - firstDigitPos + 1); + size_t size = boost::lexical_cast(contentLength); + LL_INFOS("UpdateDownload") << "download size is " << size << LL_ENDL; + + LLSD downloadData; + llifstream idataStream(mDownloadRecordPath); + LLSDSerialize parser; + parser.fromXMLDocument(downloadData, idataStream); + idataStream.close(); + downloadData["size"] = LLSD(LLSD::Integer(size)); + llofstream odataStream(mDownloadRecordPath); + parser.toPrettyXML(downloadData, odataStream); + } catch (std::exception const & e) { + LL_WARNS("UpdateDownload") << "unable to read content length (" + << e.what() << ")" << LL_ENDL; + } + } else { + ; // No op. + } +} + + +void LLUpdateDownloader::Implementation::onBody(void * buffer, size_t size) +{ + mDownloadStream.write(reinterpret_cast(buffer), size); +} + + +void LLUpdateDownloader::Implementation::run(void) +{ + CURLcode code = curl_easy_perform(mCurl); + if(code == CURLE_OK) { + LL_INFOS("UpdateDownload") << "download successful" << LL_ENDL; + mClient.downloadComplete(); + } else { + LL_WARNS("UpdateDownload") << "download failed with error " << code << LL_ENDL; + mClient.downloadError("curl error"); + } +} + + +void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & url) +{ + if(mCurl == 0) { + mCurl = curl_easy_init(); + } else { + curl_easy_reset(mCurl); + } + + llassert(mCurl != 0); // TODO: real error handling here. + + CURLcode code; + code = curl_easy_setopt(mCurl, CURLOPT_NOSIGNAL, true); + code = curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, &write_function); + code = curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, this); + code = curl_easy_setopt(mCurl, CURLOPT_HEADERFUNCTION, &header_function); + code = curl_easy_setopt(mCurl, CURLOPT_HEADERDATA, this); + code = curl_easy_setopt(mCurl, CURLOPT_HTTPGET, true); + code = curl_easy_setopt(mCurl, CURLOPT_URL, url.c_str()); } -void resumeDownloading(LLSD const & downloadData) +void LLUpdateDownloader::Implementation::resumeDownloading(LLSD const & downloadData) { } @@ -160,9 +267,14 @@ void LLUpdateDownloader::Implementation::startDownloading(LLURI const & uri) LLSD path = uri.pathArray(); std::string fileName = path[path.size() - 1].asString(); std::string filePath = gDirUtilp->getExpandedFilename(LL_PATH_TEMP, fileName); + LL_INFOS("UpdateDownload") << "downloading " << filePath << LL_ENDL; + LL_INFOS("UpdateDownload") << "from " << uri.asString() << LL_ENDL; + downloadData["path"] = filePath; llofstream dataStream(mDownloadRecordPath); LLSDSerialize parser; parser.toPrettyXML(downloadData, dataStream); - llofstream downloadStream(filePath); + mDownloadStream.open(filePath, std::ios_base::out | std::ios_base::binary); + initializeCurlGet(uri.asString()); + start(); } diff --git a/indra/viewer_components/updater/llupdatedownloader.h b/indra/viewer_components/updater/llupdatedownloader.h index 9dc5d789ce..6118c4338e 100644 --- a/indra/viewer_components/updater/llupdatedownloader.h +++ b/indra/viewer_components/updater/llupdatedownloader.h @@ -27,6 +27,7 @@ #define LL_UPDATE_DOWNLOADER_H +#include #include #include #include "lluri.h" @@ -38,15 +39,19 @@ class LLUpdateDownloader { public: + class BusyError; class Client; class Implementation; LLUpdateDownloader(Client & client); - // Cancel any in progress download. + // Cancel any in progress download; a no op if none is in progress. void cancel(void); // Start a new download. + // + // This method will throw a BusyException instance if a download is already + // in progress. void download(LLURI const & uri); // Returns true if a download is in progress. @@ -61,12 +66,13 @@ private: // An interface to be implemented by clients initiating a update download. // class LLUpdateDownloader::Client { +public: // The download has completed successfully. - void downloadComplete(void); + virtual void downloadComplete(void) = 0; // The download failed. - void downloadError(std::string const & message); + virtual void downloadError(std::string const & message) = 0; }; diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index e339c69724..a1b6de38e5 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -25,6 +25,7 @@ #include "linden_common.h" +#include "llupdatedownloader.h" #include "llevents.h" #include "lltimer.h" #include "llupdaterservice.h" @@ -42,7 +43,8 @@ boost::weak_ptr gUpdater; class LLUpdaterServiceImpl : public LLPluginProcessParentOwner, - public LLUpdateChecker::Client + public LLUpdateChecker::Client, + public LLUpdateDownloader::Client { static const std::string sListenerName; @@ -55,6 +57,7 @@ class LLUpdaterServiceImpl : boost::scoped_ptr mPlugin; LLUpdateChecker mUpdateChecker; + LLUpdateDownloader mUpdateDownloader; LLTimer mTimer; void retry(void); @@ -83,10 +86,14 @@ public: // LLUpdateChecker::Client: virtual void error(std::string const & message); - virtual void optionalUpdate(std::string const & newVersion); - virtual void requiredUpdate(std::string const & newVersion); + virtual void optionalUpdate(std::string const & newVersion, LLURI const & uri); + virtual void requiredUpdate(std::string const & newVersion, LLURI const & uri); virtual void upToDate(void); + // LLUpdateDownloader::Client + void downloadComplete(void) { retry(); } + void downloadError(std::string const & message) { retry(); } + bool onMainLoop(LLSD const & event); }; @@ -96,7 +103,8 @@ LLUpdaterServiceImpl::LLUpdaterServiceImpl() : mIsChecking(false), mCheckPeriod(0), mPlugin(0), - mUpdateChecker(*this) + mUpdateChecker(*this), + mUpdateDownloader(*this) { // Create the plugin parent, this is the owner. mPlugin.reset(new LLPluginProcessParent(this)); @@ -179,14 +187,14 @@ void LLUpdaterServiceImpl::error(std::string const & message) retry(); } -void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion) +void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion, LLURI const & uri) { - retry(); + mUpdateDownloader.download(uri); } -void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion) +void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion, LLURI const & uri) { - retry(); + mUpdateDownloader.download(uri); } void LLUpdaterServiceImpl::upToDate(void) diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index d93a85cf7d..0ffc1f2c70 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -29,6 +29,7 @@ // associated header #include "../llupdaterservice.h" #include "../llupdatechecker.h" +#include "../llupdatedownloader.h" #include "../../../test/lltut.h" //#define DEBUG_ON @@ -60,6 +61,9 @@ LLPluginMessage::LLPluginMessage(LLPluginMessage const&) {} LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client) {} void LLUpdateChecker::check(std::string const & host, std::string channel, std::string version){} +LLUpdateDownloader::LLUpdateDownloader(LLUpdateDownloader::Client & client) +{} +void LLUpdateDownloader::download(LLURI const & ){} /***************************************************************************** * TUT -- cgit v1.2.3 From dfeb7abe5f690bbd3a908c84c53bbea20a5adb7c Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 4 Nov 2010 14:08:14 -0700 Subject: checker working with v1.0 update protocol. --- .../viewer_components/updater/llupdatechecker.cpp | 52 ++++++++++++++-------- indra/viewer_components/updater/llupdatechecker.h | 3 +- .../updater/llupdatedownloader.cpp | 1 + .../viewer_components/updater/llupdaterservice.cpp | 28 ++++++++---- indra/viewer_components/updater/llupdaterservice.h | 6 +-- .../updater/tests/llupdaterservice_test.cpp | 11 ++--- 6 files changed, 65 insertions(+), 36 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index 596b122a25..2c60636122 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -41,7 +41,8 @@ public: Implementation(Client & client); ~Implementation(); - void check(std::string const & host, std::string channel, std::string version); + void check(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version); // Responder: virtual void completed(U32 status, @@ -50,7 +51,8 @@ public: virtual void error(U32 status, const std::string & reason); private: - std::string buildUrl(std::string const & host, std::string channel, std::string version); + std::string buildUrl(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version); Client & mClient; LLHTTPClient mHttpClient; @@ -74,9 +76,10 @@ LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client): } -void LLUpdateChecker::check(std::string const & host, std::string channel, std::string version) +void LLUpdateChecker::check(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version) { - mImplementation->check(host, channel, version); + mImplementation->check(protocolVersion, hostUrl, servicePath, channel, version); } @@ -100,13 +103,14 @@ LLUpdateChecker::Implementation::~Implementation() } -void LLUpdateChecker::Implementation::check(std::string const & host, std::string channel, std::string version) +void LLUpdateChecker::Implementation::check(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version) { // llassert(!mInProgress); mInProgress = true; mVersion = version; - std::string checkUrl = buildUrl(host, channel, version); + std::string checkUrl = buildUrl(protocolVersion, hostUrl, servicePath, channel, version); LL_INFOS("UpdateCheck") << "checking for updates at " << checkUrl << llendl; // The HTTP client will wrap a raw pointer in a boost::intrusive_ptr causing the @@ -125,17 +129,17 @@ void LLUpdateChecker::Implementation::completed(U32 status, if(status != 200) { LL_WARNS("UpdateCheck") << "html error " << status << " (" << reason << ")" << llendl; mClient.error(reason); - } else if(!content["valid"].asBoolean()) { - LL_INFOS("UpdateCheck") << "version invalid" << llendl; - LLURI uri(content["download_url"].asString()); - mClient.requiredUpdate(content["latest_version"].asString(), uri); - } else if(content["latest_version"].asString() != mVersion) { - LL_INFOS("UpdateCheck") << "newer version " << content["latest_version"].asString() << " available" << llendl; - LLURI uri(content["download_url"].asString()); - mClient.optionalUpdate(content["latest_version"].asString(), uri); - } else { + } else if(!content.asBoolean()) { LL_INFOS("UpdateCheck") << "up to date" << llendl; mClient.upToDate(); + } else if(content["required"].asBoolean()) { + LL_INFOS("UpdateCheck") << "version invalid" << llendl; + LLURI uri(content["url"].asString()); + mClient.requiredUpdate(content["version"].asString(), uri); + } else { + LL_INFOS("UpdateCheck") << "newer version " << content["version"].asString() << " available" << llendl; + LLURI uri(content["url"].asString()); + mClient.optionalUpdate(content["version"].asString(), uri); } } @@ -144,14 +148,26 @@ void LLUpdateChecker::Implementation::error(U32 status, const std::string & reas { mInProgress = false; LL_WARNS("UpdateCheck") << "update check failed; " << reason << llendl; + mClient.error(reason); } -std::string LLUpdateChecker::Implementation::buildUrl(std::string const & host, std::string channel, std::string version) +std::string LLUpdateChecker::Implementation::buildUrl(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version) { +#ifdef LL_WINDOWS + static const char * platform = "win"; +#elif LL_DARWIN + static const char * platform = "mac"; +#else + static const char * platform = "lnx"; +#endif + LLSD path; - path.append("version"); + path.append(servicePath); + path.append(protocolVersion); path.append(channel); path.append(version); - return LLURI::buildHTTP(host, path).asString(); + path.append(platform); + return LLURI::buildHTTP(hostUrl, path).asString(); } diff --git a/indra/viewer_components/updater/llupdatechecker.h b/indra/viewer_components/updater/llupdatechecker.h index 1f8c6d8a91..58aaee4e3d 100644 --- a/indra/viewer_components/updater/llupdatechecker.h +++ b/indra/viewer_components/updater/llupdatechecker.h @@ -41,7 +41,8 @@ public: LLUpdateChecker(Client & client); // Check status of current app on the given host for the channel and version provided. - void check(std::string const & hostUrl, std::string channel, std::string version); + void check(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version); private: boost::shared_ptr mImplementation; diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 21e4ce94cc..087d79f804 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -222,6 +222,7 @@ void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & u CURLcode code; code = curl_easy_setopt(mCurl, CURLOPT_NOSIGNAL, true); + code = curl_easy_setopt(mCurl, CURLOPT_FOLLOWLOCATION, true); code = curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, &write_function); code = curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, this); code = curl_easy_setopt(mCurl, CURLOPT_HEADERFUNCTION, &header_function); diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index a1b6de38e5..e865552fb3 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -48,7 +48,9 @@ class LLUpdaterServiceImpl : { static const std::string sListenerName; + std::string mProtocolVersion; std::string mUrl; + std::string mPath; std::string mChannel; std::string mVersion; @@ -74,10 +76,12 @@ public: virtual void pluginLaunchFailed(); virtual void pluginDied(); - void setParams(const std::string& url, + void setParams(const std::string& protocol_version, + const std::string& url, + const std::string& path, const std::string& channel, const std::string& version); - + void setCheckPeriod(unsigned int seconds); void startChecking(); @@ -134,7 +138,9 @@ void LLUpdaterServiceImpl::pluginDied() { }; -void LLUpdaterServiceImpl::setParams(const std::string& url, +void LLUpdaterServiceImpl::setParams(const std::string& protocol_version, + const std::string& url, + const std::string& path, const std::string& channel, const std::string& version) { @@ -144,7 +150,9 @@ void LLUpdaterServiceImpl::setParams(const std::string& url, " before setting params."); } + mProtocolVersion = protocol_version; mUrl = url; + mPath = path; mChannel = channel; mVersion = version; } @@ -165,7 +173,7 @@ void LLUpdaterServiceImpl::startChecking() } mIsChecking = true; - mUpdateChecker.check(mUrl, mChannel, mVersion); + mUpdateChecker.check(mProtocolVersion, mUrl, mPath, mChannel, mVersion); } } @@ -218,7 +226,7 @@ bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) { mTimer.stop(); LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); - mUpdateChecker.check(mUrl, mChannel, mVersion); + mUpdateChecker.check(mProtocolVersion, mUrl, mPath, mChannel, mVersion); } else { // Keep on waiting... } @@ -247,11 +255,13 @@ LLUpdaterService::~LLUpdaterService() { } -void LLUpdaterService::setParams(const std::string& url, - const std::string& chan, - const std::string& vers) +void LLUpdaterService::setParams(const std::string& protocol_version, + const std::string& url, + const std::string& path, + const std::string& channel, + const std::string& version) { - mImpl->setParams(url, chan, vers); + mImpl->setParams(protocol_version, url, path, channel, version); } void LLUpdaterService::setCheckPeriod(unsigned int seconds) diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 313ae8ada3..83b09c4bdd 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -42,9 +42,9 @@ public: LLUpdaterService(); ~LLUpdaterService(); - // The base URL. - // *NOTE:Mani The grid, if any, would be embedded in the base URL. - void setParams(const std::string& url, + void setParams(const std::string& version, + const std::string& url, + const std::string& path, const std::string& channel, const std::string& version); diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 0ffc1f2c70..958526e35b 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -60,9 +60,10 @@ LLPluginMessage::LLPluginMessage(LLPluginMessage const&) {} LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client) {} -void LLUpdateChecker::check(std::string const & host, std::string channel, std::string version){} -LLUpdateDownloader::LLUpdateDownloader(LLUpdateDownloader::Client & client) +void LLUpdateChecker::check(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version) {} +LLUpdateDownloader::LLUpdateDownloader(Client & ) {} void LLUpdateDownloader::download(LLURI const & ){} /***************************************************************************** @@ -113,9 +114,9 @@ namespace tut bool got_usage_error = false; try { - updater.setParams(test_url, test_channel, test_version); + updater.setParams("1.0",test_url, "update" ,test_channel, test_version); updater.startChecking(); - updater.setParams("other_url", test_channel, test_version); + updater.setParams("1.0", "other_url", "update", test_channel, test_version); } catch(LLUpdaterService::UsageError) { @@ -129,7 +130,7 @@ namespace tut { DEBUG; LLUpdaterService updater; - updater.setParams(test_url, test_channel, test_version); + updater.setParams("1.0", test_url, "update", test_channel, test_version); updater.startChecking(); ensure(updater.isChecking()); updater.stopChecking(); -- cgit v1.2.3 From e45ba2957630f6319f8c633a409d78be56c264bd Mon Sep 17 00:00:00 2001 From: brad kittenbrink Date: Thu, 4 Nov 2010 15:09:10 -0700 Subject: Fix for linux eol error. --- indra/viewer_components/updater/llupdatedownloader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.h b/indra/viewer_components/updater/llupdatedownloader.h index 6118c4338e..395d19d6bf 100644 --- a/indra/viewer_components/updater/llupdatedownloader.h +++ b/indra/viewer_components/updater/llupdatedownloader.h @@ -76,4 +76,4 @@ public: }; -#endif \ No newline at end of file +#endif -- cgit v1.2.3 From 191e164a503b72c7feae0a46ad0422740b365556 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 4 Nov 2010 15:49:19 -0700 Subject: some better error handling. --- .../viewer_components/updater/llupdatechecker.cpp | 35 ++++-- indra/viewer_components/updater/llupdatechecker.h | 11 +- .../updater/llupdatedownloader.cpp | 122 +++++++++++++-------- .../viewer_components/updater/llupdatedownloader.h | 11 +- .../viewer_components/updater/llupdaterservice.cpp | 20 +++- .../updater/tests/llupdaterservice_test.cpp | 2 +- 6 files changed, 136 insertions(+), 65 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index 2c60636122..d31244cc9b 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -24,21 +24,35 @@ */ #include "linden_common.h" +#include #include #include "llhttpclient.h" #include "llsd.h" #include "llupdatechecker.h" #include "lluri.h" + #if LL_WINDOWS #pragma warning (disable : 4355) // 'this' used in initializer list: yes, intentionally #endif + +class LLUpdateChecker::CheckError: + public std::runtime_error +{ +public: + CheckError(const char * message): + std::runtime_error(message) + { + ; // No op. + } +}; + + class LLUpdateChecker::Implementation: public LLHTTPClient::Responder { public: - Implementation(Client & client); ~Implementation(); void check(std::string const & protocolVersion, std::string const & hostUrl, @@ -50,9 +64,8 @@ public: const LLSD& content); virtual void error(U32 status, const std::string & reason); -private: - std::string buildUrl(std::string const & protocolVersion, std::string const & hostUrl, - std::string const & servicePath, std::string channel, std::string version); +private: + static const char * sProtocolVersion; Client & mClient; LLHTTPClient mHttpClient; @@ -60,6 +73,9 @@ private: LLHTTPClient::ResponderPtr mMe; std::string mVersion; + std::string buildUrl(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version); + LOG_CLASS(LLUpdateChecker::Implementation); }; @@ -88,6 +104,9 @@ void LLUpdateChecker::check(std::string const & protocolVersion, std::string con //----------------------------------------------------------------------------- +const char * LLUpdateChecker::Implementation::sProtocolVersion = "v1.0"; + + LLUpdateChecker::Implementation::Implementation(LLUpdateChecker::Client & client): mClient(client), mInProgress(false), @@ -106,7 +125,9 @@ LLUpdateChecker::Implementation::~Implementation() void LLUpdateChecker::Implementation::check(std::string const & protocolVersion, std::string const & hostUrl, std::string const & servicePath, std::string channel, std::string version) { - // llassert(!mInProgress); + llassert(!mInProgress); + + if(protocolVersion != sProtocolVersion) throw CheckError("unsupported protocol"); mInProgress = true; mVersion = version; @@ -135,11 +156,11 @@ void LLUpdateChecker::Implementation::completed(U32 status, } else if(content["required"].asBoolean()) { LL_INFOS("UpdateCheck") << "version invalid" << llendl; LLURI uri(content["url"].asString()); - mClient.requiredUpdate(content["version"].asString(), uri); + mClient.requiredUpdate(content["version"].asString(), uri, content["hash"].asString()); } else { LL_INFOS("UpdateCheck") << "newer version " << content["version"].asString() << " available" << llendl; LLURI uri(content["url"].asString()); - mClient.optionalUpdate(content["version"].asString(), uri); + mClient.optionalUpdate(content["version"].asString(), uri, content["hash"].asString()); } } diff --git a/indra/viewer_components/updater/llupdatechecker.h b/indra/viewer_components/updater/llupdatechecker.h index 58aaee4e3d..cea1f13647 100644 --- a/indra/viewer_components/updater/llupdatechecker.h +++ b/indra/viewer_components/updater/llupdatechecker.h @@ -38,6 +38,9 @@ public: class Client; class Implementation; + // An exception that may be raised on check errors. + class CheckError; + LLUpdateChecker(Client & client); // Check status of current app on the given host for the channel and version provided. @@ -62,10 +65,14 @@ public: virtual void error(std::string const & message) = 0; // A newer version is available, but the current version may still be used. - virtual void optionalUpdate(std::string const & newVersion, LLURI const & uri) = 0; + virtual void optionalUpdate(std::string const & newVersion, + LLURI const & uri, + std::string const & hash) = 0; // A newer version is available, and the current version is no longer valid. - virtual void requiredUpdate(std::string const & newVersion, LLURI const & uri) = 0; + virtual void requiredUpdate(std::string const & newVersion, + LLURI const & uri, + std::string const & hash) = 0; // The checked version is up to date; no newer version exists. virtual void upToDate(void) = 0; diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 087d79f804..23772e021e 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -24,6 +24,7 @@ */ #include "linden_common.h" +#include #include #include #include "lldir.h" @@ -41,33 +42,56 @@ public: Implementation(LLUpdateDownloader::Client & client); ~Implementation(); void cancel(void); - void download(LLURI const & uri); + void download(LLURI const & uri, std::string const & hash); bool isDownloading(void); void onHeader(void * header, size_t size); void onBody(void * header, size_t size); private: - static const char * sSecondLifeUpdateRecord; - LLUpdateDownloader::Client & mClient; CURL * mCurl; + LLSD mDownloadData; llofstream mDownloadStream; std::string mDownloadRecordPath; void initializeCurlGet(std::string const & url); void resumeDownloading(LLSD const & downloadData); void run(void); - bool shouldResumeOngoingDownload(LLURI const & uri, LLSD & downloadData); - void startDownloading(LLURI const & uri); + void startDownloading(LLURI const & uri, std::string const & hash); + void throwOnCurlError(CURLcode code); LOG_CLASS(LLUpdateDownloader::Implementation); }; +namespace { + class DownloadError: + public std::runtime_error + { + public: + DownloadError(const char * message): + std::runtime_error(message) + { + ; // No op. + } + }; + + + const char * gSecondLifeUpdateRecord = "SecondLifeUpdateDownload.xml"; +}; + + // LLUpdateDownloader //----------------------------------------------------------------------------- + +std::string LLUpdateDownloader::downloadMarkerPath(void) +{ + return gDirUtilp->getExpandedFilename(LL_PATH_LOGS, gSecondLifeUpdateRecord); +} + + LLUpdateDownloader::LLUpdateDownloader(Client & client): mImplementation(new LLUpdateDownloader::Implementation(client)) { @@ -81,9 +105,9 @@ void LLUpdateDownloader::cancel(void) } -void LLUpdateDownloader::download(LLURI const & uri) +void LLUpdateDownloader::download(LLURI const & uri, std::string const & hash) { - mImplementation->download(uri); + mImplementation->download(uri, hash); } @@ -115,15 +139,11 @@ namespace { } -const char * LLUpdateDownloader::Implementation::sSecondLifeUpdateRecord = - "SecondLifeUpdateDownload.xml"; - - LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & client): LLThread("LLUpdateDownloader"), mClient(client), mCurl(0), - mDownloadRecordPath(gDirUtilp->getExpandedFilename(LL_PATH_LOGS, sSecondLifeUpdateRecord)) + mDownloadRecordPath(LLUpdateDownloader::downloadMarkerPath()) { CURLcode code = curl_global_init(CURL_GLOBAL_ALL); // Just in case. llassert(code = CURLE_OK); // TODO: real error handling here. @@ -142,13 +162,15 @@ void LLUpdateDownloader::Implementation::cancel(void) } -void LLUpdateDownloader::Implementation::download(LLURI const & uri) +void LLUpdateDownloader::Implementation::download(LLURI const & uri, std::string const & hash) { - LLSD downloadData; - if(shouldResumeOngoingDownload(uri, downloadData)){ - startDownloading(uri); // TODO: Implement resume. - } else { - startDownloading(uri); + if(isDownloading()) mClient.downloadError("download in progress"); + + mDownloadData = LLSD(); + try { + startDownloading(uri, hash); + } catch(DownloadError const & e) { + mClient.downloadError(e.what()); } } @@ -173,14 +195,10 @@ void LLUpdateDownloader::Implementation::onHeader(void * buffer, size_t size) size_t size = boost::lexical_cast(contentLength); LL_INFOS("UpdateDownload") << "download size is " << size << LL_ENDL; - LLSD downloadData; - llifstream idataStream(mDownloadRecordPath); - LLSDSerialize parser; - parser.fromXMLDocument(downloadData, idataStream); - idataStream.close(); - downloadData["size"] = LLSD(LLSD::Integer(size)); + mDownloadData["size"] = LLSD(LLSD::Integer(size)); llofstream odataStream(mDownloadRecordPath); - parser.toPrettyXML(downloadData, odataStream); + LLSDSerialize parser; + parser.toPrettyXML(mDownloadData, odataStream); } catch (std::exception const & e) { LL_WARNS("UpdateDownload") << "unable to read content length (" << e.what() << ")" << LL_ENDL; @@ -218,17 +236,16 @@ void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & u curl_easy_reset(mCurl); } - llassert(mCurl != 0); // TODO: real error handling here. + if(mCurl == 0) throw DownloadError("failed to initialize curl"); - CURLcode code; - code = curl_easy_setopt(mCurl, CURLOPT_NOSIGNAL, true); - code = curl_easy_setopt(mCurl, CURLOPT_FOLLOWLOCATION, true); - code = curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, &write_function); - code = curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, this); - code = curl_easy_setopt(mCurl, CURLOPT_HEADERFUNCTION, &header_function); - code = curl_easy_setopt(mCurl, CURLOPT_HEADERDATA, this); - code = curl_easy_setopt(mCurl, CURLOPT_HTTPGET, true); - code = curl_easy_setopt(mCurl, CURLOPT_URL, url.c_str()); + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_NOSIGNAL, true)); + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_FOLLOWLOCATION, true)); + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, &write_function)); + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, this)); + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HEADERFUNCTION, &header_function)); + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HEADERDATA, this)); + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HTTPGET, true)); + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_URL, url.c_str())); } @@ -236,7 +253,7 @@ void LLUpdateDownloader::Implementation::resumeDownloading(LLSD const & download { } - +/* bool LLUpdateDownloader::Implementation::shouldResumeOngoingDownload(LLURI const & uri, LLSD & downloadData) { if(!LLFile::isfile(mDownloadRecordPath)) return false; @@ -259,23 +276,42 @@ bool LLUpdateDownloader::Implementation::shouldResumeOngoingDownload(LLURI const return true; } + */ -void LLUpdateDownloader::Implementation::startDownloading(LLURI const & uri) +void LLUpdateDownloader::Implementation::startDownloading(LLURI const & uri, std::string const & hash) { - LLSD downloadData; - downloadData["url"] = uri.asString(); + mDownloadData["url"] = uri.asString(); + mDownloadData["hash"] = hash; LLSD path = uri.pathArray(); + if(path.size() == 0) throw DownloadError("no file path"); std::string fileName = path[path.size() - 1].asString(); std::string filePath = gDirUtilp->getExpandedFilename(LL_PATH_TEMP, fileName); - LL_INFOS("UpdateDownload") << "downloading " << filePath << LL_ENDL; - LL_INFOS("UpdateDownload") << "from " << uri.asString() << LL_ENDL; - downloadData["path"] = filePath; + mDownloadData["path"] = filePath; + + LL_INFOS("UpdateDownload") << "downloading " << filePath << "\n" + << "from " << uri.asString() << LL_ENDL; + llofstream dataStream(mDownloadRecordPath); LLSDSerialize parser; - parser.toPrettyXML(downloadData, dataStream); + parser.toPrettyXML(mDownloadData, dataStream); mDownloadStream.open(filePath, std::ios_base::out | std::ios_base::binary); initializeCurlGet(uri.asString()); start(); } + + +void LLUpdateDownloader::Implementation::throwOnCurlError(CURLcode code) +{ + if(code != CURLE_OK) { + const char * errorString = curl_easy_strerror(code); + if(errorString != 0) { + throw DownloadError(curl_easy_strerror(code)); + } else { + throw DownloadError("unknown curl error"); + } + } else { + ; // No op. + } +} diff --git a/indra/viewer_components/updater/llupdatedownloader.h b/indra/viewer_components/updater/llupdatedownloader.h index 6118c4338e..8754ea329c 100644 --- a/indra/viewer_components/updater/llupdatedownloader.h +++ b/indra/viewer_components/updater/llupdatedownloader.h @@ -27,7 +27,6 @@ #define LL_UPDATE_DOWNLOADER_H -#include #include #include #include "lluri.h" @@ -39,20 +38,20 @@ class LLUpdateDownloader { public: - class BusyError; class Client; class Implementation; + // Returns the path to the download marker file containing details of the + // latest download. + static std::string downloadMarkerPath(void); + LLUpdateDownloader(Client & client); // Cancel any in progress download; a no op if none is in progress. void cancel(void); // Start a new download. - // - // This method will throw a BusyException instance if a download is already - // in progress. - void download(LLURI const & uri); + void download(LLURI const & uri, std::string const & hash); // Returns true if a download is in progress. bool isDownloading(void); diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index e865552fb3..1e0c393539 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -90,8 +90,12 @@ public: // LLUpdateChecker::Client: virtual void error(std::string const & message); - virtual void optionalUpdate(std::string const & newVersion, LLURI const & uri); - virtual void requiredUpdate(std::string const & newVersion, LLURI const & uri); + virtual void optionalUpdate(std::string const & newVersion, + LLURI const & uri, + std::string const & hash); + virtual void requiredUpdate(std::string const & newVersion, + LLURI const & uri, + std::string const & hash); virtual void upToDate(void); // LLUpdateDownloader::Client @@ -195,14 +199,18 @@ void LLUpdaterServiceImpl::error(std::string const & message) retry(); } -void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion, LLURI const & uri) +void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion, + LLURI const & uri, + std::string const & hash) { - mUpdateDownloader.download(uri); + mUpdateDownloader.download(uri, hash); } -void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion, LLURI const & uri) +void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion, + LLURI const & uri, + std::string const & hash) { - mUpdateDownloader.download(uri); + mUpdateDownloader.download(uri, hash); } void LLUpdaterServiceImpl::upToDate(void) diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 958526e35b..20d0f8fa09 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -64,7 +64,7 @@ void LLUpdateChecker::check(std::string const & protocolVersion, std::string con std::string const & servicePath, std::string channel, std::string version) {} LLUpdateDownloader::LLUpdateDownloader(Client & ) {} -void LLUpdateDownloader::download(LLURI const & ){} +void LLUpdateDownloader::download(LLURI const & , std::string const &){} /***************************************************************************** * TUT -- cgit v1.2.3 From 4d1e45f20f924f070d0f0139878c2c96e698fb07 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 4 Nov 2010 17:14:12 -0700 Subject: added hash validation of downloaded file. --- .../updater/llupdatedownloader.cpp | 41 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 23772e021e..59e929d99f 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -29,6 +29,7 @@ #include #include "lldir.h" #include "llfile.h" +#include "llmd5.h" #include "llsd.h" #include "llsdserialize.h" #include "llthread.h" @@ -58,6 +59,7 @@ private: void run(void); void startDownloading(LLURI const & uri, std::string const & hash); void throwOnCurlError(CURLcode code); + bool validateDownload(void); LOG_CLASS(LLUpdateDownloader::Implementation); }; @@ -130,6 +132,7 @@ namespace { return bytes; } + size_t header_function(void * data, size_t blockSize, size_t blocks, void * downloader) { size_t bytes = blockSize * blocks; @@ -219,10 +222,18 @@ void LLUpdateDownloader::Implementation::run(void) { CURLcode code = curl_easy_perform(mCurl); if(code == CURLE_OK) { - LL_INFOS("UpdateDownload") << "download successful" << LL_ENDL; - mClient.downloadComplete(); + if(validateDownload()) { + LL_INFOS("UpdateDownload") << "download successful" << LL_ENDL; + mClient.downloadComplete(); + } else { + LL_INFOS("UpdateDownload") << "download failed hash check" << LL_ENDL; + std::string filePath = mDownloadData["path"].asString(); + if(filePath.size() != 0) LLFile::remove(filePath); + mClient.downloadError("failed hash check"); + } } else { - LL_WARNS("UpdateDownload") << "download failed with error " << code << LL_ENDL; + LL_WARNS("UpdateDownload") << "download failed with error '" << + curl_easy_strerror(code) << "'" << LL_ENDL; mClient.downloadError("curl error"); } } @@ -253,6 +264,7 @@ void LLUpdateDownloader::Implementation::resumeDownloading(LLSD const & download { } + /* bool LLUpdateDownloader::Implementation::shouldResumeOngoingDownload(LLURI const & uri, LLSD & downloadData) { @@ -289,8 +301,9 @@ void LLUpdateDownloader::Implementation::startDownloading(LLURI const & uri, std std::string filePath = gDirUtilp->getExpandedFilename(LL_PATH_TEMP, fileName); mDownloadData["path"] = filePath; - LL_INFOS("UpdateDownload") << "downloading " << filePath << "\n" - << "from " << uri.asString() << LL_ENDL; + LL_INFOS("UpdateDownload") << "downloading " << filePath + << " from " << uri.asString() << LL_ENDL; + LL_INFOS("UpdateDownload") << "hash of file is " << hash << LL_ENDL; llofstream dataStream(mDownloadRecordPath); LLSDSerialize parser; @@ -315,3 +328,21 @@ void LLUpdateDownloader::Implementation::throwOnCurlError(CURLcode code) ; // No op. } } + + +bool LLUpdateDownloader::Implementation::validateDownload(void) +{ + std::string filePath = mDownloadData["path"].asString(); + llifstream fileStream(filePath); + if(!fileStream) return false; + + std::string hash = mDownloadData["hash"].asString(); + if(hash.size() != 0) { + LL_INFOS("UpdateDownload") << "checking hash..." << LL_ENDL; + char digest[33]; + LLMD5(fileStream).hex_digest(digest); + return hash == digest; + } else { + return true; // No hash check provided. + } +} -- cgit v1.2.3 From 95d39166faecec2c851285775422c3f668641de2 Mon Sep 17 00:00:00 2001 From: brad kittenbrink Date: Thu, 4 Nov 2010 19:11:40 -0700 Subject: Fix for windows build breakage in teamcity. --- indra/viewer_components/updater/llupdaterservice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 83b09c4bdd..04adf461b6 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -42,7 +42,7 @@ public: LLUpdaterService(); ~LLUpdaterService(); - void setParams(const std::string& version, + void setParams(const std::string& protocol_version, const std::string& url, const std::string& path, const std::string& channel, -- cgit v1.2.3 From 9d7cdc17e311ba5f1f62112e316c531b68f67046 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Fri, 5 Nov 2010 11:12:54 -0700 Subject: resume feature (untested). --- .../updater/llupdatedownloader.cpp | 104 ++++++++++++++------- .../viewer_components/updater/llupdatedownloader.h | 5 +- .../viewer_components/updater/llupdaterservice.cpp | 2 +- 3 files changed, 77 insertions(+), 34 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 59e929d99f..102f2f9eec 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -25,6 +25,7 @@ #include "linden_common.h" #include +#include #include #include #include "lldir.h" @@ -47,6 +48,8 @@ public: bool isDownloading(void); void onHeader(void * header, size_t size); void onBody(void * header, size_t size); + void resume(void); + private: LLUpdateDownloader::Client & mClient; CURL * mCurl; @@ -54,8 +57,8 @@ private: llofstream mDownloadStream; std::string mDownloadRecordPath; - void initializeCurlGet(std::string const & url); - void resumeDownloading(LLSD const & downloadData); + void initializeCurlGet(std::string const & url, bool processHeader); + void resumeDownloading(size_t startByte); void run(void); void startDownloading(LLURI const & uri, std::string const & hash); void throwOnCurlError(CURLcode code); @@ -119,6 +122,12 @@ bool LLUpdateDownloader::isDownloading(void) } +void LLUpdateDownloader::resume(void) +{ + mImplementation->resume(); +} + + // LLUpdateDownloader::Implementation //----------------------------------------------------------------------------- @@ -183,6 +192,45 @@ bool LLUpdateDownloader::Implementation::isDownloading(void) return !isStopped(); } + +void LLUpdateDownloader::Implementation::resume(void) +{ + llifstream dataStream(mDownloadRecordPath); + if(!dataStream) { + mClient.downloadError("no download marker"); + return; + } + + LLSDSerialize parser; + parser.fromXMLDocument(mDownloadData, dataStream); + + if(!mDownloadData.asBoolean()) { + mClient.downloadError("no download information in marker"); + return; + } + + std::string filePath = mDownloadData["path"].asString(); + try { + if(LLFile::isfile(filePath)) { + llstat fileStatus; + LLFile::stat(filePath, &fileStatus); + if(fileStatus.st_size != mDownloadData["size"].asInteger()) { + resumeDownloading(fileStatus.st_size); + } else if(!validateDownload()) { + LLFile::remove(filePath); + download(LLURI(mDownloadData["url"].asString()), mDownloadData["hash"].asString()); + } else { + mClient.downloadComplete(mDownloadData); + } + } else { + download(LLURI(mDownloadData["url"].asString()), mDownloadData["hash"].asString()); + } + } catch(DownloadError & e) { + mClient.downloadError(e.what()); + } +} + + void LLUpdateDownloader::Implementation::onHeader(void * buffer, size_t size) { char const * headerPtr = reinterpret_cast (buffer); @@ -221,10 +269,11 @@ void LLUpdateDownloader::Implementation::onBody(void * buffer, size_t size) void LLUpdateDownloader::Implementation::run(void) { CURLcode code = curl_easy_perform(mCurl); + LLFile::remove(mDownloadRecordPath); if(code == CURLE_OK) { if(validateDownload()) { LL_INFOS("UpdateDownload") << "download successful" << LL_ENDL; - mClient.downloadComplete(); + mClient.downloadComplete(mDownloadData); } else { LL_INFOS("UpdateDownload") << "download failed hash check" << LL_ENDL; std::string filePath = mDownloadData["path"].asString(); @@ -239,7 +288,7 @@ void LLUpdateDownloader::Implementation::run(void) } -void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & url) +void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & url, bool processHeader) { if(mCurl == 0) { mCurl = curl_easy_init(); @@ -253,42 +302,33 @@ void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & u throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_FOLLOWLOCATION, true)); throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, &write_function)); throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, this)); - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HEADERFUNCTION, &header_function)); - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HEADERDATA, this)); + if(processHeader) { + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HEADERFUNCTION, &header_function)); + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HEADERDATA, this)); + } throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HTTPGET, true)); throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_URL, url.c_str())); } -void LLUpdateDownloader::Implementation::resumeDownloading(LLSD const & downloadData) -{ -} - - -/* -bool LLUpdateDownloader::Implementation::shouldResumeOngoingDownload(LLURI const & uri, LLSD & downloadData) +void LLUpdateDownloader::Implementation::resumeDownloading(size_t startByte) { - if(!LLFile::isfile(mDownloadRecordPath)) return false; + initializeCurlGet(mDownloadData["url"].asString(), false); - llifstream dataStream(mDownloadRecordPath); - LLSDSerialize parser; - parser.fromXMLDocument(downloadData, dataStream); + // The header 'Range: bytes n-' will request the bytes remaining in the + // source begining with byte n and ending with the last byte. + boost::format rangeHeaderFormat("Range: bytes=%u-"); + rangeHeaderFormat % startByte; + curl_slist * headerList = 0; + headerList = curl_slist_append(headerList, rangeHeaderFormat.str().c_str()); + if(headerList == 0) throw DownloadError("cannot add Range header"); + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HTTPHEADER, headerList)); + curl_slist_free_all(headerList); - if(downloadData["url"].asString() != uri.asString()) return false; - - std::string downloadedFilePath = downloadData["path"].asString(); - if(LLFile::isfile(downloadedFilePath)) { - llstat fileStatus; - LLFile::stat(downloadedFilePath, &fileStatus); - downloadData["bytes_downloaded"] = LLSD(LLSD::Integer(fileStatus.st_size)); - return true; - } else { - return false; - } - - return true; + mDownloadStream.open(mDownloadData["path"].asString(), + std::ios_base::out | std::ios_base::binary | std::ios_base::app); + start(); } - */ void LLUpdateDownloader::Implementation::startDownloading(LLURI const & uri, std::string const & hash) @@ -310,7 +350,7 @@ void LLUpdateDownloader::Implementation::startDownloading(LLURI const & uri, std parser.toPrettyXML(mDownloadData, dataStream); mDownloadStream.open(filePath, std::ios_base::out | std::ios_base::binary); - initializeCurlGet(uri.asString()); + initializeCurlGet(uri.asString(), true); start(); } diff --git a/indra/viewer_components/updater/llupdatedownloader.h b/indra/viewer_components/updater/llupdatedownloader.h index 8754ea329c..7bfb430879 100644 --- a/indra/viewer_components/updater/llupdatedownloader.h +++ b/indra/viewer_components/updater/llupdatedownloader.h @@ -56,6 +56,9 @@ public: // Returns true if a download is in progress. bool isDownloading(void); + // Resume a partial download. + void resume(void); + private: boost::shared_ptr mImplementation; }; @@ -68,7 +71,7 @@ class LLUpdateDownloader::Client { public: // The download has completed successfully. - virtual void downloadComplete(void) = 0; + virtual void downloadComplete(LLSD const & data) = 0; // The download failed. virtual void downloadError(std::string const & message) = 0; diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 1e0c393539..dc48606cbc 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -99,7 +99,7 @@ public: virtual void upToDate(void); // LLUpdateDownloader::Client - void downloadComplete(void) { retry(); } + void downloadComplete(LLSD const & data) { retry(); } void downloadError(std::string const & message) { retry(); } bool onMainLoop(LLSD const & event); -- cgit v1.2.3 From 6f7183cd4422a008554afd854dc631fe575ad8dc Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Fri, 5 Nov 2010 13:56:36 -0700 Subject: Fixed windows build error. --- indra/viewer_components/updater/llupdatedownloader.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 102f2f9eec..75f896cc76 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -201,8 +201,7 @@ void LLUpdateDownloader::Implementation::resume(void) return; } - LLSDSerialize parser; - parser.fromXMLDocument(mDownloadData, dataStream); + LLSDSerialize::fromXMLDocument(mDownloadData, dataStream); if(!mDownloadData.asBoolean()) { mClient.downloadError("no download information in marker"); @@ -248,8 +247,7 @@ void LLUpdateDownloader::Implementation::onHeader(void * buffer, size_t size) mDownloadData["size"] = LLSD(LLSD::Integer(size)); llofstream odataStream(mDownloadRecordPath); - LLSDSerialize parser; - parser.toPrettyXML(mDownloadData, odataStream); + LLSDSerialize::toPrettyXML(mDownloadData, odataStream); } catch (std::exception const & e) { LL_WARNS("UpdateDownload") << "unable to read content length (" << e.what() << ")" << LL_ENDL; @@ -346,8 +344,7 @@ void LLUpdateDownloader::Implementation::startDownloading(LLURI const & uri, std LL_INFOS("UpdateDownload") << "hash of file is " << hash << LL_ENDL; llofstream dataStream(mDownloadRecordPath); - LLSDSerialize parser; - parser.toPrettyXML(mDownloadData, dataStream); + LLSDSerialize::toPrettyXML(mDownloadData, dataStream); mDownloadStream.open(filePath, std::ios_base::out | std::ios_base::binary); initializeCurlGet(uri.asString(), true); -- cgit v1.2.3 From a13acfc9073b0e29d84e1633fc11ff08e285be8f Mon Sep 17 00:00:00 2001 From: brad kittenbrink Date: Fri, 5 Nov 2010 15:08:27 -0700 Subject: Fixed build error due to unreferenced local variable. --- indra/viewer_components/updater/llupdatedownloader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 75f896cc76..efb55ab83a 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -158,7 +158,7 @@ LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & mDownloadRecordPath(LLUpdateDownloader::downloadMarkerPath()) { CURLcode code = curl_global_init(CURL_GLOBAL_ALL); // Just in case. - llassert(code = CURLE_OK); // TODO: real error handling here. + llverify(code == CURLE_OK); // TODO: real error handling here. } -- cgit v1.2.3 From 02c362b8ccad08f290ca99a738ca6ad1546c7df6 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Fri, 5 Nov 2010 15:56:33 -0700 Subject: implement download cancel (untested). --- .../updater/llupdatedownloader.cpp | 37 +++++++++++++++------- .../viewer_components/updater/llupdatedownloader.h | 3 +- 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 102f2f9eec..eaef230a8f 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -46,11 +46,12 @@ public: void cancel(void); void download(LLURI const & uri, std::string const & hash); bool isDownloading(void); - void onHeader(void * header, size_t size); - void onBody(void * header, size_t size); + size_t onHeader(void * header, size_t size); + size_t onBody(void * header, size_t size); void resume(void); private: + bool mCancelled; LLUpdateDownloader::Client & mClient; CURL * mCurl; LLSD mDownloadData; @@ -137,28 +138,27 @@ namespace { size_t write_function(void * data, size_t blockSize, size_t blocks, void * downloader) { size_t bytes = blockSize * blocks; - reinterpret_cast(downloader)->onBody(data, bytes); - return bytes; + return reinterpret_cast(downloader)->onBody(data, bytes); } size_t header_function(void * data, size_t blockSize, size_t blocks, void * downloader) { size_t bytes = blockSize * blocks; - reinterpret_cast(downloader)->onHeader(data, bytes); - return bytes; + return reinterpret_cast(downloader)->onHeader(data, bytes); } } LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & client): LLThread("LLUpdateDownloader"), + mCancelled(false), mClient(client), mCurl(0), mDownloadRecordPath(LLUpdateDownloader::downloadMarkerPath()) { CURLcode code = curl_global_init(CURL_GLOBAL_ALL); // Just in case. - llassert(code = CURLE_OK); // TODO: real error handling here. + llassert(code == CURLE_OK); // TODO: real error handling here. } @@ -170,7 +170,7 @@ LLUpdateDownloader::Implementation::~Implementation() void LLUpdateDownloader::Implementation::cancel(void) { - llassert(!"not implemented"); + mCancelled = true; } @@ -231,12 +231,12 @@ void LLUpdateDownloader::Implementation::resume(void) } -void LLUpdateDownloader::Implementation::onHeader(void * buffer, size_t size) +size_t LLUpdateDownloader::Implementation::onHeader(void * buffer, size_t size) { char const * headerPtr = reinterpret_cast (buffer); std::string header(headerPtr, headerPtr + size); size_t colonPosition = header.find(':'); - if(colonPosition == std::string::npos) return; // HTML response; ignore. + if(colonPosition == std::string::npos) return size; // HTML response; ignore. if(header.substr(0, colonPosition) == "Content-Length") { try { @@ -257,20 +257,25 @@ void LLUpdateDownloader::Implementation::onHeader(void * buffer, size_t size) } else { ; // No op. } + + return size; } -void LLUpdateDownloader::Implementation::onBody(void * buffer, size_t size) +size_t LLUpdateDownloader::Implementation::onBody(void * buffer, size_t size) { + if(mCancelled) return 0; // Forces a write error which will halt curl thread. + mDownloadStream.write(reinterpret_cast(buffer), size); + return size; } void LLUpdateDownloader::Implementation::run(void) { CURLcode code = curl_easy_perform(mCurl); - LLFile::remove(mDownloadRecordPath); if(code == CURLE_OK) { + LLFile::remove(mDownloadRecordPath); if(validateDownload()) { LL_INFOS("UpdateDownload") << "download successful" << LL_ENDL; mClient.downloadComplete(mDownloadData); @@ -280,9 +285,13 @@ void LLUpdateDownloader::Implementation::run(void) if(filePath.size() != 0) LLFile::remove(filePath); mClient.downloadError("failed hash check"); } + } else if(mCancelled && (code == CURLE_WRITE_ERROR)) { + LL_INFOS("UpdateDownload") << "download canceled by user" << LL_ENDL; + // Do not call back client. } else { LL_WARNS("UpdateDownload") << "download failed with error '" << curl_easy_strerror(code) << "'" << LL_ENDL; + LLFile::remove(mDownloadRecordPath); mClient.downloadError("curl error"); } } @@ -381,6 +390,10 @@ bool LLUpdateDownloader::Implementation::validateDownload(void) LL_INFOS("UpdateDownload") << "checking hash..." << LL_ENDL; char digest[33]; LLMD5(fileStream).hex_digest(digest); + if(hash != digest) { + LL_WARNS("UpdateDownload") << "download hash mismatch; expeted " << hash << + " but download is " << digest << LL_ENDL; + } return hash == digest; } else { return true; // No hash check provided. diff --git a/indra/viewer_components/updater/llupdatedownloader.h b/indra/viewer_components/updater/llupdatedownloader.h index dc8ecc378a..491a638f9a 100644 --- a/indra/viewer_components/updater/llupdatedownloader.h +++ b/indra/viewer_components/updater/llupdatedownloader.h @@ -47,7 +47,8 @@ public: LLUpdateDownloader(Client & client); - // Cancel any in progress download; a no op if none is in progress. + // Cancel any in progress download; a no op if none is in progress. The + // client will not receive a complete or error callback. void cancel(void); // Start a new download. -- cgit v1.2.3 From 1a711b3fd5912776424012fcfcb472baf6c195af Mon Sep 17 00:00:00 2001 From: brad kittenbrink Date: Fri, 5 Nov 2010 18:33:25 -0700 Subject: "Fix" for linux link errors due to library ordering problems on the linker command line. --- indra/viewer_components/updater/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index 64a0f98c2a..563b64655d 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -49,7 +49,6 @@ target_link_libraries(llupdaterservice ${LLMESSAGE_LIBRARIES} ${LLPLUGIN_LIBRARIES} ${LLVFS_LIBRARIES} - ${CURL_LIBRARIES} ) if(LL_TESTS) -- cgit v1.2.3 From e1016b5bc7cda03fed98b10f1ee5615245495e00 Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Mon, 8 Nov 2010 09:49:38 -0800 Subject: Removed refrences to SLPlugin from LLUpdaterService and test. --- .../viewer_components/updater/llupdaterservice.cpp | 30 ---------------------- .../updater/tests/llupdaterservice_test.cpp | 18 ------------- 2 files changed, 48 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index dc48606cbc..4292da1528 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -31,7 +31,6 @@ #include "llupdaterservice.h" #include "llupdatechecker.h" -#include "llpluginprocessparent.h" #include #include @@ -42,7 +41,6 @@ boost::weak_ptr gUpdater; class LLUpdaterServiceImpl : - public LLPluginProcessParentOwner, public LLUpdateChecker::Client, public LLUpdateDownloader::Client { @@ -56,7 +54,6 @@ class LLUpdaterServiceImpl : unsigned int mCheckPeriod; bool mIsChecking; - boost::scoped_ptr mPlugin; LLUpdateChecker mUpdateChecker; LLUpdateDownloader mUpdateDownloader; @@ -70,12 +67,6 @@ public: LLUpdaterServiceImpl(); virtual ~LLUpdaterServiceImpl(); - // LLPluginProcessParentOwner interfaces - virtual void receivePluginMessage(const LLPluginMessage &message); - virtual bool receivePluginMessageEarly(const LLPluginMessage &message); - virtual void pluginLaunchFailed(); - virtual void pluginDied(); - void setParams(const std::string& protocol_version, const std::string& url, const std::string& path, @@ -110,12 +101,9 @@ const std::string LLUpdaterServiceImpl::sListenerName = "LLUpdaterServiceImpl"; LLUpdaterServiceImpl::LLUpdaterServiceImpl() : mIsChecking(false), mCheckPeriod(0), - mPlugin(0), mUpdateChecker(*this), mUpdateDownloader(*this) { - // Create the plugin parent, this is the owner. - mPlugin.reset(new LLPluginProcessParent(this)); } LLUpdaterServiceImpl::~LLUpdaterServiceImpl() @@ -124,24 +112,6 @@ LLUpdaterServiceImpl::~LLUpdaterServiceImpl() LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); } -// LLPluginProcessParentOwner interfaces -void LLUpdaterServiceImpl::receivePluginMessage(const LLPluginMessage &message) -{ -} - -bool LLUpdaterServiceImpl::receivePluginMessageEarly(const LLPluginMessage &message) -{ - return false; -}; - -void LLUpdaterServiceImpl::pluginLaunchFailed() -{ -}; - -void LLUpdaterServiceImpl::pluginDied() -{ -}; - void LLUpdaterServiceImpl::setParams(const std::string& protocol_version, const std::string& url, const std::string& path, diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 20d0f8fa09..7f45ae51fb 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -36,28 +36,10 @@ #include "../../../test/debug.h" #include "llevents.h" -#include "llpluginprocessparent.h" /***************************************************************************** * MOCK'd *****************************************************************************/ -LLPluginProcessParentOwner::~LLPluginProcessParentOwner() {} -LLPluginProcessParent::LLPluginProcessParent(LLPluginProcessParentOwner *owner) -: mOwner(owner), - mIncomingQueueMutex(gAPRPoolp) -{ -} - -LLPluginProcessParent::~LLPluginProcessParent() {} -LLPluginMessagePipeOwner::LLPluginMessagePipeOwner(){} -LLPluginMessagePipeOwner::~LLPluginMessagePipeOwner(){} -void LLPluginProcessParent::receiveMessageRaw(const std::string &message) {} -int LLPluginMessagePipeOwner::socketError(int) { return 0; } -void LLPluginProcessParent::setMessagePipe(LLPluginMessagePipe *message_pipe) {} -void LLPluginMessagePipeOwner::setMessagePipe(class LLPluginMessagePipe *) {} -LLPluginMessage::~LLPluginMessage() {} -LLPluginMessage::LLPluginMessage(LLPluginMessage const&) {} - LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client) {} void LLUpdateChecker::check(std::string const & protocolVersion, std::string const & hostUrl, -- cgit v1.2.3 From d681ea89d27e0e37d77c7f57c9bc66fda3f08f4e Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Mon, 8 Nov 2010 16:10:54 -0800 Subject: Get rid of intrusive_ptr member to prevent crash on shutdown. --- indra/viewer_components/updater/llupdatechecker.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index d31244cc9b..c6aa9b0f11 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -70,7 +70,6 @@ private: Client & mClient; LLHTTPClient mHttpClient; bool mInProgress; - LLHTTPClient::ResponderPtr mMe; std::string mVersion; std::string buildUrl(std::string const & protocolVersion, std::string const & hostUrl, @@ -109,8 +108,7 @@ const char * LLUpdateChecker::Implementation::sProtocolVersion = "v1.0"; LLUpdateChecker::Implementation::Implementation(LLUpdateChecker::Client & client): mClient(client), - mInProgress(false), - mMe(this) + mInProgress(false) { ; // No op. } @@ -118,7 +116,7 @@ LLUpdateChecker::Implementation::Implementation(LLUpdateChecker::Client & client LLUpdateChecker::Implementation::~Implementation() { - mMe.reset(0); + ; // No op. } @@ -136,9 +134,11 @@ void LLUpdateChecker::Implementation::check(std::string const & protocolVersion, // The HTTP client will wrap a raw pointer in a boost::intrusive_ptr causing the // passed object to be silently and automatically deleted. We pass a self- - // referential intrusive pointer stored as an attribute of this class to keep - // the client from deletig the update checker implementation instance. - mHttpClient.get(checkUrl, mMe); + // referential intrusive pointer to which we add a reference to keep the + // client from deleting the update checker implementation instance. + LLHTTPClient::ResponderPtr temporaryPtr(this); + boost::intrusive_ptr_add_ref(temporaryPtr.get()); + mHttpClient.get(checkUrl, temporaryPtr); } void LLUpdateChecker::Implementation::completed(U32 status, -- cgit v1.2.3 From 2cfcdfe2ffd97384324c940447a4197cbf85a38e Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Tue, 9 Nov 2010 09:14:50 -0800 Subject: Fix some stream bugs that were affecting windows download and validation. --- indra/viewer_components/updater/llupdatedownloader.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index ca1d2d25de..2794f80c47 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -272,6 +272,7 @@ size_t LLUpdateDownloader::Implementation::onBody(void * buffer, size_t size) void LLUpdateDownloader::Implementation::run(void) { CURLcode code = curl_easy_perform(mCurl); + mDownloadStream.close(); if(code == CURLE_OK) { LLFile::remove(mDownloadRecordPath); if(validateDownload()) { @@ -379,7 +380,7 @@ void LLUpdateDownloader::Implementation::throwOnCurlError(CURLcode code) bool LLUpdateDownloader::Implementation::validateDownload(void) { std::string filePath = mDownloadData["path"].asString(); - llifstream fileStream(filePath); + llifstream fileStream(filePath, std::ios_base::in | std::ios_base::binary); if(!fileStream) return false; std::string hash = mDownloadData["hash"].asString(); -- cgit v1.2.3 From 5da253fdde8737361333161517c1173358bd17ff Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Tue, 9 Nov 2010 11:16:28 -0800 Subject: Shut down thread if viewer closed while downloading; fix problem of download marker path failing to expand correctly because it was happening too early in start up. --- indra/viewer_components/updater/llupdatedownloader.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 2794f80c47..208cc48c12 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -154,8 +154,7 @@ LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & LLThread("LLUpdateDownloader"), mCancelled(false), mClient(client), - mCurl(0), - mDownloadRecordPath(LLUpdateDownloader::downloadMarkerPath()) + mCurl(0) { CURLcode code = curl_global_init(CURL_GLOBAL_ALL); // Just in case. llverify(code == CURLE_OK); // TODO: real error handling here. @@ -164,6 +163,12 @@ LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & LLUpdateDownloader::Implementation::~Implementation() { + if(isDownloading()) { + cancel(); + shutdown(); + } else { + ; // No op. + } if(mCurl) curl_easy_cleanup(mCurl); } @@ -177,7 +182,8 @@ void LLUpdateDownloader::Implementation::cancel(void) void LLUpdateDownloader::Implementation::download(LLURI const & uri, std::string const & hash) { if(isDownloading()) mClient.downloadError("download in progress"); - + + mDownloadRecordPath = downloadMarkerPath(); mDownloadData = LLSD(); try { startDownloading(uri, hash); @@ -195,6 +201,9 @@ bool LLUpdateDownloader::Implementation::isDownloading(void) void LLUpdateDownloader::Implementation::resume(void) { + if(isDownloading()) mClient.downloadError("download in progress"); + + mDownloadRecordPath = downloadMarkerPath(); llifstream dataStream(mDownloadRecordPath); if(!dataStream) { mClient.downloadError("no download marker"); -- cgit v1.2.3 From fdf616c59d87219e2d5ad6e12687cf2793cfba1e Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Tue, 9 Nov 2010 11:23:32 -0800 Subject: beginnings of the update installer (with simple install script for darwin). --- indra/viewer_components/updater/CMakeLists.txt | 23 ++++++++---- .../updater/llupdateinstaller.cpp | 38 ++++++++++++++++++++ .../viewer_components/updater/llupdateinstaller.h | 42 ++++++++++++++++++++++ .../updater/scripts/darwin/update_install | 6 ++++ 4 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 indra/viewer_components/updater/llupdateinstaller.cpp create mode 100644 indra/viewer_components/updater/llupdateinstaller.h create mode 100755 indra/viewer_components/updater/scripts/darwin/update_install (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index 563b64655d..c3607dff39 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -6,6 +6,7 @@ include(00-Common) if(LL_TESTS) include(LLAddBuildTest) endif(LL_TESTS) +include(CMakeCopyIfDifferent) include(CURL) include(LLCommon) include(LLMessage) @@ -24,12 +25,14 @@ set(updater_service_SOURCE_FILES llupdaterservice.cpp llupdatechecker.cpp llupdatedownloader.cpp + llupdateinstaller.cpp ) set(updater_service_HEADER_FILES llupdaterservice.h llupdatechecker.h llupdatedownloader.h + llupdateinstaller.h ) set_source_files_properties(${updater_service_HEADER_FILES} @@ -56,12 +59,6 @@ if(LL_TESTS) llupdaterservice.cpp ) -# set_source_files_properties( -# llupdaterservice.cpp -# PROPERTIES -# LL_TEST_ADDITIONAL_LIBRARIES "${PTH_LIBRARIES}" -# ) - LL_ADD_PROJECT_UNIT_TESTS(llupdaterservice "${llupdater_service_TEST_SOURCE_FILES}") endif(LL_TESTS) @@ -74,3 +71,17 @@ set(UPDATER_LIBRARIES llupdaterservice CACHE INTERNAL "" ) + +# Copy install script. +if(DARWIN) + copy_if_different( + "${CMAKE_CURRENT_SOURCE_DIR}/scripts/darwin" + "${CMAKE_CURRENT_BINARY_DIR}" + update_installer_targets + "update_install" + ) +endif() +add_custom_target(copy_update_install ALL DEPENDS ${update_installer_targets}) + + + \ No newline at end of file diff --git a/indra/viewer_components/updater/llupdateinstaller.cpp b/indra/viewer_components/updater/llupdateinstaller.cpp new file mode 100644 index 0000000000..4d7c78d36c --- /dev/null +++ b/indra/viewer_components/updater/llupdateinstaller.cpp @@ -0,0 +1,38 @@ +/** + * @file llupdateinstaller.cpp + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" +#include "llprocesslauncher.h" +#include "llupdateinstaller.h" + + +void ll_install_update(std::string const & script, std::string const & updatePath) +{ + LLProcessLauncher launcher; + launcher.setExecutable(script); + launcher.addArgument(updatePath); + launcher.launch(); + launcher.orphan(); +} \ No newline at end of file diff --git a/indra/viewer_components/updater/llupdateinstaller.h b/indra/viewer_components/updater/llupdateinstaller.h new file mode 100644 index 0000000000..a6068e9025 --- /dev/null +++ b/indra/viewer_components/updater/llupdateinstaller.h @@ -0,0 +1,42 @@ +/** + * @file llupdateinstaller.h + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_UPDATE_INSTALLER_H +#define LL_UPDATE_INSTALLER_H + + +#include + + +// +// Launch the installation script. +// +// The updater will overwrite the current installation, so it is highly recommended +// that the current application terminate once this function is called. +// +void ll_install_update(std::string const & script, std::string const & updatePath); + + +#endif \ No newline at end of file diff --git a/indra/viewer_components/updater/scripts/darwin/update_install b/indra/viewer_components/updater/scripts/darwin/update_install new file mode 100755 index 0000000000..24d344ca52 --- /dev/null +++ b/indra/viewer_components/updater/scripts/darwin/update_install @@ -0,0 +1,6 @@ +#! /bin/bash + +hdiutil attach -nobrowse $1 +cp -R /Volumes/Second\ Life\ Installer/Second\ Life\ Viewer\ 2.app /Applications +hdiutil detach /Volumes/Second\ Life\ Installer +open /Applications/Second\ Life\ Viewer\ 2.app \ No newline at end of file -- cgit v1.2.3 From 3493da8c41a157f2cd52632c2ac69b67e4091644 Mon Sep 17 00:00:00 2001 From: brad kittenbrink Date: Tue, 9 Nov 2010 17:42:05 -0800 Subject: Fix for linux eol failures. --- indra/viewer_components/updater/llupdateinstaller.cpp | 2 +- indra/viewer_components/updater/llupdateinstaller.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdateinstaller.cpp b/indra/viewer_components/updater/llupdateinstaller.cpp index 4d7c78d36c..1bb2101df1 100644 --- a/indra/viewer_components/updater/llupdateinstaller.cpp +++ b/indra/viewer_components/updater/llupdateinstaller.cpp @@ -35,4 +35,4 @@ void ll_install_update(std::string const & script, std::string const & updatePat launcher.addArgument(updatePath); launcher.launch(); launcher.orphan(); -} \ No newline at end of file +} diff --git a/indra/viewer_components/updater/llupdateinstaller.h b/indra/viewer_components/updater/llupdateinstaller.h index a6068e9025..991fe2afe1 100644 --- a/indra/viewer_components/updater/llupdateinstaller.h +++ b/indra/viewer_components/updater/llupdateinstaller.h @@ -39,4 +39,4 @@ void ll_install_update(std::string const & script, std::string const & updatePath); -#endif \ No newline at end of file +#endif -- cgit v1.2.3 From deaaad5e3350a57153d7eaf8635e492ab1062c27 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Wed, 10 Nov 2010 10:03:37 -0800 Subject: Add dependency to fix viewer manifest exception in build modes other than all. --- indra/viewer_components/updater/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index c3607dff39..7657dd4517 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -82,6 +82,7 @@ if(DARWIN) ) endif() add_custom_target(copy_update_install ALL DEPENDS ${update_installer_targets}) +add_dependencies(llupdaterservice copy_update_install) \ No newline at end of file -- cgit v1.2.3 From b2e84d739b4f5c00b497e57e892fc10d78af8b76 Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Wed, 10 Nov 2010 14:26:14 -0800 Subject: CHOP-151 Adding startup updater flow to drive update installation and resume. --- indra/viewer_components/updater/CMakeLists.txt | 7 +- .../viewer_components/updater/llupdatedownloader.h | 5 + .../viewer_components/updater/llupdaterservice.cpp | 111 +++++++++++++++++++-- indra/viewer_components/updater/llupdaterservice.h | 20 +++- .../updater/tests/llupdaterservice_test.cpp | 71 ++++++++++++- 5 files changed, 194 insertions(+), 20 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index 64a0f98c2a..980599dd48 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -57,10 +57,13 @@ if(LL_TESTS) llupdaterservice.cpp ) -# set_source_files_properties( +# *NOTE:Mani - I was trying to use the preprocessor seam to mock out +# llifstream (and other) llcommon classes. I didn't work +# because of the windows declspec(dllimport)attribute. +#set_source_files_properties( # llupdaterservice.cpp # PROPERTIES -# LL_TEST_ADDITIONAL_LIBRARIES "${PTH_LIBRARIES}" +# LL_TEST_ADDITIONAL_CFLAGS "-Dllifstream=llus_mock_llifstream" # ) LL_ADD_PROJECT_UNIT_TESTS(llupdaterservice "${llupdater_service_TEST_SOURCE_FILES}") diff --git a/indra/viewer_components/updater/llupdatedownloader.h b/indra/viewer_components/updater/llupdatedownloader.h index dc8ecc378a..fb628c99eb 100644 --- a/indra/viewer_components/updater/llupdatedownloader.h +++ b/indra/viewer_components/updater/llupdatedownloader.h @@ -71,6 +71,11 @@ class LLUpdateDownloader::Client { public: // The download has completed successfully. + // data is a map containing the following items: + // url - source (remote) location + // hash - the md5 sum that should match the installer file. + // path - destination (local) location + // size - the size of the installer in bytes virtual void downloadComplete(LLSD const & data) = 0; // The download failed. diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 4292da1528..4eb317e668 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -33,12 +33,26 @@ #include #include +#include "lldir.h" +#include "llsdserialize.h" +#include "llfile.h" #if LL_WINDOWS #pragma warning (disable : 4355) // 'this' used in initializer list: yes, intentionally #endif -boost::weak_ptr gUpdater; + +namespace +{ + boost::weak_ptr gUpdater; + + const std::string UPDATE_MARKER_FILENAME("SecondLifeUpdateReady.xml"); + std::string update_marker_path() + { + return gDirUtilp->getExpandedFilename(LL_PATH_LOGS, + UPDATE_MARKER_FILENAME); + } +} class LLUpdaterServiceImpl : public LLUpdateChecker::Client, @@ -59,7 +73,7 @@ class LLUpdaterServiceImpl : LLUpdateDownloader mUpdateDownloader; LLTimer mTimer; - void retry(void); + LLUpdaterService::app_exit_callback_t mAppExitCallback; LOG_CLASS(LLUpdaterServiceImpl); @@ -67,7 +81,7 @@ public: LLUpdaterServiceImpl(); virtual ~LLUpdaterServiceImpl(); - void setParams(const std::string& protocol_version, + void initialize(const std::string& protocol_version, const std::string& url, const std::string& path, const std::string& channel, @@ -79,6 +93,11 @@ public: void stopChecking(); bool isChecking(); + void setAppExitCallback(LLUpdaterService::app_exit_callback_t aecb) { mAppExitCallback = aecb;} + + bool checkForInstall(); // Test if a local install is ready. + bool checkForResume(); // Test for resumeable d/l. + // LLUpdateChecker::Client: virtual void error(std::string const & message); virtual void optionalUpdate(std::string const & newVersion, @@ -90,10 +109,14 @@ public: virtual void upToDate(void); // LLUpdateDownloader::Client - void downloadComplete(LLSD const & data) { retry(); } - void downloadError(std::string const & message) { retry(); } + void downloadComplete(LLSD const & data); + void downloadError(std::string const & message); bool onMainLoop(LLSD const & event); + +private: + void retry(void); + }; const std::string LLUpdaterServiceImpl::sListenerName = "LLUpdaterServiceImpl"; @@ -112,8 +135,8 @@ LLUpdaterServiceImpl::~LLUpdaterServiceImpl() LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); } -void LLUpdaterServiceImpl::setParams(const std::string& protocol_version, - const std::string& url, +void LLUpdaterServiceImpl::initialize(const std::string& protocol_version, + const std::string& url, const std::string& path, const std::string& channel, const std::string& version) @@ -129,6 +152,12 @@ void LLUpdaterServiceImpl::setParams(const std::string& protocol_version, mPath = path; mChannel = channel; mVersion = version; + + // Check to see if an install is ready. + if(!checkForInstall()) + { + checkForResume(); + } } void LLUpdaterServiceImpl::setCheckPeriod(unsigned int seconds) @@ -146,7 +175,7 @@ void LLUpdaterServiceImpl::startChecking() "LLUpdaterService::startCheck()."); } mIsChecking = true; - + mUpdateChecker.check(mProtocolVersion, mUrl, mPath, mChannel, mVersion); } } @@ -164,6 +193,45 @@ bool LLUpdaterServiceImpl::isChecking() return mIsChecking; } +bool LLUpdaterServiceImpl::checkForInstall() +{ + bool result = false; // return true if install is found. + + llifstream update_marker(update_marker_path(), + std::ios::in | std::ios::binary); + + if(update_marker.is_open()) + { + // Found an update info - now lets see if its valid. + LLSD update_info; + LLSDSerialize::fromXMLDocument(update_info, update_marker); + + // Get the path to the installer file. + LLSD path = update_info.get("path"); + if(path.isDefined() && !path.asString().empty()) + { + // install! + } + + update_marker.close(); + LLFile::remove(update_marker_path()); + result = true; + } + return result; +} + +bool LLUpdaterServiceImpl::checkForResume() +{ + bool result = false; + llstat stat_info; + if(0 == LLFile::stat(mUpdateDownloader.downloadMarkerPath(), &stat_info)) + { + mUpdateDownloader.resume(); + result = true; + } + return false; +} + void LLUpdaterServiceImpl::error(std::string const & message) { retry(); @@ -188,6 +256,24 @@ void LLUpdaterServiceImpl::upToDate(void) retry(); } +void LLUpdaterServiceImpl::downloadComplete(LLSD const & data) +{ + // Save out the download data to the SecondLifeUpdateReady + // marker file. + llofstream update_marker(update_marker_path()); + LLSDSerialize::toPrettyXML(data, update_marker); + + // Stop checking. + stopChecking(); + + // Wait for restart...? +} + +void LLUpdaterServiceImpl::downloadError(std::string const & message) +{ + retry(); +} + void LLUpdaterServiceImpl::retry(void) { LL_INFOS("UpdaterService") << "will check for update again in " << @@ -233,13 +319,13 @@ LLUpdaterService::~LLUpdaterService() { } -void LLUpdaterService::setParams(const std::string& protocol_version, +void LLUpdaterService::initialize(const std::string& protocol_version, const std::string& url, const std::string& path, const std::string& channel, const std::string& version) { - mImpl->setParams(protocol_version, url, path, channel, version); + mImpl->initialize(protocol_version, url, path, channel, version); } void LLUpdaterService::setCheckPeriod(unsigned int seconds) @@ -261,3 +347,8 @@ bool LLUpdaterService::isChecking() { return mImpl->isChecking(); } + +void LLUpdaterService::setImplAppExitCallback(LLUpdaterService::app_exit_callback_t aecb) +{ + return mImpl->setAppExitCallback(aecb); +} diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 04adf461b6..42ec3a2cab 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -27,6 +27,7 @@ #define LL_UPDATERSERVICE_H #include +#include class LLUpdaterServiceImpl; @@ -42,11 +43,11 @@ public: LLUpdaterService(); ~LLUpdaterService(); - void setParams(const std::string& protocol_version, - const std::string& url, - const std::string& path, - const std::string& channel, - const std::string& version); + void initialize(const std::string& protocol_version, + const std::string& url, + const std::string& path, + const std::string& channel, + const std::string& version); void setCheckPeriod(unsigned int seconds); @@ -54,8 +55,17 @@ public: void stopChecking(); bool isChecking(); + typedef boost::function app_exit_callback_t; + template + void setAppExitCallback(F const &callable) + { + app_exit_callback_t aecb = callable; + setImplAppExitCallback(aecb); + } + private: boost::shared_ptr mImpl; + void setImplAppExitCallback(app_exit_callback_t aecb); }; #endif // LL_UPDATERSERVICE_H diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 7f45ae51fb..57732ad0a5 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -36,6 +36,7 @@ #include "../../../test/debug.h" #include "llevents.h" +#include "lldir.h" /***************************************************************************** * MOCK'd @@ -48,6 +49,70 @@ void LLUpdateChecker::check(std::string const & protocolVersion, std::string con LLUpdateDownloader::LLUpdateDownloader(Client & ) {} void LLUpdateDownloader::download(LLURI const & , std::string const &){} +class LLDir_Mock : public LLDir +{ + void initAppDirs(const std::string &app_name, + const std::string& app_read_only_data_dir = "") {} + U32 countFilesInDir(const std::string &dirname, const std::string &mask) + { + return 0; + } + + BOOL getNextFileInDir(const std::string &dirname, + const std::string &mask, + std::string &fname, BOOL wrap) + { + return false; + } + void getRandomFileInDir(const std::string &dirname, + const std::string &mask, + std::string &fname) {} + std::string getCurPath() { return ""; } + BOOL fileExists(const std::string &filename) const { return false; } + std::string getLLPluginLauncher() { return ""; } + std::string getLLPluginFilename(std::string base_name) { return ""; } + +} gDirUtil; +LLDir* gDirUtilp = &gDirUtil; +LLDir::LLDir() {} +LLDir::~LLDir() {} +S32 LLDir::deleteFilesInDir(const std::string &dirname, + const std::string &mask) +{ return 0; } + +void LLDir::setChatLogsDir(const std::string &path){} +void LLDir::setPerAccountChatLogsDir(const std::string &username){} +void LLDir::setLindenUserDir(const std::string &username){} +void LLDir::setSkinFolder(const std::string &skin_folder){} +bool LLDir::setCacheDir(const std::string &path){ return true; } +void LLDir::dumpCurrentDirectories() {} + +std::string LLDir::getExpandedFilename(ELLPath location, + const std::string &filename) const +{ + return ""; +} + +std::string LLUpdateDownloader::downloadMarkerPath(void) +{ + return ""; +} + +void LLUpdateDownloader::resume(void) {} + +/* +#pragma warning(disable: 4273) +llus_mock_llifstream::llus_mock_llifstream(const std::string& _Filename, + ios_base::openmode _Mode, + int _Prot) : + std::basic_istream >(NULL,true) +{} + +llus_mock_llifstream::~llus_mock_llifstream() {} +bool llus_mock_llifstream::is_open() const {return true;} +void llus_mock_llifstream::close() {} +*/ + /***************************************************************************** * TUT *****************************************************************************/ @@ -96,9 +161,9 @@ namespace tut bool got_usage_error = false; try { - updater.setParams("1.0",test_url, "update" ,test_channel, test_version); + updater.initialize("1.0",test_url, "update" ,test_channel, test_version); updater.startChecking(); - updater.setParams("1.0", "other_url", "update", test_channel, test_version); + updater.initialize("1.0", "other_url", "update", test_channel, test_version); } catch(LLUpdaterService::UsageError) { @@ -112,7 +177,7 @@ namespace tut { DEBUG; LLUpdaterService updater; - updater.setParams("1.0", test_url, "update", test_channel, test_version); + updater.initialize("1.0", test_url, "update", test_channel, test_version); updater.startChecking(); ensure(updater.isChecking()); updater.stopChecking(); -- cgit v1.2.3 From 41ec2e01ddf12c7d9fc57a115b1e6047560c7e5e Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Wed, 10 Nov 2010 14:30:11 -0800 Subject: copy script to temp if needed before installing. --- .../updater/llupdateinstaller.cpp | 44 ++++++++++++++++++++-- .../viewer_components/updater/llupdateinstaller.h | 10 ++++- 2 files changed, 50 insertions(+), 4 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdateinstaller.cpp b/indra/viewer_components/updater/llupdateinstaller.cpp index 1bb2101df1..52744b0479 100644 --- a/indra/viewer_components/updater/llupdateinstaller.cpp +++ b/indra/viewer_components/updater/llupdateinstaller.cpp @@ -24,15 +24,53 @@ */ #include "linden_common.h" +#include +#include "llapr.h" #include "llprocesslauncher.h" #include "llupdateinstaller.h" +#include "lldir.h" -void ll_install_update(std::string const & script, std::string const & updatePath) +namespace { + class RelocateError {}; + + + std::string copy_to_temp(std::string const & path) + { + std::string scriptFile = gDirUtilp->getBaseFileName(path); + std::string newPath = gDirUtilp->getExpandedFilename(LL_PATH_TEMP, scriptFile); + apr_status_t status = apr_file_copy(path.c_str(), newPath.c_str(), APR_FILE_SOURCE_PERMS, gAPRPoolp); + if(status != APR_SUCCESS) throw RelocateError(); + + return newPath; + } +} + + +int ll_install_update(std::string const & script, std::string const & updatePath, LLInstallScriptMode mode) { + std::string finalPath; + switch(mode) { + case LL_COPY_INSTALL_SCRIPT_TO_TEMP: + try { + finalPath = copy_to_temp(updatePath); + } + catch (RelocateError &) { + return -1; + } + break; + case LL_RUN_INSTALL_SCRIPT_IN_PLACE: + finalPath = updatePath; + break; + default: + llassert(!"unpossible copy mode"); + } + LLProcessLauncher launcher; launcher.setExecutable(script); - launcher.addArgument(updatePath); - launcher.launch(); + launcher.addArgument(finalPath); + int result = launcher.launch(); launcher.orphan(); + + return result; } diff --git a/indra/viewer_components/updater/llupdateinstaller.h b/indra/viewer_components/updater/llupdateinstaller.h index 991fe2afe1..310bfe4348 100644 --- a/indra/viewer_components/updater/llupdateinstaller.h +++ b/indra/viewer_components/updater/llupdateinstaller.h @@ -30,13 +30,21 @@ #include +enum LLInstallScriptMode { + LL_RUN_INSTALL_SCRIPT_IN_PLACE, + LL_COPY_INSTALL_SCRIPT_TO_TEMP +}; + // // Launch the installation script. // // The updater will overwrite the current installation, so it is highly recommended // that the current application terminate once this function is called. // -void ll_install_update(std::string const & script, std::string const & updatePath); +int ll_install_update( + std::string const & script, // Script to execute. + std::string const & updatePath, // Path to update file. + LLInstallScriptMode mode=LL_COPY_INSTALL_SCRIPT_TO_TEMP); // Run in place or copy to temp? #endif -- cgit v1.2.3 From dcf4ddacd81e3864525c44f145514911116daebd Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Wed, 10 Nov 2010 15:15:25 -0800 Subject: fix race between resume and download check. --- indra/viewer_components/updater/llupdaterservice.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 4eb317e668..28d9075efa 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -137,9 +137,9 @@ LLUpdaterServiceImpl::~LLUpdaterServiceImpl() void LLUpdaterServiceImpl::initialize(const std::string& protocol_version, const std::string& url, - const std::string& path, - const std::string& channel, - const std::string& version) + const std::string& path, + const std::string& channel, + const std::string& version) { if(mIsChecking) { @@ -226,6 +226,7 @@ bool LLUpdaterServiceImpl::checkForResume() llstat stat_info; if(0 == LLFile::stat(mUpdateDownloader.downloadMarkerPath(), &stat_info)) { + mIsChecking = true; mUpdateDownloader.resume(); result = true; } -- cgit v1.2.3 From 94942671fa81ad0da3682af31b715ca49f8e3bef Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Wed, 10 Nov 2010 15:23:26 -0800 Subject: fix resume crash. --- .../viewer_components/updater/llupdatedownloader.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 208cc48c12..21555dc3ff 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -57,6 +57,7 @@ private: LLSD mDownloadData; llofstream mDownloadStream; std::string mDownloadRecordPath; + curl_slist * mHeaderList; void initializeCurlGet(std::string const & url, bool processHeader); void resumeDownloading(size_t startByte); @@ -154,7 +155,8 @@ LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & LLThread("LLUpdateDownloader"), mCancelled(false), mClient(client), - mCurl(0) + mCurl(0), + mHeaderList(0) { CURLcode code = curl_global_init(CURL_GLOBAL_ALL); // Just in case. llverify(code == CURLE_OK); // TODO: real error handling here. @@ -302,6 +304,11 @@ void LLUpdateDownloader::Implementation::run(void) LLFile::remove(mDownloadRecordPath); mClient.downloadError("curl error"); } + + if(mHeaderList) { + curl_slist_free_all(mHeaderList); + mHeaderList = 0; + } } @@ -330,17 +337,18 @@ void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & u void LLUpdateDownloader::Implementation::resumeDownloading(size_t startByte) { + LL_INFOS("UpdateDownload") << "resuming download from " << mDownloadData["url"].asString() + << " at byte " << startByte << LL_ENDL; + initializeCurlGet(mDownloadData["url"].asString(), false); // The header 'Range: bytes n-' will request the bytes remaining in the // source begining with byte n and ending with the last byte. boost::format rangeHeaderFormat("Range: bytes=%u-"); rangeHeaderFormat % startByte; - curl_slist * headerList = 0; - headerList = curl_slist_append(headerList, rangeHeaderFormat.str().c_str()); - if(headerList == 0) throw DownloadError("cannot add Range header"); - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HTTPHEADER, headerList)); - curl_slist_free_all(headerList); + mHeaderList = curl_slist_append(mHeaderList, rangeHeaderFormat.str().c_str()); + if(mHeaderList == 0) throw DownloadError("cannot add Range header"); + throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HTTPHEADER, mHeaderList)); mDownloadStream.open(mDownloadData["path"].asString(), std::ios_base::out | std::ios_base::binary | std::ios_base::app); -- cgit v1.2.3 From 41517715844c986aab169502c94f39a9f507eb55 Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Wed, 10 Nov 2010 19:21:03 -0800 Subject: CHOP-151 Hooked up app exit callback, cleaned up early exit. Rev. by Brad --- .../viewer_components/updater/llupdaterservice.cpp | 86 ++++++++++++++-------- .../updater/tests/llupdaterservice_test.cpp | 12 +-- 2 files changed, 62 insertions(+), 36 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 28d9075efa..466b27f6fe 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -68,6 +68,7 @@ class LLUpdaterServiceImpl : unsigned int mCheckPeriod; bool mIsChecking; + bool mIsDownloading; LLUpdateChecker mUpdateChecker; LLUpdateDownloader mUpdateDownloader; @@ -115,14 +116,14 @@ public: bool onMainLoop(LLSD const & event); private: - void retry(void); - + void restartTimer(unsigned int seconds); }; const std::string LLUpdaterServiceImpl::sListenerName = "LLUpdaterServiceImpl"; LLUpdaterServiceImpl::LLUpdaterServiceImpl() : mIsChecking(false), + mIsDownloading(false), mCheckPeriod(0), mUpdateChecker(*this), mUpdateDownloader(*this) @@ -141,10 +142,10 @@ void LLUpdaterServiceImpl::initialize(const std::string& protocol_version, const std::string& channel, const std::string& version) { - if(mIsChecking) + if(mIsChecking || mIsDownloading) { - throw LLUpdaterService::UsageError("Call LLUpdaterService::stopCheck()" - " before setting params."); + throw LLUpdaterService::UsageError("LLUpdaterService::initialize call " + "while updater is running."); } mProtocolVersion = protocol_version; @@ -167,16 +168,20 @@ void LLUpdaterServiceImpl::setCheckPeriod(unsigned int seconds) void LLUpdaterServiceImpl::startChecking() { - if(!mIsChecking) + if(mUrl.empty() || mChannel.empty() || mVersion.empty()) { - if(mUrl.empty() || mChannel.empty() || mVersion.empty()) - { - throw LLUpdaterService::UsageError("Set params before call to " - "LLUpdaterService::startCheck()."); - } - mIsChecking = true; - - mUpdateChecker.check(mProtocolVersion, mUrl, mPath, mChannel, mVersion); + throw LLUpdaterService::UsageError("Set params before call to " + "LLUpdaterService::startCheck()."); + } + + mIsChecking = true; + + if(!mIsDownloading) + { + // Checking can only occur during the mainloop. + // reset the timer to 0 so that the next mainloop event + // triggers a check; + restartTimer(0); } } @@ -185,6 +190,7 @@ void LLUpdaterServiceImpl::stopChecking() if(mIsChecking) { mIsChecking = false; + mTimer.stop(); } } @@ -205,16 +211,21 @@ bool LLUpdaterServiceImpl::checkForInstall() // Found an update info - now lets see if its valid. LLSD update_info; LLSDSerialize::fromXMLDocument(update_info, update_marker); + update_marker.close(); + LLFile::remove(update_marker_path()); // Get the path to the installer file. LLSD path = update_info.get("path"); if(path.isDefined() && !path.asString().empty()) { // install! + + if(mAppExitCallback) + { + mAppExitCallback(); + } } - update_marker.close(); - LLFile::remove(update_marker_path()); result = true; } return result; @@ -226,7 +237,7 @@ bool LLUpdaterServiceImpl::checkForResume() llstat stat_info; if(0 == LLFile::stat(mUpdateDownloader.downloadMarkerPath(), &stat_info)) { - mIsChecking = true; + mIsDownloading = true; mUpdateDownloader.resume(); result = true; } @@ -235,13 +246,18 @@ bool LLUpdaterServiceImpl::checkForResume() void LLUpdaterServiceImpl::error(std::string const & message) { - retry(); + if(mIsChecking) + { + restartTimer(mCheckPeriod); + } } void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion, LLURI const & uri, std::string const & hash) { + mTimer.stop(); + mIsDownloading = true; mUpdateDownloader.download(uri, hash); } @@ -249,50 +265,60 @@ void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion, LLURI const & uri, std::string const & hash) { + mTimer.stop(); + mIsDownloading = true; mUpdateDownloader.download(uri, hash); } void LLUpdaterServiceImpl::upToDate(void) { - retry(); + if(mIsChecking) + { + restartTimer(mCheckPeriod); + } } void LLUpdaterServiceImpl::downloadComplete(LLSD const & data) { + mIsDownloading = false; + // Save out the download data to the SecondLifeUpdateReady - // marker file. + // marker file. llofstream update_marker(update_marker_path()); LLSDSerialize::toPrettyXML(data, update_marker); - - // Stop checking. - stopChecking(); - - // Wait for restart...? } void LLUpdaterServiceImpl::downloadError(std::string const & message) { - retry(); + mIsDownloading = false; + + // Restart the + if(mIsChecking) + { + restartTimer(mCheckPeriod); + } } -void LLUpdaterServiceImpl::retry(void) +void LLUpdaterServiceImpl::restartTimer(unsigned int seconds) { LL_INFOS("UpdaterService") << "will check for update again in " << mCheckPeriod << " seconds" << LL_ENDL; mTimer.start(); - mTimer.setTimerExpirySec(mCheckPeriod); + mTimer.setTimerExpirySec(seconds); LLEventPumps::instance().obtain("mainloop").listen( sListenerName, boost::bind(&LLUpdaterServiceImpl::onMainLoop, this, _1)); } bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) { - if(mTimer.hasExpired()) + if(mTimer.getStarted() && mTimer.hasExpired()) { mTimer.stop(); LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); mUpdateChecker.check(mProtocolVersion, mUrl, mPath, mChannel, mVersion); - } else { + } + else + { // Keep on waiting... } diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 57732ad0a5..aa30fa717d 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -102,12 +102,12 @@ void LLUpdateDownloader::resume(void) {} /* #pragma warning(disable: 4273) -llus_mock_llifstream::llus_mock_llifstream(const std::string& _Filename, - ios_base::openmode _Mode, - int _Prot) : - std::basic_istream >(NULL,true) -{} - +llus_mock_llifstream::llus_mock_llifstream(const std::string& _Filename, + ios_base::openmode _Mode, + int _Prot) : + std::basic_istream >(NULL,true) +{} + llus_mock_llifstream::~llus_mock_llifstream() {} bool llus_mock_llifstream::is_open() const {return true;} void llus_mock_llifstream::close() {} -- cgit v1.2.3 From 6e15957d909787ba612004903f04335a593b5348 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 11 Nov 2010 09:40:30 -0800 Subject: run install script on successful download --- .../updater/llupdateinstaller.cpp | 13 +++++---- .../viewer_components/updater/llupdaterservice.cpp | 33 ++++++++++++++++++++-- .../updater/tests/llupdaterservice_test.cpp | 6 ++++ 3 files changed, 44 insertions(+), 8 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdateinstaller.cpp b/indra/viewer_components/updater/llupdateinstaller.cpp index 52744b0479..10d5edc6a0 100644 --- a/indra/viewer_components/updater/llupdateinstaller.cpp +++ b/indra/viewer_components/updater/llupdateinstaller.cpp @@ -49,26 +49,29 @@ namespace { int ll_install_update(std::string const & script, std::string const & updatePath, LLInstallScriptMode mode) { - std::string finalPath; + std::string actualScriptPath; switch(mode) { case LL_COPY_INSTALL_SCRIPT_TO_TEMP: try { - finalPath = copy_to_temp(updatePath); + actualScriptPath = copy_to_temp(script); } catch (RelocateError &) { return -1; } break; case LL_RUN_INSTALL_SCRIPT_IN_PLACE: - finalPath = updatePath; + actualScriptPath = script; break; default: llassert(!"unpossible copy mode"); } + llinfos << "UpdateInstaller: installing " << updatePath << " using " << + actualScriptPath << LL_ENDL; + LLProcessLauncher launcher; - launcher.setExecutable(script); - launcher.addArgument(finalPath); + launcher.setExecutable(actualScriptPath); + launcher.addArgument(updatePath); int result = launcher.launch(); launcher.orphan(); diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 466b27f6fe..43551d6cea 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -30,6 +30,7 @@ #include "lltimer.h" #include "llupdaterservice.h" #include "llupdatechecker.h" +#include "llupdateinstaller.h" #include #include @@ -52,6 +53,26 @@ namespace return gDirUtilp->getExpandedFilename(LL_PATH_LOGS, UPDATE_MARKER_FILENAME); } + + std::string install_script_path(void) + { +#ifdef LL_WINDOWS + std::string scriptFile = "update_install.bat"; +#else + std::string scriptFile = "update_install"; +#endif + return gDirUtilp->getExpandedFilename(LL_PATH_EXECUTABLE, scriptFile); + } + + LLInstallScriptMode install_script_mode(void) + { +#ifdef LL_WINDOWS + return LL_COPY_INSTALL_SCRIPT_TO_TEMP; +#else + return LL_RUN_INSTALL_SCRIPT_IN_PLACE; +#endif + }; + } class LLUpdaterServiceImpl : @@ -218,11 +239,17 @@ bool LLUpdaterServiceImpl::checkForInstall() LLSD path = update_info.get("path"); if(path.isDefined() && !path.asString().empty()) { - // install! - - if(mAppExitCallback) + int result = ll_install_update(install_script_path(), + update_info["path"].asString(), + install_script_mode()); + + if((result == 0) && mAppExitCallback) { mAppExitCallback(); + } else if(result != 0) { + llwarns << "failed to run update install script" << LL_ENDL; + } else { + ; // No op. } } diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index aa30fa717d..9b56a04ff6 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -30,6 +30,7 @@ #include "../llupdaterservice.h" #include "../llupdatechecker.h" #include "../llupdatedownloader.h" +#include "../llupdateinstaller.h" #include "../../../test/lltut.h" //#define DEBUG_ON @@ -100,6 +101,11 @@ std::string LLUpdateDownloader::downloadMarkerPath(void) void LLUpdateDownloader::resume(void) {} +int ll_install_update(std::string const &, std::string const &, LLInstallScriptMode) +{ + return 0; +} + /* #pragma warning(disable: 4273) llus_mock_llifstream::llus_mock_llifstream(const std::string& _Filename, -- cgit v1.2.3 From 4e22d63352dd65085cfbba9c22070271ecdd4bcf Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 11 Nov 2010 11:05:46 -0800 Subject: Add very basic windows install script. --- indra/viewer_components/updater/CMakeLists.txt | 7 +++++++ indra/viewer_components/updater/scripts/windows/update_install.bat | 1 + 2 files changed, 8 insertions(+) create mode 100644 indra/viewer_components/updater/scripts/windows/update_install.bat (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index c5ccfbf66a..469c0cf05e 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -89,6 +89,13 @@ if(DARWIN) update_installer_targets "update_install" ) +elseif(WINDOWS) + copy_if_different( + "${CMAKE_CURRENT_SOURCE_DIR}/scripts/windows" + "${CMAKE_CURRENT_BINARY_DIR}" + update_installer_targets + "update_install.bat" + ) endif() add_custom_target(copy_update_install ALL DEPENDS ${update_installer_targets}) add_dependencies(llupdaterservice copy_update_install) diff --git a/indra/viewer_components/updater/scripts/windows/update_install.bat b/indra/viewer_components/updater/scripts/windows/update_install.bat new file mode 100644 index 0000000000..def33c1346 --- /dev/null +++ b/indra/viewer_components/updater/scripts/windows/update_install.bat @@ -0,0 +1 @@ +start /WAIT %1 \ No newline at end of file -- cgit v1.2.3 From 830afa5b27092668517b2f5670e892143de3cf66 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 11 Nov 2010 16:45:38 -0800 Subject: hacking mac updater to install from local dmg --- indra/viewer_components/updater/scripts/darwin/update_install | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) mode change 100644 => 100755 indra/viewer_components/updater/scripts/darwin/update_install (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/scripts/darwin/update_install b/indra/viewer_components/updater/scripts/darwin/update_install old mode 100644 new mode 100755 index 24d344ca52..c061d2818f --- a/indra/viewer_components/updater/scripts/darwin/update_install +++ b/indra/viewer_components/updater/scripts/darwin/update_install @@ -1,6 +1,3 @@ #! /bin/bash -hdiutil attach -nobrowse $1 -cp -R /Volumes/Second\ Life\ Installer/Second\ Life\ Viewer\ 2.app /Applications -hdiutil detach /Volumes/Second\ Life\ Installer -open /Applications/Second\ Life\ Viewer\ 2.app \ No newline at end of file +open ../Resources/mac-updater.app --args -dmg "$1" -name "Second Life Viewer 2" -- cgit v1.2.3 From 1368a94f014884588b343802eef5fd2c7888390a Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Fri, 12 Nov 2010 12:23:30 -0800 Subject: do not resume or install if current viewer version doesn't match the recorded version which started the process. --- .../updater/llupdatedownloader.cpp | 2 + .../viewer_components/updater/llupdaterservice.cpp | 71 +++++++++++++++++++--- indra/viewer_components/updater/llupdaterservice.h | 3 + 3 files changed, 67 insertions(+), 9 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 21555dc3ff..ab441aa747 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -35,6 +35,7 @@ #include "llsdserialize.h" #include "llthread.h" #include "llupdatedownloader.h" +#include "llupdaterservice.h" class LLUpdateDownloader::Implementation: @@ -360,6 +361,7 @@ void LLUpdateDownloader::Implementation::startDownloading(LLURI const & uri, std { mDownloadData["url"] = uri.asString(); mDownloadData["hash"] = hash; + mDownloadData["current_version"] = ll_get_version(); LLSD path = uri.pathArray(); if(path.size() == 0) throw DownloadError("no file path"); std::string fileName = path[path.size() - 1].asString(); diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 43551d6cea..6cc872f2ca 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -31,6 +31,7 @@ #include "llupdaterservice.h" #include "llupdatechecker.h" #include "llupdateinstaller.h" +#include "llversionviewer.h" #include #include @@ -237,7 +238,23 @@ bool LLUpdaterServiceImpl::checkForInstall() // Get the path to the installer file. LLSD path = update_info.get("path"); - if(path.isDefined() && !path.asString().empty()) + if(update_info["current_version"].asString() != ll_get_version()) + { + // This viewer is not the same version as the one that downloaded + // the update. Do not install this update. + if(!path.asString().empty()) + { + llinfos << "ignoring update dowloaded by different client version" << llendl; + LLFile::remove(path.asString()); + } + else + { + ; // Nothing to clean up. + } + + result = false; + } + else if(path.isDefined() && !path.asString().empty()) { int result = ll_install_update(install_script_path(), update_info["path"].asString(), @@ -251,9 +268,9 @@ bool LLUpdaterServiceImpl::checkForInstall() } else { ; // No op. } + + result = true; } - - result = true; } return result; } @@ -261,14 +278,33 @@ bool LLUpdaterServiceImpl::checkForInstall() bool LLUpdaterServiceImpl::checkForResume() { bool result = false; - llstat stat_info; - if(0 == LLFile::stat(mUpdateDownloader.downloadMarkerPath(), &stat_info)) + std::string download_marker_path = mUpdateDownloader.downloadMarkerPath(); + if(LLFile::isfile(download_marker_path)) { - mIsDownloading = true; - mUpdateDownloader.resume(); - result = true; + llifstream download_marker_stream(download_marker_path, + std::ios::in | std::ios::binary); + if(download_marker_stream.is_open()) + { + LLSD download_info; + LLSDSerialize::fromXMLDocument(download_info, download_marker_stream); + download_marker_stream.close(); + if(download_info["current_version"].asString() == ll_get_version()) + { + mIsDownloading = true; + mUpdateDownloader.resume(); + result = true; + } + else + { + // The viewer that started this download is not the same as this viewer; ignore. + llinfos << "ignoring partial download from different viewer version" << llendl; + std::string path = download_info["path"].asString(); + if(!path.empty()) LLFile::remove(path); + LLFile::remove(download_marker_path); + } + } } - return false; + return result; } void LLUpdaterServiceImpl::error(std::string const & message) @@ -406,3 +442,20 @@ void LLUpdaterService::setImplAppExitCallback(LLUpdaterService::app_exit_callbac { return mImpl->setAppExitCallback(aecb); } + + +std::string const & ll_get_version(void) { + static std::string version(""); + + if (version.empty()) { + std::ostringstream stream; + stream << LL_VERSION_MAJOR << "." + << LL_VERSION_MINOR << "." + << LL_VERSION_PATCH << "." + << LL_VERSION_BUILD; + version = stream.str(); + } + + return version; +} + diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 42ec3a2cab..ec20dc6e05 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -68,4 +68,7 @@ private: void setImplAppExitCallback(app_exit_callback_t aecb); }; +// Returns the full version as a string. +std::string const & ll_get_version(void); + #endif // LL_UPDATERSERVICE_H -- cgit v1.2.3 From ec7d36f6cfbed53a30d918415dfa3e429a645ce1 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Mon, 15 Nov 2010 09:38:20 -0800 Subject: added mechanism for install scripts to indicate a failed install and for update service to note the failure; modified mac installer to write marker on error. --- indra/viewer_components/updater/llupdateinstaller.cpp | 11 +++++++++++ indra/viewer_components/updater/llupdateinstaller.h | 7 +++++++ indra/viewer_components/updater/llupdaterservice.cpp | 14 +++++++++++++- .../updater/scripts/darwin/update_install | 8 +++++++- .../updater/tests/llupdaterservice_test.cpp | 6 ++++++ 5 files changed, 44 insertions(+), 2 deletions(-) mode change 100644 => 100755 indra/viewer_components/updater/scripts/darwin/update_install (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdateinstaller.cpp b/indra/viewer_components/updater/llupdateinstaller.cpp index 10d5edc6a0..6e69bcf28b 100644 --- a/indra/viewer_components/updater/llupdateinstaller.cpp +++ b/indra/viewer_components/updater/llupdateinstaller.cpp @@ -72,8 +72,19 @@ int ll_install_update(std::string const & script, std::string const & updatePath LLProcessLauncher launcher; launcher.setExecutable(actualScriptPath); launcher.addArgument(updatePath); + launcher.addArgument(ll_install_failed_marker_path().c_str()); int result = launcher.launch(); launcher.orphan(); return result; } + + +std::string const & ll_install_failed_marker_path(void) +{ + static std::string path; + if(path.empty()) { + path = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "SecondLifeInstallFailed.marker"); + } + return path; +} diff --git a/indra/viewer_components/updater/llupdateinstaller.h b/indra/viewer_components/updater/llupdateinstaller.h index 310bfe4348..6ce08ce6fa 100644 --- a/indra/viewer_components/updater/llupdateinstaller.h +++ b/indra/viewer_components/updater/llupdateinstaller.h @@ -47,4 +47,11 @@ int ll_install_update( LLInstallScriptMode mode=LL_COPY_INSTALL_SCRIPT_TO_TEMP); // Run in place or copy to temp? +// +// Returns the path which points to the failed install marker file, should it +// exist. +// +std::string const & ll_install_failed_marker_path(void); + + #endif diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 6cc872f2ca..a1ad3e3381 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -378,7 +378,19 @@ bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) { mTimer.stop(); LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); - mUpdateChecker.check(mProtocolVersion, mUrl, mPath, mChannel, mVersion); + + // Check for failed install. + if(LLFile::isfile(ll_install_failed_marker_path())) + { + // TODO: notify the user. + llinfos << "found marker " << ll_install_failed_marker_path() << llendl; + llinfos << "last install attempt failed" << llendl; + LLFile::remove(ll_install_failed_marker_path()); + } + else + { + mUpdateChecker.check(mProtocolVersion, mUrl, mPath, mChannel, mVersion); + } } else { diff --git a/indra/viewer_components/updater/scripts/darwin/update_install b/indra/viewer_components/updater/scripts/darwin/update_install old mode 100644 new mode 100755 index c061d2818f..b174b3570a --- a/indra/viewer_components/updater/scripts/darwin/update_install +++ b/indra/viewer_components/updater/scripts/darwin/update_install @@ -1,3 +1,9 @@ #! /bin/bash -open ../Resources/mac-updater.app --args -dmg "$1" -name "Second Life Viewer 2" +# +# The first argument contains the path to the installer app. The second a path +# to a marker file which should be created if the installer fails.q +# + +open ../Resources/mac-updater.app --args -dmg "$1" -name "Second Life Viewer 2" -marker "$2" +exit 0 diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 9b56a04ff6..25fd1b034d 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -106,6 +106,12 @@ int ll_install_update(std::string const &, std::string const &, LLInstallScriptM return 0; } +std::string const & ll_install_failed_marker_path() +{ + static std::string wubba; + return wubba; +} + /* #pragma warning(disable: 4273) llus_mock_llifstream::llus_mock_llifstream(const std::string& _Filename, -- cgit v1.2.3 From a89024fb372bb293d24d860fb70156b5cf48d6f3 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Mon, 15 Nov 2010 09:57:00 -0800 Subject: write marker on windows installer fail. --- indra/viewer_components/updater/scripts/windows/update_install.bat | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/scripts/windows/update_install.bat b/indra/viewer_components/updater/scripts/windows/update_install.bat index def33c1346..9cdc51847a 100644 --- a/indra/viewer_components/updater/scripts/windows/update_install.bat +++ b/indra/viewer_components/updater/scripts/windows/update_install.bat @@ -1 +1,2 @@ -start /WAIT %1 \ No newline at end of file +start /WAIT %1 +IF ERRORLEVEL 1 ECHO ERRORLEVEL > %2 -- cgit v1.2.3 From f47c42bb10cd3291ce966be7b209b422646dff19 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Mon, 15 Nov 2010 14:26:45 -0800 Subject: create marker on error; use /SKIP_DIALOGS option in installer to run without user input. --- indra/viewer_components/updater/scripts/windows/update_install.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/scripts/windows/update_install.bat b/indra/viewer_components/updater/scripts/windows/update_install.bat index 9cdc51847a..44ccef010b 100644 --- a/indra/viewer_components/updater/scripts/windows/update_install.bat +++ b/indra/viewer_components/updater/scripts/windows/update_install.bat @@ -1,2 +1,2 @@ -start /WAIT %1 +start /WAIT %1 /SKIP_DIALOGS IF ERRORLEVEL 1 ECHO ERRORLEVEL > %2 -- cgit v1.2.3 From 64876ea9459ed0e0f1673c5ec9ae67abea2280e2 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Tue, 16 Nov 2010 09:43:23 -0800 Subject: better error checking when writing downloaded file. --- indra/viewer_components/updater/llupdatedownloader.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index ab441aa747..eccc25aeee 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -275,9 +275,14 @@ size_t LLUpdateDownloader::Implementation::onHeader(void * buffer, size_t size) size_t LLUpdateDownloader::Implementation::onBody(void * buffer, size_t size) { if(mCancelled) return 0; // Forces a write error which will halt curl thread. + if((size == 0) || (buffer == 0)) return 0; mDownloadStream.write(reinterpret_cast(buffer), size); - return size; + if(mDownloadStream.bad()) { + return 0; + } else { + return size; + } } -- cgit v1.2.3 From ad354324ca444d1fc71653e2ade799053a8d6f01 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Tue, 16 Nov 2010 15:21:35 -0800 Subject: clean up installer file after install. --- indra/viewer_components/updater/scripts/windows/update_install.bat | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/scripts/windows/update_install.bat b/indra/viewer_components/updater/scripts/windows/update_install.bat index 44ccef010b..42e148a707 100644 --- a/indra/viewer_components/updater/scripts/windows/update_install.bat +++ b/indra/viewer_components/updater/scripts/windows/update_install.bat @@ -1,2 +1,3 @@ start /WAIT %1 /SKIP_DIALOGS -IF ERRORLEVEL 1 ECHO ERRORLEVEL > %2 +IF ERRORLEVEL 1 ECHO %ERRORLEVEL% > %2 +DEL %1 -- cgit v1.2.3 From 13b77e3622de18ac8d06fdfffceb08990eb908f9 Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Tue, 16 Nov 2010 16:21:17 -0800 Subject: CHOP-179 Linux install uses linux-updater. Rev. by Alain --- indra/viewer_components/updater/CMakeLists.txt | 22 ---------------------- .../viewer_components/updater/llupdaterservice.cpp | 6 ++++-- .../updater/scripts/linux/update_install | 5 +++++ 3 files changed, 9 insertions(+), 24 deletions(-) create mode 100755 indra/viewer_components/updater/scripts/linux/update_install (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index 469c0cf05e..0e288bb496 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -80,25 +80,3 @@ set(UPDATER_LIBRARIES llupdaterservice CACHE INTERNAL "" ) - -# Copy install script. -if(DARWIN) - copy_if_different( - "${CMAKE_CURRENT_SOURCE_DIR}/scripts/darwin" - "${CMAKE_CURRENT_BINARY_DIR}" - update_installer_targets - "update_install" - ) -elseif(WINDOWS) - copy_if_different( - "${CMAKE_CURRENT_SOURCE_DIR}/scripts/windows" - "${CMAKE_CURRENT_BINARY_DIR}" - update_installer_targets - "update_install.bat" - ) -endif() -add_custom_target(copy_update_install ALL DEPENDS ${update_installer_targets}) -add_dependencies(llupdaterservice copy_update_install) - - - \ No newline at end of file diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index a1ad3e3381..976e639098 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -353,9 +353,11 @@ void LLUpdaterServiceImpl::downloadComplete(LLSD const & data) void LLUpdaterServiceImpl::downloadError(std::string const & message) { + LL_INFOS("UpdaterService") << "Error downloading: " << message << LL_ENDL; + mIsDownloading = false; - // Restart the + // Restart the timer on error if(mIsChecking) { restartTimer(mCheckPeriod); @@ -365,7 +367,7 @@ void LLUpdaterServiceImpl::downloadError(std::string const & message) void LLUpdaterServiceImpl::restartTimer(unsigned int seconds) { LL_INFOS("UpdaterService") << "will check for update again in " << - mCheckPeriod << " seconds" << LL_ENDL; + seconds << " seconds" << LL_ENDL; mTimer.start(); mTimer.setTimerExpirySec(seconds); LLEventPumps::instance().obtain("mainloop").listen( diff --git a/indra/viewer_components/updater/scripts/linux/update_install b/indra/viewer_components/updater/scripts/linux/update_install new file mode 100755 index 0000000000..acedaad25c --- /dev/null +++ b/indra/viewer_components/updater/scripts/linux/update_install @@ -0,0 +1,5 @@ +#! /bin/bash +INSTALL_DIR=$(cd "$(dirname $0)/.." ; pwd) +export LD_LIBRARY_PATH=$INSTALL_DIR/lib +bin/linux-updater.bin --file "$1" --dest "$INSTALL_DIR" --name "Second Life Viewer 2" --stringsdir "$INSTALL_DIR/skins/default/xui/en" --stringsfile "strings.xml" + -- cgit v1.2.3 From 74a60346b2f04157862786d31d7181885092b766 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Tue, 16 Nov 2010 16:22:37 -0800 Subject: remove downloaded file on error. --- indra/viewer_components/updater/llupdatedownloader.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index eccc25aeee..4820f1f452 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -308,6 +308,7 @@ void LLUpdateDownloader::Implementation::run(void) LL_WARNS("UpdateDownload") << "download failed with error '" << curl_easy_strerror(code) << "'" << LL_ENDL; LLFile::remove(mDownloadRecordPath); + if(mDownloadData.has("path")) LLFile::remove(mDownloadData["path"].asString()); mClient.downloadError("curl error"); } -- cgit v1.2.3 From dd6213abf4f70cfb9d221572f9dc4d597d8fa0dc Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Tue, 16 Nov 2010 18:34:58 -0800 Subject: CHOP-209 Added marker creation, fixed updater crash bug --- indra/viewer_components/updater/scripts/linux/update_install | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/scripts/linux/update_install b/indra/viewer_components/updater/scripts/linux/update_install index acedaad25c..7d8a27607c 100755 --- a/indra/viewer_components/updater/scripts/linux/update_install +++ b/indra/viewer_components/updater/scripts/linux/update_install @@ -3,3 +3,6 @@ INSTALL_DIR=$(cd "$(dirname $0)/.." ; pwd) export LD_LIBRARY_PATH=$INSTALL_DIR/lib bin/linux-updater.bin --file "$1" --dest "$INSTALL_DIR" --name "Second Life Viewer 2" --stringsdir "$INSTALL_DIR/skins/default/xui/en" --stringsfile "strings.xml" +if [ $? -ne 0 ] + then touch $2 +fi \ No newline at end of file -- cgit v1.2.3 From 8e0e5e0bd9fd3e699a36b6babfacab3c0f61935b Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Wed, 17 Nov 2010 15:20:53 -0800 Subject: CHOP-203 Deleting the update file after installer run. --- indra/viewer_components/updater/scripts/linux/update_install | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/scripts/linux/update_install b/indra/viewer_components/updater/scripts/linux/update_install index 7d8a27607c..fef5ef7d09 100755 --- a/indra/viewer_components/updater/scripts/linux/update_install +++ b/indra/viewer_components/updater/scripts/linux/update_install @@ -5,4 +5,6 @@ bin/linux-updater.bin --file "$1" --dest "$INSTALL_DIR" --name "Second Life View if [ $? -ne 0 ] then touch $2 -fi \ No newline at end of file +fi + +rm -f $1 -- cgit v1.2.3 From c212695cd96f94248b0da2085aeb23c54a5ca76b Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Wed, 17 Nov 2010 16:27:50 -0800 Subject: post events for dowload success and error. --- .../viewer_components/updater/llupdaterservice.cpp | 24 +++++++++++++++++++++- indra/viewer_components/updater/llupdaterservice.h | 10 +++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 976e639098..6a40246497 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -135,7 +135,7 @@ public: void downloadComplete(LLSD const & data); void downloadError(std::string const & message); - bool onMainLoop(LLSD const & event); + bool onMainLoop(LLSD const & event); private: void restartTimer(unsigned int seconds); @@ -349,6 +349,13 @@ void LLUpdaterServiceImpl::downloadComplete(LLSD const & data) // marker file. llofstream update_marker(update_marker_path()); LLSDSerialize::toPrettyXML(data, update_marker); + + LLSD event; + event["pump"] = LLUpdaterService::pumpName(); + LLSD payload; + payload["type"] = LLSD(LLUpdaterService::DOWNLOAD_COMPLETE); + event["payload"] = payload; + LLEventPumps::instance().obtain("mainlooprepeater").post(event); } void LLUpdaterServiceImpl::downloadError(std::string const & message) @@ -362,6 +369,14 @@ void LLUpdaterServiceImpl::downloadError(std::string const & message) { restartTimer(mCheckPeriod); } + + LLSD event; + event["pump"] = LLUpdaterService::pumpName(); + LLSD payload; + payload["type"] = LLSD(LLUpdaterService::DOWNLOAD_ERROR); + payload["message"] = message; + event["payload"] = payload; + LLEventPumps::instance().obtain("mainlooprepeater").post(event); } void LLUpdaterServiceImpl::restartTimer(unsigned int seconds) @@ -405,6 +420,13 @@ bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) //----------------------------------------------------------------------- // Facade interface + +std::string const & LLUpdaterService::pumpName(void) +{ + static std::string name("updater_service"); + return name; +} + LLUpdaterService::LLUpdaterService() { if(gUpdater.expired()) diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index ec20dc6e05..8d0b95be86 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -39,6 +39,16 @@ public: public: UsageError(const std::string& msg) : std::runtime_error(msg) {} }; + + // Name of the event pump through which update events will be delivered. + static std::string const & pumpName(void); + + // Type codes for events posted by this service. Stored the event's 'type' element. + enum UpdateEvent { + INVALID, + DOWNLOAD_COMPLETE, + DOWNLOAD_ERROR + }; LLUpdaterService(); ~LLUpdaterService(); -- cgit v1.2.3 From 098fa21c4f812b94348c0631c29babff68968d3d Mon Sep 17 00:00:00 2001 From: brad kittenbrink Date: Wed, 17 Nov 2010 17:06:21 -0800 Subject: Work on CHOP-135: Hooking up setting UpdaterServiceActive to functionality. Paired with Mani. Toggling the setting now calls LLUpdaterService::startChecking() and LLUpdaterService::stopChecking(), which enable and disable the service. --- indra/viewer_components/updater/llupdaterservice.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 6a40246497..58f2c7da76 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -175,12 +175,6 @@ void LLUpdaterServiceImpl::initialize(const std::string& protocol_version, mPath = path; mChannel = channel; mVersion = version; - - // Check to see if an install is ready. - if(!checkForInstall()) - { - checkForResume(); - } } void LLUpdaterServiceImpl::setCheckPeriod(unsigned int seconds) @@ -198,6 +192,12 @@ void LLUpdaterServiceImpl::startChecking() mIsChecking = true; + // Check to see if an install is ready. + if(!checkForInstall()) + { + checkForResume(); + } + if(!mIsDownloading) { // Checking can only occur during the mainloop. @@ -214,6 +214,11 @@ void LLUpdaterServiceImpl::stopChecking() mIsChecking = false; mTimer.stop(); } + + if(mIsDownloading) + { + this->mUpdateDownloader.cancel(); + } } bool LLUpdaterServiceImpl::isChecking() -- cgit v1.2.3 From 0018762228c627b27ccc0d98528cfe745ca5d53e Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 18 Nov 2010 12:12:44 -0500 Subject: Dummy out LLUpdateDownloader::cancel() too for testing. --- indra/viewer_components/updater/tests/llupdaterservice_test.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 25fd1b034d..390879352c 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -100,6 +100,7 @@ std::string LLUpdateDownloader::downloadMarkerPath(void) } void LLUpdateDownloader::resume(void) {} +void LLUpdateDownloader::cancel(void) {} int ll_install_update(std::string const &, std::string const &, LLInstallScriptMode) { -- cgit v1.2.3 From 3625a0f2362d2285d925052aedc69d27713e416d Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 18 Nov 2010 13:25:44 -0800 Subject: inform user on failed install--needs proper user dialog ;-) --- indra/viewer_components/updater/llupdaterservice.cpp | 4 ++++ indra/viewer_components/updater/llupdaterservice.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 58f2c7da76..b49f6d04b0 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -408,6 +408,10 @@ bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) llinfos << "found marker " << ll_install_failed_marker_path() << llendl; llinfos << "last install attempt failed" << llendl; LLFile::remove(ll_install_failed_marker_path()); + + LLSD event; + event["type"] = LLSD(LLUpdaterService::INSTALL_ERROR); + LLEventPumps::instance().obtain(LLUpdaterService::pumpName()).post(event); } else { diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 8d0b95be86..3655136f3c 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -47,7 +47,8 @@ public: enum UpdateEvent { INVALID, DOWNLOAD_COMPLETE, - DOWNLOAD_ERROR + DOWNLOAD_ERROR, + INSTALL_ERROR }; LLUpdaterService(); -- cgit v1.2.3 From 86e84a1313f9fcb78b3e6b490dcf1604829ef175 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 18 Nov 2010 15:40:21 -0800 Subject: conform to coding standard. --- indra/viewer_components/updater/llupdaterservice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 3655136f3c..55824af188 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -44,7 +44,7 @@ public: static std::string const & pumpName(void); // Type codes for events posted by this service. Stored the event's 'type' element. - enum UpdateEvent { + enum eUpdateEvent { INVALID, DOWNLOAD_COMPLETE, DOWNLOAD_ERROR, -- cgit v1.2.3 From c893c55d8a1328a134c956b70e6fef7fd7053d47 Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Thu, 18 Nov 2010 17:03:01 -0800 Subject: Fixing bugs discovered in merge with viewer development --- indra/viewer_components/updater/tests/llupdaterservice_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 390879352c..04ed4e6364 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -61,7 +61,7 @@ class LLDir_Mock : public LLDir BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, - std::string &fname, BOOL wrap) + std::string &fname) { return false; } -- cgit v1.2.3 From 8c2026d6b71f133deafa6b0e19baf69632a2510a Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Thu, 18 Nov 2010 21:57:27 -0800 Subject: CHOP-135 Bug fixes. --- .../updater/llupdatedownloader.cpp | 6 +- .../viewer_components/updater/llupdaterservice.cpp | 85 +++++++++++++--------- indra/viewer_components/updater/llupdaterservice.h | 2 +- 3 files changed, 55 insertions(+), 38 deletions(-) (limited to 'indra/viewer_components') diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 4820f1f452..c17a50e242 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -204,7 +204,11 @@ bool LLUpdateDownloader::Implementation::isDownloading(void) void LLUpdateDownloader::Implementation::resume(void) { - if(isDownloading()) mClient.downloadError("download in progress"); + mCancelled = false; + + if(isDownloading()) { + mClient.downloadError("download in progress"); + } mDownloadRecordPath = downloadMarkerPath(); llifstream dataStream(mDownloadRecordPath); diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index b49f6d04b0..cc60eaead2 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -112,13 +112,13 @@ public: void setCheckPeriod(unsigned int seconds); - void startChecking(); + void startChecking(bool install_if_ready); void stopChecking(); bool isChecking(); void setAppExitCallback(LLUpdaterService::app_exit_callback_t aecb) { mAppExitCallback = aecb;} - bool checkForInstall(); // Test if a local install is ready. + bool checkForInstall(bool launchInstaller); // Test if a local install is ready. bool checkForResume(); // Test for resumeable d/l. // LLUpdateChecker::Client: @@ -139,6 +139,7 @@ public: private: void restartTimer(unsigned int seconds); + void stopTimer(); }; const std::string LLUpdaterServiceImpl::sListenerName = "LLUpdaterServiceImpl"; @@ -182,7 +183,7 @@ void LLUpdaterServiceImpl::setCheckPeriod(unsigned int seconds) mCheckPeriod = seconds; } -void LLUpdaterServiceImpl::startChecking() +void LLUpdaterServiceImpl::startChecking(bool install_if_ready) { if(mUrl.empty() || mChannel.empty() || mVersion.empty()) { @@ -193,17 +194,18 @@ void LLUpdaterServiceImpl::startChecking() mIsChecking = true; // Check to see if an install is ready. - if(!checkForInstall()) + bool has_install = checkForInstall(install_if_ready); + if(!has_install) { - checkForResume(); - } + checkForResume(); // will set mIsDownloading to true if resuming - if(!mIsDownloading) - { - // Checking can only occur during the mainloop. - // reset the timer to 0 so that the next mainloop event - // triggers a check; - restartTimer(0); + if(!mIsDownloading) + { + // Checking can only occur during the mainloop. + // reset the timer to 0 so that the next mainloop event + // triggers a check; + restartTimer(0); + } } } @@ -212,12 +214,13 @@ void LLUpdaterServiceImpl::stopChecking() if(mIsChecking) { mIsChecking = false; - mTimer.stop(); + stopTimer(); } if(mIsDownloading) { - this->mUpdateDownloader.cancel(); + mUpdateDownloader.cancel(); + mIsDownloading = false; } } @@ -226,9 +229,9 @@ bool LLUpdaterServiceImpl::isChecking() return mIsChecking; } -bool LLUpdaterServiceImpl::checkForInstall() +bool LLUpdaterServiceImpl::checkForInstall(bool launchInstaller) { - bool result = false; // return true if install is found. + bool foundInstall = false; // return true if install is found. llifstream update_marker(update_marker_path(), std::ios::in | std::ios::binary); @@ -239,7 +242,6 @@ bool LLUpdaterServiceImpl::checkForInstall() LLSD update_info; LLSDSerialize::fromXMLDocument(update_info, update_marker); update_marker.close(); - LLFile::remove(update_marker_path()); // Get the path to the installer file. LLSD path = update_info.get("path"); @@ -251,33 +253,39 @@ bool LLUpdaterServiceImpl::checkForInstall() { llinfos << "ignoring update dowloaded by different client version" << llendl; LLFile::remove(path.asString()); + LLFile::remove(update_marker_path()); } else { ; // Nothing to clean up. } - result = false; + foundInstall = false; } else if(path.isDefined() && !path.asString().empty()) { - int result = ll_install_update(install_script_path(), - update_info["path"].asString(), - install_script_mode()); - - if((result == 0) && mAppExitCallback) + if(launchInstaller) { - mAppExitCallback(); - } else if(result != 0) { - llwarns << "failed to run update install script" << LL_ENDL; - } else { - ; // No op. + LLFile::remove(update_marker_path()); + + int result = ll_install_update(install_script_path(), + update_info["path"].asString(), + install_script_mode()); + + if((result == 0) && mAppExitCallback) + { + mAppExitCallback(); + } else if(result != 0) { + llwarns << "failed to run update install script" << LL_ENDL; + } else { + ; // No op. + } } - result = true; + foundInstall = true; } } - return result; + return foundInstall; } bool LLUpdaterServiceImpl::checkForResume() @@ -324,7 +332,7 @@ void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion, LLURI const & uri, std::string const & hash) { - mTimer.stop(); + stopTimer(); mIsDownloading = true; mUpdateDownloader.download(uri, hash); } @@ -333,7 +341,7 @@ void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion, LLURI const & uri, std::string const & hash) { - mTimer.stop(); + stopTimer(); mIsDownloading = true; mUpdateDownloader.download(uri, hash); } @@ -394,12 +402,17 @@ void LLUpdaterServiceImpl::restartTimer(unsigned int seconds) sListenerName, boost::bind(&LLUpdaterServiceImpl::onMainLoop, this, _1)); } +void LLUpdaterServiceImpl::stopTimer() +{ + mTimer.stop(); + LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); +} + bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) { if(mTimer.getStarted() && mTimer.hasExpired()) { - mTimer.stop(); - LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); + stopTimer(); // Check for failed install. if(LLFile::isfile(ll_install_failed_marker_path())) @@ -468,9 +481,9 @@ void LLUpdaterService::setCheckPeriod(unsigned int seconds) mImpl->setCheckPeriod(seconds); } -void LLUpdaterService::startChecking() +void LLUpdaterService::startChecking(bool install_if_ready) { - mImpl->startChecking(); + mImpl->startChecking(install_if_ready); } void LLUpdaterService::stopChecking() diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 55824af188..752a6f834b 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -62,7 +62,7 @@ public: void setCheckPeriod(unsigned int seconds); - void startChecking(); + void startChecking(bool install_if_ready = false); void stopChecking(); bool isChecking(); -- cgit v1.2.3