check for initialization with an empty pattern (backport from old trunk)

This commit is contained in:
Marian Krivos 2012-08-07 20:56:38 +00:00
parent 9e27531c68
commit 2f0ab58544

View File

@ -46,11 +46,10 @@
namespace Poco { namespace Poco {
Glob::Glob(const std::string& pattern, int options): Glob::Glob(const std::string& pattern, int options)
_pattern(pattern), : _pattern(pattern), _options(options)
_options(options)
{ {
poco_assert (!_pattern.empty()); poco_assert(!_pattern.empty());
} }
@ -90,20 +89,21 @@ void Glob::glob(const Path& pathPattern, std::set<std::string>& files, int optio
{ {
Path pattern(pathPattern); Path pattern(pathPattern);
pattern.makeDirectory(); // to simplify pattern handling later on pattern.makeDirectory(); // to simplify pattern handling later on
Path base(pattern); Path base(pattern);
Path absBase(base); Path absBase(base);
absBase.makeAbsolute(); absBase.makeAbsolute();
// In case of UNC paths we must not pop the topmost directory // In case of UNC paths we must not pop the topmost directory
// (which must not contain wildcards), otherwise collect() will fail // (which must not contain wildcards), otherwise collect() will fail
// as one cannot create a DirectoryIterator with only a node name ("\\srv\"). // as one cannot create a DirectoryIterator with only a node name ("\\srv\").
int minDepth = base.getNode().empty() ? 0 : 1; int minDepth = base.getNode().empty() ? 0 : 1;
while (base.depth() > minDepth && base[base.depth() - 1] != "..") while (base.depth() > minDepth && base[base.depth() - 1] != "..")
{ {
base.popDirectory(); base.popDirectory();
absBase.popDirectory(); absBase.popDirectory();
} }
if (pathPattern.isDirectory()) options |= GLOB_DIRS_ONLY; if (pathPattern.isDirectory())
collect(pattern, absBase, base, pathPattern[base.depth()], files, options); options |= GLOB_DIRS_ONLY;
collect(pattern, absBase, base, pathPattern[base.depth()], files, options);
} }