Overview
Features
Download
Documentation
Community
Add-Ons & Services

DirectoryIteratorImpl::DirectoryIteratorImpl() bug

Please post support and help requests here.

DirectoryIteratorImpl::DirectoryIteratorImpl() bug

Postby keith » 01 May 2007, 12:49

Code in DirectoryIteratorImpl constructor includes:

_fh = FindFirstFileW(uFindPath.c_str(), &_fd);

if (_fh == INVALID_HANDLE_VALUE)

{
if (GetLastError() != ERROR_NO_MORE_FILES)
FileImpl::handleError(path);

}

UnicodeConverter::toUTF8(_fd.cFileName, _current);

if (_current == "." OR _current == "..")
next();


and this should be fixed to:

_fh = FindFirstFileW(uFindPath.c_str(), &_fd);

if (_fh == INVALID_HANDLE_VALUE)

{

if (GetLastError() != ERROR_NO_MORE_FILES)

FileImpl::handleError(path);

else

_current.clear();

}

else

{

UnicodeConverter::toUTF8(_fd.cFileName, _current);

if (_current == "." OR _current == "..")

next();

}


Definately needs fixed in the WIN32/WIN32U implementations - probably needs a similar fix in the UNIX implementation also. If not fixed, then get random invalid File.list() results on empty directories, and also causes File.remove(true) to throw up occasionally.

BTW, how do I format code in this comment box ?, I tried wrapping it in 'code' tags to no avail - so please accept my apologies for the bad formatting in the code above (replace the OR with ||).

Cheers,
Keith.
keith
 
Posts: 4
Joined: 25 Apr 2007, 14:10

Re: DirectoryIteratorImpl::DirectoryIteratorImpl() bug

Postby keith » 01 May 2007, 13:03

I've figured out how to format:

the buggy code is:

Code: Select all

_fh = FindFirstFileW(uFindPath.c_str(), &_fd);
   if (_fh == INVALID_HANDLE_VALUE)
   {
      if (GetLastError() != ERROR_NO_MORE_FILES)
         FileImpl::handleError(path);
   }
   UnicodeConverter::toUTF8(_fd.cFileName, _current);
   if (_current == "." || _current == "..")   
      next();


and the less buggy code is:

Code: Select all

_fh = FindFirstFileW(uFindPath.c_str(), &_fd);
   if (_fh == INVALID_HANDLE_VALUE)
   {
      if (GetLastError() != ERROR_NO_MORE_FILES)
         FileImpl::handleError(path);
      else
         _current.clear();
   }
   else
   {
      UnicodeConverter::toUTF8(_fd.cFileName, _current);
      if (_current == "." || _current == "..")   
         next();
   }


Cheers,
Keith.
keith
 
Posts: 4
Joined: 25 Apr 2007, 14:10

Re: DirectoryIteratorImpl::DirectoryIteratorImpl() bug

Postby guenter » 01 May 2007, 13:45

Thank you Keith, I have fixed it.

Guenter
guenter
 
Posts: 1092
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest