/indra/viewer_components/updater/llupdateinstaller.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 100 lines · 61 code · 15 blank · 24 comment · 4 complexity · f28df02af45867bb4895bf005412f828 MD5 · raw file

  1. /**
  2. * @file llupdateinstaller.cpp
  3. *
  4. * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #include "linden_common.h"
  26. #include <apr_file_io.h>
  27. #include "llapr.h"
  28. #include "llprocesslauncher.h"
  29. #include "llupdateinstaller.h"
  30. #include "lldir.h"
  31. #if defined(LL_WINDOWS)
  32. #pragma warning(disable: 4702) // disable 'unreachable code' so we can use lexical_cast (really!).
  33. #endif
  34. #include <boost/lexical_cast.hpp>
  35. namespace {
  36. class RelocateError {};
  37. std::string copy_to_temp(std::string const & path)
  38. {
  39. std::string scriptFile = gDirUtilp->getBaseFileName(path);
  40. std::string newPath = gDirUtilp->getExpandedFilename(LL_PATH_TEMP, scriptFile);
  41. apr_status_t status = apr_file_copy(path.c_str(), newPath.c_str(), APR_FILE_SOURCE_PERMS, gAPRPoolp);
  42. if(status != APR_SUCCESS) throw RelocateError();
  43. return newPath;
  44. }
  45. }
  46. int ll_install_update(std::string const & script,
  47. std::string const & updatePath,
  48. bool required,
  49. LLInstallScriptMode mode)
  50. {
  51. std::string actualScriptPath;
  52. switch(mode) {
  53. case LL_COPY_INSTALL_SCRIPT_TO_TEMP:
  54. try {
  55. actualScriptPath = copy_to_temp(script);
  56. }
  57. catch (RelocateError &) {
  58. return -1;
  59. }
  60. break;
  61. case LL_RUN_INSTALL_SCRIPT_IN_PLACE:
  62. actualScriptPath = script;
  63. break;
  64. default:
  65. llassert(!"unpossible copy mode");
  66. }
  67. llinfos << "UpdateInstaller: installing " << updatePath << " using " <<
  68. actualScriptPath << LL_ENDL;
  69. LLProcessLauncher launcher;
  70. launcher.setExecutable(actualScriptPath);
  71. launcher.addArgument(updatePath);
  72. launcher.addArgument(ll_install_failed_marker_path().c_str());
  73. launcher.addArgument(boost::lexical_cast<std::string>(required));
  74. int result = launcher.launch();
  75. launcher.orphan();
  76. return result;
  77. }
  78. std::string const & ll_install_failed_marker_path(void)
  79. {
  80. static std::string path;
  81. if(path.empty()) {
  82. path = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "SecondLifeInstallFailed.marker");
  83. }
  84. return path;
  85. }