fixed #627: Poco::Path::home() returns c:\windows\system32 instead home directory

This commit is contained in:
Guenter Obiltschnig 2014-12-09 10:38:11 +01:00
parent 10aedfe5ad
commit a5c8b751d9
2 changed files with 12 additions and 8 deletions

View File

@ -55,14 +55,16 @@ std::string PathImpl::systemImpl()
std::string PathImpl::homeImpl() std::string PathImpl::homeImpl()
{ {
std::string result; std::string result;
if (EnvironmentImpl::hasImpl("HOMEDRIVE") && EnvironmentImpl::hasImpl("HOMEPATH"))
// windows service has no home dir, return system directory instead
try
{ {
result = EnvironmentImpl::getImpl("HOMEDRIVE"); result = EnvironmentImpl::getImpl("HOMEDRIVE");
result.append(EnvironmentImpl::getImpl("HOMEPATH")); result.append(EnvironmentImpl::getImpl("HOMEPATH"));
} }
catch (NotFoundException&) else if (EnvironmentImpl::hasImpl("USERPROFILE"))
{
result = EnvironmentImpl::getImpl("USERPROFILE");
}
else
{ {
result = systemImpl(); result = systemImpl();
} }

View File

@ -65,14 +65,16 @@ std::string PathImpl::systemImpl()
std::string PathImpl::homeImpl() std::string PathImpl::homeImpl()
{ {
std::string result; std::string result;
if (EnvironmentImpl::hasImpl("HOMEDRIVE") && EnvironmentImpl::hasImpl("HOMEPATH"))
// windows service has no home dir, return system directory instead
try
{ {
result = EnvironmentImpl::getImpl("HOMEDRIVE"); result = EnvironmentImpl::getImpl("HOMEDRIVE");
result.append(EnvironmentImpl::getImpl("HOMEPATH")); result.append(EnvironmentImpl::getImpl("HOMEPATH"));
} }
catch (NotFoundException&) else if (EnvironmentImpl::hasImpl("USERPROFILE"))
{
result = EnvironmentImpl::getImpl("USERPROFILE");
}
else
{ {
result = systemImpl(); result = systemImpl();
} }