diff options
Diffstat (limited to 'indra/llvfs')
| -rw-r--r-- | indra/llvfs/lldir.cpp | 11 | ||||
| -rw-r--r-- | indra/llvfs/lldir.h | 25 | ||||
| -rw-r--r-- | indra/llvfs/lldir_linux.cpp | 28 | ||||
| -rw-r--r-- | indra/llvfs/lldir_mac.cpp | 2 | ||||
| -rw-r--r-- | indra/llvfs/lldir_solaris.cpp | 28 | ||||
| -rw-r--r-- | indra/llvfs/lldir_win32.cpp | 109 | 
6 files changed, 107 insertions, 96 deletions
| diff --git a/indra/llvfs/lldir.cpp b/indra/llvfs/lldir.cpp index b845de71fa..2069888774 100644 --- a/indra/llvfs/lldir.cpp +++ b/indra/llvfs/lldir.cpp @@ -597,7 +597,7 @@ std::string LLDir::getExpandedFilename(ELLPath location, const std::string& subd  				<< "': prefix is empty, possible bad filename" << LL_ENDL;  	} -	std::string expanded_filename = add(add(prefix, subdir1), subdir2); +	std::string expanded_filename = add(prefix, subdir1, subdir2);  	if (expanded_filename.empty() && in_filename.empty())  	{  		return ""; @@ -693,7 +693,7 @@ void LLDir::walkSearchSkinDirs(const std::string& subdir,  		std::string subdir_path(add(skindir, subdir));  		BOOST_FOREACH(std::string subsubdir, subsubdirs)  		{ -			std::string full_path(add(add(subdir_path, subsubdir), filename)); +			std::string full_path(add(subdir_path, subsubdir, filename));  			if (fileExists(full_path))  			{  				function(subsubdir, full_path); @@ -1052,13 +1052,6 @@ void LLDir::dumpCurrentDirectories()  	LL_DEBUGS("AppInit","Directories") << "  SkinDir:               " << getSkinDir() << LL_ENDL;  } -std::string LLDir::add(const std::string& path, const std::string& name) const -{ -	std::string destpath(path); -	append(destpath, name); -	return destpath; -} -  void LLDir::append(std::string& destpath, const std::string& name) const  {  	// Delegate question of whether we need a separator to helper method. diff --git a/indra/llvfs/lldir.h b/indra/llvfs/lldir.h index b219c6e29f..e233413a7f 100644 --- a/indra/llvfs/lldir.h +++ b/indra/llvfs/lldir.h @@ -202,9 +202,28 @@ class LLDir  	/// Append specified @a name to @a destpath, separated by getDirDelimiter()  	/// if both are non-empty.  	void append(std::string& destpath, const std::string& name) const; -	/// Append specified @a name to @a path, separated by getDirDelimiter() -	/// if both are non-empty. Return result, leaving @a path unmodified. -	std::string add(const std::string& path, const std::string& name) const; +	/// Variadic form: append @a name0 and @a name1 and arbitrary other @a +	/// names to @a destpath, separated by getDirDelimiter() as needed. +	template <typename... NAMES> +	void append(std::string& destpath, const std::string& name0, const std::string& name1, +				const NAMES& ... names) const +	{ +		// In a typical recursion case, we'd accept (destpath, name0, names). +		// We accept (destpath, name0, name1, names) because it's important to +		// delegate the two-argument case to the non-template implementation. +		append(destpath, name0); +		append(destpath, name1, names...); +	} + +	/// Append specified @a names to @a path, separated by getDirDelimiter() +	/// as needed. Return result, leaving @a path unmodified. +	template <typename... NAMES> +	std::string add(const std::string& path, const NAMES& ... names) const +	{ +		std::string destpath(path); +		append(destpath, names...); +		return destpath; +	}  protected:  	// Does an add() or append() call need a directory delimiter? diff --git a/indra/llvfs/lldir_linux.cpp b/indra/llvfs/lldir_linux.cpp index 7a4034c228..a9f3166d41 100644 --- a/indra/llvfs/lldir_linux.cpp +++ b/indra/llvfs/lldir_linux.cpp @@ -185,41 +185,29 @@ void LLDir_Linux::initAppDirs(const std::string &app_name,  	int res = LLFile::mkdir(mOSUserAppDir);  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create app user dir " << mOSUserAppDir << LL_ENDL; -			LL_WARNS() << "Default to base dir" << mOSUserDir << LL_ENDL; -			mOSUserAppDir = mOSUserDir; -		} +		LL_WARNS() << "Couldn't create app user dir " << mOSUserAppDir << LL_ENDL; +		LL_WARNS() << "Default to base dir" << mOSUserDir << LL_ENDL; +		mOSUserAppDir = mOSUserDir;  	}  	res = LLFile::mkdir(getExpandedFilename(LL_PATH_LOGS,""));  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create LL_PATH_LOGS dir " << getExpandedFilename(LL_PATH_LOGS,"") << LL_ENDL; -		} +		LL_WARNS() << "Couldn't create LL_PATH_LOGS dir " << getExpandedFilename(LL_PATH_LOGS,"") << LL_ENDL;  	}  	res = LLFile::mkdir(getExpandedFilename(LL_PATH_USER_SETTINGS,""));  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create LL_PATH_USER_SETTINGS dir " << getExpandedFilename(LL_PATH_USER_SETTINGS,"") << LL_ENDL; -		} +		LL_WARNS() << "Couldn't create LL_PATH_USER_SETTINGS dir " << getExpandedFilename(LL_PATH_USER_SETTINGS,"") << LL_ENDL;  	} -	 +  	res = LLFile::mkdir(getExpandedFilename(LL_PATH_CACHE,""));  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << getExpandedFilename(LL_PATH_CACHE,"") << LL_ENDL; -		} +		LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << getExpandedFilename(LL_PATH_CACHE,"") << LL_ENDL;  	} -	 +  	mCAFile = getExpandedFilename(LL_PATH_APP_SETTINGS, "CA.pem");  } diff --git a/indra/llvfs/lldir_mac.cpp b/indra/llvfs/lldir_mac.cpp index 4038c92465..e776b84a12 100644 --- a/indra/llvfs/lldir_mac.cpp +++ b/indra/llvfs/lldir_mac.cpp @@ -94,7 +94,7 @@ LLDir_Mac::LLDir_Mac()  		// MBW -- This keeps the mac application from finding other things.  		// If this is really for skins, it should JUST apply to skins. -		U32 build_dir_pos = mExecutableDir.rfind("/build-darwin-"); +		std::string::size_type build_dir_pos = mExecutableDir.rfind("/build-darwin-");  		if (build_dir_pos != std::string::npos)  		{  			// ...we're in a dev checkout diff --git a/indra/llvfs/lldir_solaris.cpp b/indra/llvfs/lldir_solaris.cpp index b43b2f27ce..d60237bacc 100644 --- a/indra/llvfs/lldir_solaris.cpp +++ b/indra/llvfs/lldir_solaris.cpp @@ -203,41 +203,29 @@ void LLDir_Solaris::initAppDirs(const std::string &app_name,  	int res = LLFile::mkdir(mOSUserAppDir);  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create app user dir " << mOSUserAppDir << LL_ENDL; -			LL_WARNS() << "Default to base dir" << mOSUserDir << LL_ENDL; -			mOSUserAppDir = mOSUserDir; -		} +		LL_WARNS() << "Couldn't create app user dir " << mOSUserAppDir << LL_ENDL; +		LL_WARNS() << "Default to base dir" << mOSUserDir << LL_ENDL; +		mOSUserAppDir = mOSUserDir;  	}  	res = LLFile::mkdir(getExpandedFilename(LL_PATH_LOGS,""));  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create LL_PATH_LOGS dir " << getExpandedFilename(LL_PATH_LOGS,"") << LL_ENDL; -		} +		LL_WARNS() << "Couldn't create LL_PATH_LOGS dir " << getExpandedFilename(LL_PATH_LOGS,"") << LL_ENDL;  	}  	res = LLFile::mkdir(getExpandedFilename(LL_PATH_USER_SETTINGS,""));  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create LL_PATH_USER_SETTINGS dir " << getExpandedFilename(LL_PATH_USER_SETTINGS,"") << LL_ENDL; -		} +		LL_WARNS() << "Couldn't create LL_PATH_USER_SETTINGS dir " << getExpandedFilename(LL_PATH_USER_SETTINGS,"") << LL_ENDL;  	} -	 +  	res = LLFile::mkdir(getExpandedFilename(LL_PATH_CACHE,""));  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << getExpandedFilename(LL_PATH_CACHE,"") << LL_ENDL; -		} +		LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << getExpandedFilename(LL_PATH_CACHE,"") << LL_ENDL;  	} -	 +  	mCAFile = getExpandedFilename(LL_PATH_APP_SETTINGS, "CA.pem");  } diff --git a/indra/llvfs/lldir_win32.cpp b/indra/llvfs/lldir_win32.cpp index ebc8fdca33..5485349c83 100644 --- a/indra/llvfs/lldir_win32.cpp +++ b/indra/llvfs/lldir_win32.cpp @@ -31,7 +31,8 @@  #include "lldir_win32.h"  #include "llerror.h"  #include "llrand.h"		// for gLindenLabRandomNumber -#include "shlobj.h" +#include <shlobj.h> +#include <fstream>  #include <direct.h>  #include <errno.h> @@ -44,28 +45,25 @@ DWORD GetDllVersion(LPCTSTR lpszDllName);  LLDir_Win32::LLDir_Win32()  { +	// set this first: used by append() and add() methods  	mDirDelimiter = "\\"; -	WCHAR w_str[MAX_PATH]; - -	// Application Data is where user settings go -	SHGetSpecialFolderPath(NULL, w_str, CSIDL_APPDATA, TRUE); - -	mOSUserDir = utf16str_to_utf8str(llutf16string(w_str)); +	// Application Data is where user settings go. We rely on $APPDATA being +	// correct; in fact the VMP makes a point of setting it properly, since +	// Windows itself botches the job for non-ASCII usernames (MAINT-8087). +	mOSUserDir = ll_safe_string(getenv("APPDATA"));  	// We want cache files to go on the local disk, even if the  	// user is on a network with a "roaming profile".  	// -	// On XP this is: -	//   C:\Docments and Settings\James\Local Settings\Application Data  	// On Vista this is:  	//   C:\Users\James\AppData\Local  	//  	// We used to store the cache in AppData\Roaming, and the installer  	// cleans up that version on upgrade.  JC -	SHGetSpecialFolderPath(NULL, w_str, CSIDL_LOCAL_APPDATA, TRUE); -	mOSCacheDir = utf16str_to_utf8str(llutf16string(w_str)); +	mOSCacheDir = ll_safe_string(getenv("LOCALAPPDATA")); +	WCHAR w_str[MAX_PATH];  	if (GetTempPath(MAX_PATH, w_str))  	{  		if (wcslen(w_str))	/* Flawfinder: ignore */  @@ -73,12 +71,54 @@ LLDir_Win32::LLDir_Win32()  			w_str[wcslen(w_str)-1] = '\0'; /* Flawfinder: ignore */ // remove trailing slash  		}  		mTempDir = utf16str_to_utf8str(llutf16string(w_str)); + +		if (mOSUserDir.empty()) +		{ +			mOSUserDir = mTempDir; +		} + +		if (mOSCacheDir.empty()) +		{ +			mOSCacheDir = mTempDir; +		}  	}  	else  	{  		mTempDir = mOSUserDir;  	} +/*==========================================================================*| +	// Now that we've got mOSUserDir, one way or another, let's see how we did +	// with our environment variables. +	{ +		auto report = [this](std::ostream& out){ +			out << "mOSUserDir  = '" << mOSUserDir  << "'\n" +				<< "mOSCacheDir = '" << mOSCacheDir << "'\n" +				<< "mTempDir    = '" << mTempDir    << "'" << std::endl; +		}; +		int res = LLFile::mkdir(mOSUserDir); +		if (res == -1) +		{ +			// If we couldn't even create the directory, just blurt to stderr +			report(std::cerr); +		} +		else +		{ +			// successfully created logdir, plunk a log file there +			std::string logfilename(add(mOSUserDir, "lldir.log")); +			std::ofstream logfile(logfilename.c_str()); +			if (! logfile.is_open()) +			{ +				report(std::cerr); +			} +			else +			{ +				report(logfile); +			} +		} +	} +|*==========================================================================*/ +  //	fprintf(stderr, "mTempDir = <%s>",mTempDir);  	// Set working directory, for LLDir::getWorkingDir() @@ -124,7 +164,7 @@ LLDir_Win32::LLDir_Win32()  	// 'llplugin' need to go somewhere else.  	// alas... this also gets called during static initialization   	// time due to the construction of gDirUtil in lldir.cpp. -	if(! LLFile::isdir(mAppRODataDir + mDirDelimiter + "skins")) +	if(! LLFile::isdir(add(mAppRODataDir, "skins")))  	{  		// What? No skins in the working dir?  		// Try the executable's directory. @@ -133,7 +173,7 @@ LLDir_Win32::LLDir_Win32()  //	LL_INFOS() << "mAppRODataDir = " << mAppRODataDir << LL_ENDL; -	mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins"; +	mSkinBaseDir = add(mAppRODataDir, "skins");  	// Build the default cache directory  	mDefaultCacheDir = buildSLOSCacheDir(); @@ -142,13 +182,10 @@ LLDir_Win32::LLDir_Win32()  	int res = LLFile::mkdir(mDefaultCacheDir);  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << mDefaultCacheDir << LL_ENDL; -		} +		LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << mDefaultCacheDir << LL_ENDL;  	} -	mLLPluginDir = mExecutableDir + mDirDelimiter + "llplugin"; +	mLLPluginDir = add(mExecutableDir, "llplugin");  }  LLDir_Win32::~LLDir_Win32() @@ -164,52 +201,38 @@ void LLDir_Win32::initAppDirs(const std::string &app_name,  	if (!app_read_only_data_dir.empty())  	{  		mAppRODataDir = app_read_only_data_dir; -		mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins"; +		mSkinBaseDir = add(mAppRODataDir, "skins");  	}  	mAppName = app_name; -	mOSUserAppDir = mOSUserDir; -	mOSUserAppDir += "\\"; -	mOSUserAppDir += app_name; +	mOSUserAppDir = add(mOSUserDir, app_name);  	int res = LLFile::mkdir(mOSUserAppDir);  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create app user dir " << mOSUserAppDir << LL_ENDL; -			LL_WARNS() << "Default to base dir" << mOSUserDir << LL_ENDL; -			mOSUserAppDir = mOSUserDir; -		} +		LL_WARNS() << "Couldn't create app user dir " << mOSUserAppDir << LL_ENDL; +		LL_WARNS() << "Default to base dir" << mOSUserDir << LL_ENDL; +		mOSUserAppDir = mOSUserDir;  	}  	//dumpCurrentDirectories();  	res = LLFile::mkdir(getExpandedFilename(LL_PATH_LOGS,""));  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create LL_PATH_LOGS dir " << getExpandedFilename(LL_PATH_LOGS,"") << LL_ENDL; -		} +		LL_WARNS() << "Couldn't create LL_PATH_LOGS dir " << getExpandedFilename(LL_PATH_LOGS,"") << LL_ENDL;  	} -	 +  	res = LLFile::mkdir(getExpandedFilename(LL_PATH_USER_SETTINGS,""));  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create LL_PATH_USER_SETTINGS dir " << getExpandedFilename(LL_PATH_USER_SETTINGS,"") << LL_ENDL; -		} +		LL_WARNS() << "Couldn't create LL_PATH_USER_SETTINGS dir " << getExpandedFilename(LL_PATH_USER_SETTINGS,"") << LL_ENDL;  	} -	 +  	res = LLFile::mkdir(getExpandedFilename(LL_PATH_CACHE,""));  	if (res == -1)  	{ -		if (errno != EEXIST) -		{ -			LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << getExpandedFilename(LL_PATH_CACHE,"") << LL_ENDL; -		} +		LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << getExpandedFilename(LL_PATH_CACHE,"") << LL_ENDL;  	} -	 +  	mCAFile = getExpandedFilename(LL_PATH_APP_SETTINGS, "CA.pem");  } | 
