PageRenderTime 31ms CodeModel.GetById 8ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/viewer_components/updater/llupdateinstaller.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 100 lines | 61 code | 15 blank | 24 comment | 3 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
 26#include "linden_common.h"
 27#include <apr_file_io.h>
 28#include "llapr.h"
 29#include "llprocesslauncher.h"
 30#include "llupdateinstaller.h"
 31#include "lldir.h" 
 32
 33
 34#if defined(LL_WINDOWS)
 35#pragma warning(disable: 4702)      // disable 'unreachable code' so we can use lexical_cast (really!).
 36#endif
 37#include <boost/lexical_cast.hpp>
 38
 39
 40namespace {
 41	class RelocateError {};
 42	
 43	
 44	std::string copy_to_temp(std::string const & path)
 45	{
 46		std::string scriptFile = gDirUtilp->getBaseFileName(path);
 47		std::string newPath = gDirUtilp->getExpandedFilename(LL_PATH_TEMP, scriptFile);
 48		apr_status_t status = apr_file_copy(path.c_str(), newPath.c_str(), APR_FILE_SOURCE_PERMS, gAPRPoolp);
 49		if(status != APR_SUCCESS) throw RelocateError();
 50		
 51		return newPath;
 52	}
 53}
 54
 55
 56int ll_install_update(std::string const & script,
 57					  std::string const & updatePath,
 58					  bool required,
 59					  LLInstallScriptMode mode)
 60{
 61	std::string actualScriptPath;
 62	switch(mode) {
 63		case LL_COPY_INSTALL_SCRIPT_TO_TEMP:
 64			try {
 65				actualScriptPath = copy_to_temp(script);
 66			}
 67			catch (RelocateError &) {
 68				return -1;
 69			}
 70			break;
 71		case LL_RUN_INSTALL_SCRIPT_IN_PLACE:
 72			actualScriptPath = script;
 73			break;
 74		default:
 75			llassert(!"unpossible copy mode");
 76	}
 77	
 78	llinfos << "UpdateInstaller: installing " << updatePath << " using " <<
 79		actualScriptPath << LL_ENDL;
 80	
 81	LLProcessLauncher launcher;
 82	launcher.setExecutable(actualScriptPath);
 83	launcher.addArgument(updatePath);
 84	launcher.addArgument(ll_install_failed_marker_path().c_str());
 85	launcher.addArgument(boost::lexical_cast<std::string>(required));
 86	int result = launcher.launch();
 87	launcher.orphan();
 88	
 89	return result;
 90}
 91
 92
 93std::string const & ll_install_failed_marker_path(void)
 94{
 95	static std::string path;
 96	if(path.empty()) {
 97		path = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "SecondLifeInstallFailed.marker");
 98	}
 99	return path;
100}