Fix broken target directory handling.

Files and syminks are not allowed as target dir either.
Fixes a broken check if the selected target contains an
installation already. Do not complain on empty targets.
This commit is contained in:
kh1 2011-04-13 08:19:34 +02:00
parent 1f2883f47a
commit c31eddb8fa
2 changed files with 26 additions and 6 deletions

View File

@ -32,6 +32,7 @@
**************************************************************************/
#include "installerbasecommons.h"
#include <common/installersettings.h>
#include <messageboxhandler.h>
#include <qinstaller.h>
#include <qinstallercomponent.h>
@ -236,9 +237,13 @@ bool TargetDirectoryPageImpl::validatePage()
if (!QVariant(remove).toBool())
return true;
if (QFileInfo(targetDir()).isDir()) {
QFileInfo fi2(targetDir() + QDir::separator() + installer()->uninstallerName());
if (QDir(targetDir()) == QDir::root()) {
const QDir dir(targetDir());
if (dir.exists() && dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty())
return true;
QFileInfo fi(targetDir());
if (fi.isDir()) {
if (dir == QDir::root()) {
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
QLatin1String("forbiddenTargetDirectory"), tr("Error"),
tr("As the install directory is completely deleted installing in %1 is forbidden")
@ -246,6 +251,15 @@ bool TargetDirectoryPageImpl::validatePage()
return false;
}
QString fileName = installer()->settings().uninstallerName();
#if defined(Q_WS_MAC)
if (QFileInfo(QCoreApplication::applicationDirPath() + QLatin1String("/../..")).isBundle())
fileName += QLatin1String(".app/Contents/MacOS/") + fileName;
#elif defined(Q_OS_WIN)
fileName += QLatin1String(".exe");
#endif
QFileInfo fi2(targetDir() + QDir::separator() + fileName);
if (fi2.exists()) {
return askQuestion(QLatin1String("overwriteTargetDirectory"),
TargetDirectoryPageImpl::tr("The folder you selected exists already and "
@ -257,6 +271,12 @@ bool TargetDirectoryPageImpl::validatePage()
"Note that it will be completely wiped on uninstallation of this application.\n"
"It is not advisable to install into this folder as installation might fail.\n"
"Do you want to continue?"));
} else if (fi.isFile() || fi.isSymLink()) {
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
QLatin1String("WrongTargetDirectory"), tr("Error"),
tr("You have selected an existing file or symlink, please choose a different target for "
"installation."), QMessageBox::Ok);
return false;
}
return true;
}

View File

@ -1144,10 +1144,10 @@ bool TargetDirectoryPage::validatePage()
if (targetDir().isEmpty()) {
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
QLatin1String("forbiddenTargetDirectory"), tr("Error"),
tr( "The install directory cannot be empty, please specify a valid folder"),
QMessageBox::Ok);
tr( "The install directory cannot be empty, please specify a valid folder"), QMessageBox::Ok);
return false;
}
const QDir dir(targetDir());
// it exists, but is empty (might be created by the Browse button (getExistingDirectory)
if (dir.exists() && dir.entryList(QDir::NoDotAndDotDot).isEmpty()) {