Fix program files and HOME dir

This commit is contained in:
Senthil 2016-02-23 20:26:17 -08:00
parent 7407a898e0
commit 84f9ede5ef
2 changed files with 29 additions and 5 deletions

View file

@ -9,6 +9,9 @@
#include <dlfcn.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>
#if defined(__APPLE__)
#include <mach-o/dyld.h>
@ -83,12 +86,22 @@ bool pal::is_path_rooted(const pal::string_t& path)
bool pal::get_default_packages_directory(pal::string_t* recv)
{
recv->clear();
if (!pal::getenv("HOME", recv))
pal::string_t dir;
if (!pal::getenv("HOME", &dir))
{
struct passwd* pw = getpwuid(getuid());
if (pw && pw->pw_dir)
{
dir.assign(pw->pw_dir);
}
}
if (dir.empty())
{
return false;
}
append_path(&*recv, _X(".nuget"));
append_path(&*recv, _X("packages"));
append_path(&dir, _X(".nuget"));
append_path(&dir, _X("packages"));
recv->assign(dir);
return true;
}

View file

@ -14,7 +14,6 @@ static std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> g_converter;
bool pal::find_coreclr(pal::string_t* recv)
{
pal::string_t candidate;
pal::string_t test;
// Try %LocalAppData%\dotnet
if (pal::getenv(_X("LocalAppData"), &candidate)) {
@ -27,7 +26,19 @@ bool pal::find_coreclr(pal::string_t* recv)
}
}
// TODO: Try somewhere in Program Files, see https://github.com/dotnet/cli/issues/249
// Try %ProgramFiles%. Note this works for both x86 and x64/wow64 as per:
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa384274(v=vs.85).aspx
// candidate.clear(); getenv clears it.
if (pal::getenv(_X("ProgramFiles"), &candidate)) {
append_path(&candidate, _X("dotnet"));
append_path(&candidate, _X("bin"));
if (coreclr_exists_in_dir(candidate)) {
recv->assign(candidate);
return true;
}
}
return false;
}