Fixed bugs in scanFolder() and fileIterator.
This commit is contained in:
parent
5c8333cb1e
commit
510979b5ef
@ -32,7 +32,8 @@ namespace messaging {
|
||||
|
||||
|
||||
maildirFolder::maildirFolder(const folder::path& path, maildirStore* store)
|
||||
: m_store(store), m_path(path), m_name(path.getLastComponent()), m_mode(-1), m_open(false)
|
||||
: m_store(store), m_path(path), m_name(path.getLastComponent()), m_mode(-1), m_open(false),
|
||||
m_unreadMessageCount(0), m_messageCount(0)
|
||||
{
|
||||
m_store->registerFolder(this);
|
||||
}
|
||||
@ -261,6 +262,9 @@ void maildirFolder::scanFolder()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_messageCount = 0;
|
||||
m_unreadMessageCount = 0;
|
||||
|
||||
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
|
||||
|
||||
utility::file::path newDirPath = maildirUtils::getFolderFSPath
|
||||
@ -272,7 +276,7 @@ void maildirFolder::scanFolder()
|
||||
utility::auto_ptr <utility::file> curDir = fsf->create(curDirPath);
|
||||
|
||||
// New received messages (new/)
|
||||
utility::auto_ptr <utility::fileIterator> nit = newDir->getFiles();
|
||||
utility::fileIterator* nit = newDir->getFiles();
|
||||
std::vector <utility::file::path::component> newMessageFilenames;
|
||||
|
||||
while (nit->hasMoreElements())
|
||||
@ -281,8 +285,10 @@ void maildirFolder::scanFolder()
|
||||
newMessageFilenames.push_back(file->getFullPath().getLastComponent());
|
||||
}
|
||||
|
||||
delete (nit); // Free directory
|
||||
|
||||
// Current messages (cur/)
|
||||
utility::auto_ptr <utility::fileIterator> cit = curDir->getFiles();
|
||||
utility::fileIterator* cit = curDir->getFiles();
|
||||
std::vector <utility::file::path::component> curMessageFilenames;
|
||||
|
||||
while (cit->hasMoreElements())
|
||||
@ -291,6 +297,8 @@ void maildirFolder::scanFolder()
|
||||
curMessageFilenames.push_back(file->getFullPath().getLastComponent());
|
||||
}
|
||||
|
||||
delete (cit); // Free directory
|
||||
|
||||
// Update/delete existing messages (found in previous scan)
|
||||
for (unsigned int i = 0 ; i < m_messageInfos.size() ; ++i)
|
||||
{
|
||||
@ -322,6 +330,9 @@ void maildirFolder::scanFolder()
|
||||
}
|
||||
}
|
||||
|
||||
m_messageInfos.reserve(m_messageInfos.size()
|
||||
+ newMessageFilenames.size() + curMessageFilenames.size());
|
||||
|
||||
// Add new messages from 'new': we are responsible to move the files
|
||||
// from the 'new' directory to the 'cur' directory, and append them
|
||||
// to our message list.
|
||||
@ -458,28 +469,38 @@ void maildirFolder::listFolders(std::vector <folder*>& list, const bool recursiv
|
||||
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
|
||||
|
||||
utility::auto_ptr <utility::file> rootDir = fsf->create
|
||||
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_CONTAINER));
|
||||
utility::auto_ptr <utility::fileIterator> it = rootDir->getFiles();
|
||||
(maildirUtils::getFolderFSPath(m_store, m_path,
|
||||
m_path.isEmpty() ? maildirUtils::FOLDER_PATH_ROOT
|
||||
: maildirUtils::FOLDER_PATH_CONTAINER));
|
||||
|
||||
while (it->hasMoreElements())
|
||||
if (rootDir->exists())
|
||||
{
|
||||
utility::auto_ptr <utility::file> file = it->nextElement();
|
||||
utility::auto_ptr <utility::fileIterator> it = rootDir->getFiles();
|
||||
|
||||
if (maildirUtils::isSubfolderDirectory(*file))
|
||||
while (it->hasMoreElements())
|
||||
{
|
||||
const utility::path subPath = m_path / file->getFullPath().getLastComponent();
|
||||
maildirFolder* subFolder = new maildirFolder(subPath, m_store);
|
||||
utility::auto_ptr <utility::file> file = it->nextElement();
|
||||
|
||||
list.push_back(subFolder);
|
||||
if (maildirUtils::isSubfolderDirectory(*file))
|
||||
{
|
||||
const utility::path subPath = m_path / file->getFullPath().getLastComponent();
|
||||
maildirFolder* subFolder = new maildirFolder(subPath, m_store);
|
||||
|
||||
if (recursive)
|
||||
subFolder->listFolders(list, true);
|
||||
list.push_back(subFolder);
|
||||
|
||||
if (recursive)
|
||||
subFolder->listFolders(list, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No sub-folder
|
||||
}
|
||||
}
|
||||
catch (exceptions::filesystem_exception& e)
|
||||
{
|
||||
throw exceptions::command_error("LIST", e.what());
|
||||
throw exceptions::command_error("LIST", "", "", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,8 @@
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "../../exception.hpp"
|
||||
|
||||
|
||||
@ -49,7 +51,7 @@ posixFileIterator::posixFileIterator(const vmime::utility::file::path& path, con
|
||||
if ((m_dir = ::opendir(m_nativePath.c_str())) == NULL)
|
||||
posixFileSystemFactory::reportError(path, errno);
|
||||
|
||||
m_dirEntry = ::readdir(m_dir);
|
||||
getNextElement();
|
||||
}
|
||||
|
||||
|
||||
@ -70,12 +72,28 @@ vmime::utility::file* posixFileIterator::nextElement()
|
||||
{
|
||||
posixFile* file = new posixFile(m_path / vmime::utility::file::path::component(m_dirEntry->d_name));
|
||||
|
||||
m_dirEntry = ::readdir(m_dir);
|
||||
getNextElement();
|
||||
|
||||
return (file);
|
||||
}
|
||||
|
||||
|
||||
void posixFileIterator::getNextElement()
|
||||
{
|
||||
while (m_dirEntry = ::readdir(m_dir))
|
||||
{
|
||||
const char* name = m_dirEntry->d_name;
|
||||
const int len = ::strlen(name);
|
||||
|
||||
if (!(len == 1 && name[0] == '.') &&
|
||||
!(len == 2 && name[0] == '.' && name[1] == '.'))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// posixFileWriterOutputStream
|
||||
@ -399,6 +417,9 @@ const vmime::utility::file::path posixFileSystemFactory::stringToPathImpl(const
|
||||
offset++;
|
||||
}
|
||||
|
||||
if (prev < str.length())
|
||||
path.appendComponent(vmime::string(str.begin() + prev, str.end()));
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
@ -409,7 +430,7 @@ const vmime::string posixFileSystemFactory::pathToStringImpl(const vmime::utilit
|
||||
|
||||
for (int i = 0 ; i < path.getSize() ; ++i)
|
||||
{
|
||||
if (i >= 0)
|
||||
if (i > 0)
|
||||
native += "/";
|
||||
|
||||
native += path[i].getBuffer();
|
||||
@ -460,7 +481,7 @@ void posixFileSystemFactory::reportError(const vmime::utility::path& path, const
|
||||
default:
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "Unknown error " << err << ".";
|
||||
oss << ::strerror(err) << ".";
|
||||
|
||||
desc = oss.str();
|
||||
break;
|
||||
|
@ -121,6 +121,8 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void getNextElement();
|
||||
|
||||
vmime::utility::file::path m_path;
|
||||
vmime::string m_nativePath;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user