Fixed directory renaming.

This commit is contained in:
Vincent Richard 2009-12-01 14:24:55 +00:00
parent ee2fa4feaf
commit 82e1a690d9
4 changed files with 85 additions and 3 deletions

View File

@ -396,7 +396,11 @@ void posixFile::rename(const path& newName)
const vmime::string newNativePath = posixFileSystemFactory::pathToStringImpl(newName);
posixFile dest(newName);
dest.createFile();
if (isDirectory())
dest.createDirectory();
else
dest.createFile();
if (::rename(m_nativePath.c_str(), newNativePath.c_str()) == -1)
posixFileSystemFactory::reportError(m_path, errno);

View File

@ -322,12 +322,28 @@ public:
void testRenameFolder_KMail()
{
testRenameFolderImpl(TEST_MAILDIR_KMAIL, TEST_MAILDIRFILES_KMAIL);
try
{
testRenameFolderImpl(TEST_MAILDIR_KMAIL, TEST_MAILDIRFILES_KMAIL);
}
catch (vmime::exception& e)
{
std::cerr << e;
throw e;
}
}
void testRenameFolder_Courier()
{
testRenameFolderImpl(TEST_MAILDIR_COURIER, TEST_MAILDIRFILES_COURIER);
try
{
testRenameFolderImpl(TEST_MAILDIR_COURIER, TEST_MAILDIRFILES_COURIER);
}
catch (vmime::exception& e)
{
std::cerr << e;
throw e;
}
}
void testRenameFolderImpl(const vmime::string* const dirs, const vmime::string* const files)

View File

@ -187,3 +187,61 @@ vmime::ref <vmime::net::timeoutHandler> testTimeoutHandlerFactory::create()
return vmime::create <testTimeoutHandler>();
}
// Exception helper
std::ostream& operator<<(std::ostream& os, const vmime::exception& e)
{
os << "* vmime::exceptions::" << e.name() << std::endl;
os << " what = " << e.what() << std::endl;
// More information for special exceptions
if (dynamic_cast <const vmime::exceptions::command_error*>(&e))
{
const vmime::exceptions::command_error& cee =
dynamic_cast <const vmime::exceptions::command_error&>(e);
os << " command = " << cee.command() << std::endl;
os << " response = " << cee.response() << std::endl;
}
if (dynamic_cast <const vmime::exceptions::invalid_response*>(&e))
{
const vmime::exceptions::invalid_response& ir =
dynamic_cast <const vmime::exceptions::invalid_response&>(e);
os << " response = " << ir.response() << std::endl;
}
if (dynamic_cast <const vmime::exceptions::connection_greeting_error*>(&e))
{
const vmime::exceptions::connection_greeting_error& cgee =
dynamic_cast <const vmime::exceptions::connection_greeting_error&>(e);
os << " response = " << cgee.response() << std::endl;
}
if (dynamic_cast <const vmime::exceptions::authentication_error*>(&e))
{
const vmime::exceptions::authentication_error& aee =
dynamic_cast <const vmime::exceptions::authentication_error&>(e);
os << " response = " << aee.response() << std::endl;
}
if (dynamic_cast <const vmime::exceptions::filesystem_exception*>(&e))
{
const vmime::exceptions::filesystem_exception& fse =
dynamic_cast <const vmime::exceptions::filesystem_exception&>(e);
os << " path = " << vmime::platform::getHandler()->
getFileSystemFactory()->pathToString(fse.path()) << std::endl;
}
if (e.other() != NULL)
os << *e.other();
return os;
}

View File

@ -305,3 +305,7 @@ public:
vmime::ref <vmime::net::timeoutHandler> create();
};
// Exception helper
std::ostream& operator<<(std::ostream& os, const vmime::exception& e);