mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 02:53:10 +01:00
GH 30:Poco::Path::home() throws
GH #30: Poco::Path::home() throws when called from Windows Service done for Win32 and Win32U, return root for WinCE
This commit is contained in:
39
CONTRIBUTORS
39
CONTRIBUTORS
@@ -1,23 +1,23 @@
|
|||||||
Guenter Obiltschnig <guenter.obiltschnig@appinf.com>
|
Guenter Obiltschnig
|
||||||
Alex Fabijanic <alex@pocoproject.org>
|
Alex Fabijanic
|
||||||
Peter Schojer <peter.schojer@appinf.com>
|
Peter Schojer
|
||||||
Ferdinand Beyer <fbeyer@users.sourceforge.net>
|
Ferdinand Beyer
|
||||||
Krzysztof Burghardt <burghardt@users.sourceforge.net>
|
Krzysztof Burghardt
|
||||||
Claus Dabringer <claus.dabringer@appinf.com>
|
Claus Dabringer
|
||||||
Caleb Epstein <caleb.epstein@gmail.com>
|
Caleb Epstein
|
||||||
Eran Hammer-Lahav <therazorblade@users.sourceforge.net>
|
Eran Hammer-Lahav
|
||||||
Chris Johnson <devcjohnson@gmail.com>
|
Chris Johnson
|
||||||
Sergey Kholodilov <serghol@gmail.com>
|
Sergey Kholodilov
|
||||||
Ryan Kraay <rkraay@users.sourceforge.net>
|
Ryan Kraay
|
||||||
Larry Lewis <lewislp@users.sourceforge.net>
|
Larry Lewis
|
||||||
Andrew J. P. Maclean <a.maclean@optusnet.com.au>
|
Andrew J. P. Maclean
|
||||||
Andrew Marlow <public@marlowa.plus.com>
|
Andrew Marlow
|
||||||
Paschal Mushubi <mushubi@sympatico.ca>
|
Paschal Mushubi
|
||||||
Jiang Shan <pasorobo@users.sourceforge.net>
|
Jiang Shan
|
||||||
David Shawley <boredc0der@users.sourceforge.net>
|
David Shawley
|
||||||
Sergey Skorokhodov <ryppka@users.sourceforge.net>
|
Sergey Skorokhodov
|
||||||
Tom Tan
|
Tom Tan
|
||||||
Sergey N. Yatskevich <snc@begun.ru>
|
Sergey N. Yatskevich
|
||||||
Marc Chevrier
|
Marc Chevrier
|
||||||
Philippe Cuvillier
|
Philippe Cuvillier
|
||||||
Marian Krivos
|
Marian Krivos
|
||||||
@@ -28,6 +28,7 @@ Rangel Reale
|
|||||||
Fabrizio Duhem
|
Fabrizio Duhem
|
||||||
Patrick White
|
Patrick White
|
||||||
Mike Naquin
|
Mike Naquin
|
||||||
|
Roger Meier
|
||||||
|
|
||||||
--
|
--
|
||||||
$Id$
|
$Id$
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public:
|
|||||||
static std::string homeImpl();
|
static std::string homeImpl();
|
||||||
static std::string tempImpl();
|
static std::string tempImpl();
|
||||||
static std::string nullImpl();
|
static std::string nullImpl();
|
||||||
|
static std::string systemImpl();
|
||||||
static std::string expandImpl(const std::string& path);
|
static std::string expandImpl(const std::string& path);
|
||||||
static void listRootsImpl(std::vector<std::string>& roots);
|
static void listRootsImpl(std::vector<std::string>& roots);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public:
|
|||||||
static std::string homeImpl();
|
static std::string homeImpl();
|
||||||
static std::string tempImpl();
|
static std::string tempImpl();
|
||||||
static std::string nullImpl();
|
static std::string nullImpl();
|
||||||
|
static std::string systemImpl();
|
||||||
static std::string expandImpl(const std::string& path);
|
static std::string expandImpl(const std::string& path);
|
||||||
static void listRootsImpl(std::vector<std::string>& roots);
|
static void listRootsImpl(std::vector<std::string>& roots);
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public:
|
|||||||
static std::string homeImpl();
|
static std::string homeImpl();
|
||||||
static std::string tempImpl();
|
static std::string tempImpl();
|
||||||
static std::string nullImpl();
|
static std::string nullImpl();
|
||||||
|
static std::string systemImpl();
|
||||||
static std::string expandImpl(const std::string& path);
|
static std::string expandImpl(const std::string& path);
|
||||||
static void listRootsImpl(std::vector<std::string>& roots);
|
static void listRootsImpl(std::vector<std::string>& roots);
|
||||||
|
|
||||||
|
|||||||
@@ -599,7 +599,7 @@ Path& Path::clear()
|
|||||||
_dirs.clear();
|
_dirs.clear();
|
||||||
_version.clear();
|
_version.clear();
|
||||||
_absolute = false;
|
_absolute = false;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -57,10 +57,36 @@ std::string PathImpl::currentImpl()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string PathImpl::systemImpl()
|
||||||
|
{
|
||||||
|
char buffer[MAX_PATH];
|
||||||
|
DWORD n = GetSystemDirectoryA(buffer, sizeof(buffer));
|
||||||
|
if (n > 0 && n < sizeof(buffer))
|
||||||
|
{
|
||||||
|
std::string result(buffer, n);
|
||||||
|
if (result[n - 1] != '\\')
|
||||||
|
result.append("\\");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else throw SystemException("Cannot get system directory");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string PathImpl::homeImpl()
|
std::string PathImpl::homeImpl()
|
||||||
{
|
{
|
||||||
std::string result = EnvironmentImpl::getImpl("HOMEDRIVE");
|
std::string result;
|
||||||
result.append(EnvironmentImpl::getImpl("HOMEPATH"));
|
|
||||||
|
// windows service has no home dir, return system directory instead
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = EnvironmentImpl::getImpl("HOMEDRIVE");
|
||||||
|
result.append(EnvironmentImpl::getImpl("HOMEPATH"));
|
||||||
|
}
|
||||||
|
catch (NotFoundException&)
|
||||||
|
{
|
||||||
|
result = systemImpl();
|
||||||
|
}
|
||||||
|
|
||||||
std::string::size_type n = result.size();
|
std::string::size_type n = result.size();
|
||||||
if (n > 0 && result[n - 1] != '\\')
|
if (n > 0 && result[n - 1] != '\\')
|
||||||
result.append("\\");
|
result.append("\\");
|
||||||
|
|||||||
@@ -65,10 +65,38 @@ std::string PathImpl::currentImpl()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string PathImpl::systemImpl()
|
||||||
|
{
|
||||||
|
Buffer<wchar_t> buffer(MAX_PATH_LEN);
|
||||||
|
DWORD n = GetSystemDirectoryW(buffer.begin(), static_cast<DWORD>(buffer.size()));
|
||||||
|
if (n > 0)
|
||||||
|
{
|
||||||
|
n = GetLongPathNameW(buffer.begin(), buffer.begin(), static_cast<DWORD>(buffer.size()));
|
||||||
|
if (n <= 0) throw SystemException("Cannot get system directory long path name");
|
||||||
|
std::string result;
|
||||||
|
UnicodeConverter::toUTF8(buffer.begin(), result);
|
||||||
|
if (result[result.size() - 1] != '\\') result.append("\\");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
throw SystemException("Cannot get temporary directory path");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string PathImpl::homeImpl()
|
std::string PathImpl::homeImpl()
|
||||||
{
|
{
|
||||||
std::string result = EnvironmentImpl::getImpl("HOMEDRIVE");
|
std::string result;
|
||||||
result.append(EnvironmentImpl::getImpl("HOMEPATH"));
|
|
||||||
|
// windows service has no home dir, return system directory instead
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = EnvironmentImpl::getImpl("HOMEDRIVE");
|
||||||
|
result.append(EnvironmentImpl::getImpl("HOMEPATH"));
|
||||||
|
}
|
||||||
|
catch (NotFoundException&)
|
||||||
|
{
|
||||||
|
result = systemImpl();
|
||||||
|
}
|
||||||
|
|
||||||
std::string::size_type n = result.size();
|
std::string::size_type n = result.size();
|
||||||
if (n > 0 && result[n - 1] != '\\')
|
if (n > 0 && result[n - 1] != '\\')
|
||||||
result.append("\\");
|
result.append("\\");
|
||||||
|
|||||||
@@ -58,19 +58,9 @@ std::string PathImpl::homeImpl()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string PathImpl::tempImpl()
|
std::string PathImpl::systemImpl()
|
||||||
{
|
{
|
||||||
Buffer<wchar_t> buffer(MAX_PATH_LEN);
|
return("\\");
|
||||||
DWORD n = GetTempPathW(static_cast<DWORD>(buffer.size()), buffer.begin());
|
|
||||||
if (n > 0)
|
|
||||||
{
|
|
||||||
std::string result;
|
|
||||||
UnicodeConverter::toUTF8(buffer.begin(), result);
|
|
||||||
if (result[n - 1] != '\\')
|
|
||||||
result.append("\\");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
throw SystemException("Cannot get current directory");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,15 @@
|
|||||||
#include "Poco/Environment.h"
|
#include "Poco/Environment.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
|
||||||
|
#if defined(_WIN32_WCE)
|
||||||
|
#include "Poco/Path_WINCE.h"
|
||||||
|
#else
|
||||||
|
#include "Poco/Path_WIN32U.h"
|
||||||
|
#endif
|
||||||
|
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||||
|
#include "Poco/Path_WIN32.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using Poco::Path;
|
using Poco::Path;
|
||||||
using Poco::PathSyntaxException;
|
using Poco::PathSyntaxException;
|
||||||
@@ -1625,6 +1634,14 @@ void PathTest::testPushPop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PathTest::testWindowsSystem()
|
||||||
|
{
|
||||||
|
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||||
|
std::cout << Poco::PathImpl::systemImpl() << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PathTest::setUp()
|
void PathTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -1666,6 +1683,7 @@ CppUnit::Test* PathTest::suite()
|
|||||||
CppUnit_addTest(pSuite, PathTest, testSwap);
|
CppUnit_addTest(pSuite, PathTest, testSwap);
|
||||||
CppUnit_addTest(pSuite, PathTest, testResolve);
|
CppUnit_addTest(pSuite, PathTest, testResolve);
|
||||||
CppUnit_addTest(pSuite, PathTest, testPushPop);
|
CppUnit_addTest(pSuite, PathTest, testPushPop);
|
||||||
|
CppUnit_addTest(pSuite, PathTest, testWindowsSystem);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ public:
|
|||||||
void testSwap();
|
void testSwap();
|
||||||
void testResolve();
|
void testResolve();
|
||||||
void testPushPop();
|
void testPushPop();
|
||||||
|
void testWindowsSystem();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|||||||
Reference in New Issue
Block a user