From dce4493590bbf72a95a4e55951ecb2fe92a53287 Mon Sep 17 00:00:00 2001 From: Till Adam Date: Mon, 2 Jun 2003 20:30:38 +0000 Subject: [PATCH] Check whether the dir that is to be used as the local mail store (~/Mail) exists, is a dir, is readable and writeable, if it needs to be created that creation succeeded and bail out otherwise. It would be nice, I guess, to ask the user for an alternative dir to use, but this fixes the reported crashes, at least. The change to main.cpp is necessary to prevent kmail from acting like the KUniqueApplication it is and try to bring up a new instance while we are engaged in our somewhat onesided discussion with the user. CC: 59244-done@bugs.kde.org CC: 56278-done@bugs.kde.org svn path=/trunk/kdepim/; revision=229374 --- kmfoldermgr.cpp | 30 ++++++++++++++++++++++-------- main.cpp | 8 ++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/kmfoldermgr.cpp b/kmfoldermgr.cpp index 682776a24..59a8b896a 100644 --- a/kmfoldermgr.cpp +++ b/kmfoldermgr.cpp @@ -121,8 +121,6 @@ void KMFolderMgr::compactAllAux(KMFolderDir* dir) //----------------------------------------------------------------------------- void KMFolderMgr::setBasePath(const QString& aBasePath) { - QDir dir; - assert(!aBasePath.isNull()); if (aBasePath[0] == '~') @@ -134,14 +132,30 @@ void KMFolderMgr::setBasePath(const QString& aBasePath) else mBasePath = aBasePath; + QFileInfo info( mBasePath ); - dir.setPath(mBasePath); - if (!dir.exists()) - { - // FIXME: mkdir can fail! - mkdir(QFile::encodeName(mBasePath), 0700); + // FIXME We should ask for an alternative dir, rather than bailing out, + // I guess - till + if ( info.exists() ) { + if ( !info.isDir() ) { + KMessageBox::sorry(0, i18n("%1 does not appear to be a directory.\n" + "Please move the file out of the way.\n").arg( mBasePath ) ); + ::exit(-1); + } + if ( !info.isReadable() || !info.isWritable() ) { + KMessageBox::sorry(0, i18n("Permissions on the %1 directory are incorrect!\n" + "Please set them to 0700.\n").arg( mBasePath ) ); + ::exit(-1); + } + } else { + // ~/Mail (or whatever the user specified) doesn't exist, create it + if ( ::mkdir( QFile::encodeName( mBasePath ) , S_IRWXU ) == -1 ) { + KMessageBox::sorry(0, i18n("KMail couldn't create %1 directory !\n" + "Make sure you have write permissions in %2 directory.\n") + .arg( mBasePath ).arg( QDir::homeDirPath() ) ); + ::exit(-1); + } } - mDir.setPath(mBasePath); mDir.reload(); contentsChanged(); diff --git a/main.cpp b/main.cpp index f3948cf0d..db5fbb9bd 100644 --- a/main.cpp +++ b/main.cpp @@ -9,6 +9,7 @@ #include #include "kmkernel.h" //control center #include +#include #undef Status // stupid X headers @@ -73,6 +74,13 @@ int KMailApplication::newInstance() bool checkMail = false; //bool viewOnly = false; + if (dcopClient()->isSuspended()) + { + // Try again later. + QTimer::singleShot( 100, this, SLOT(newInstance()) ); + return; + } + // process args: KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (args->getOption("subject"))