# # # patch "src/util/Platform.cpp" # from [7f879b0a786869e1df2472adcc6136e252ceca8b] # to [167660f80c70f7d675bfcb0592ced768489bbffe] # # patch "src/util/Platform.h" # from [62d37fa2758d2e842282e5d5daceba20e8fb49b6] # to [d7189f5bcc1063d1133c0e8fe64de81f81b39c9d] # # patch "src/view/dialogs/CheckoutRevision.cpp" # from [e87e47226ce4c690d8d1019d034ea60c85f92763] # to [0885555106b7b5d3ad632286b782f86763b09ad9] # # patch "src/view/dialogs/NewProjectSetup.cpp" # from [4aea59310f5c7e2527f7ddb1866e6b79472f236f] # to [b82fc8e9f06b682ebf3d9dcc93ae0ee7eb40d9c1] # ============================================================ --- src/util/Platform.cpp 7f879b0a786869e1df2472adcc6136e252ceca8b +++ src/util/Platform.cpp 167660f80c70f7d675bfcb0592ced768489bbffe @@ -229,12 +229,42 @@ QString Platform::getUsername() return username; } -bool Platform::mkpath(const QString & path) +QDir Platform::safeMakePath(const QString & path) { + QFileInfo fileInfo(path); + if (fileInfo.exists()) + { + if (!fileInfo.isDir()) + { + throw GuitoneException( + QObject::tr("Path exists, but is not a directory") + ); + } + + if (!fileInfo.isWritable()) + { + throw GuitoneException( + QObject::tr("Directory exists, but is not writable") + ); + } + + QDir dir(fileInfo.absolutePath()); + QDir::Filters filters = QDir::NoDotAndDotDot | QDir::AllEntries | + QDir::Hidden | QDir::System; + if (dir.entryList(filters).size() > 0) + { + throw GuitoneException( + QObject::tr("Directory is not empty") + ); + } + return dir; + } + if (path.indexOf(QRegExp("(^|[\\/])\\.\\.([\\/]|$)")) != -1) { - W("no support for relative paths"); - return false; + throw GuitoneException( + QObject::tr("Relative paths are not supported") + ); } // default to the application's current directory if we get a @@ -245,9 +275,11 @@ bool Platform::mkpath(const QString & pa #ifdef Q_WS_WIN if (path.left(2) == "\\\\") { - W("UNC paths are not supported"); - return false; + throw GuitoneException( + QObject::tr("UNC paths are not supported") + ); } + if (path.mid(1, 2) == ":\\" || path.mid(1, 2) == ":/") { actualPath = path.mid(3); @@ -263,8 +295,9 @@ bool Platform::mkpath(const QString & pa } if (!driveFound) { - W(QString("drive %1 not found").arg(prefixPath)); - return false; + throw GuitoneException( + QObject::tr("Drive %1 does not exist").arg(prefixPath) + ); } } #else @@ -276,6 +309,13 @@ bool Platform::mkpath(const QString & pa #endif QDir dir(prefixPath); - return dir.mkpath(actualPath); + if (dir.mkpath(actualPath)) + { + throw GuitoneException( + QObject::tr("Path could not be created") + ); + } + + return dir; } ============================================================ --- src/util/Platform.h 62d37fa2758d2e842282e5d5daceba20e8fb49b6 +++ src/util/Platform.h d7189f5bcc1063d1133c0e8fe64de81f81b39c9d @@ -20,6 +20,7 @@ #define PLATFORM_H #include +#include class Platform { @@ -34,9 +35,10 @@ public: */ static QString getUsername(); /** - * Creates all unknown directries along the given path + * Safely tries to create the directory path from the argument and if + * the path already exists, ensures that its valid and writable */ - static bool mkpath(const QString & path); + static QDir safeMakePath(const QString & path); }; #endif ============================================================ --- src/view/dialogs/CheckoutRevision.cpp e87e47226ce4c690d8d1019d034ea60c85f92763 +++ src/view/dialogs/CheckoutRevision.cpp 0885555106b7b5d3ad632286b782f86763b09ad9 @@ -19,6 +19,7 @@ #include "CheckoutRevision.h" #include "MonotoneUtil.h" #include "Settings.h" +#include "Platform.h" #include "WorkspaceCreator.h" #include @@ -159,67 +160,23 @@ void CheckoutRevision::accept() return; } - QString checkoutPath = localCheckoutPath->text(); - QDir checkoutDir(checkoutPath); - - // check if the dir exists, and if not, create it - if (!checkoutDir.exists()) + QDir checkoutDir; + try { - QMessageBox::StandardButton btn = QMessageBox::question( - this, - tr("Directory does not exist"), - tr("The checkout directory does not exist, " - "do you want to create it?"), - QMessageBox::Yes | QMessageBox::No - ); - - if (btn == QMessageBox::No) return; - - checkoutDir.setPath(QDir::rootPath()); - if (!checkoutDir.mkpath(checkoutPath)) - { - QMessageBox::critical( - this, - tr("Directory path could not be created"), - tr("The directory path could not be created, " - "please check your permissions or enter a different one."), - QMessageBox::Ok - ); - return; - } - checkoutDir.setPath(checkoutPath); + checkoutDir = Platform::safeMakePath(localCheckoutPath->text()); } - - // check permissions - QFileInfo info(checkoutDir.absolutePath()); - if (!info.isWritable()) + catch (GuitoneException & e) { - QMessageBox::critical( + QMessageBox::critical( this, - tr("Directory not writable"), - tr("The directory is not writable, " - "please check your permissions or enter a different one."), + tr("Could not create export directory"), + tr("The directory could not be used / created:\n%1") + .arg(e.what()), QMessageBox::Ok ); return; } - QDir::Filters filters = QDir::NoDotAndDotDot | QDir::AllEntries | - QDir::Hidden | QDir::System; - // ensure the user acknowledges that a directory may not be empty - if (checkoutDir.entryList(filters).size() > 0) - { - QMessageBox::StandardButton btn = QMessageBox::question( - this, - tr("Directory not empty"), - tr("The checkout directory is not empty. " - "Do you want to continue?"), - QMessageBox::Yes | QMessageBox::No - ); - - if (btn == QMessageBox::No) return; - } - WorkspaceCreator creator(databaseFile, revList.at(0), checkoutDir); if (!creator.run()) ============================================================ --- src/view/dialogs/NewProjectSetup.cpp 4aea59310f5c7e2527f7ddb1866e6b79472f236f +++ src/view/dialogs/NewProjectSetup.cpp b82fc8e9f06b682ebf3d9dcc93ae0ee7eb40d9c1 @@ -19,6 +19,7 @@ #include "NewProjectSetup.h" #include "WorkspaceCreator.h" #include "MonotoneUtil.h" +#include "Platform.h" #include #include @@ -70,55 +71,37 @@ void NewProjectSetup::accept() return; } - QDir workspace(workspacePath->text()); - if (workspace.exists()) + QDir workspaceDir; + try { - QFileInfo fileInfo(workspacePath->text()); - if (fileInfo.exists() && !fileInfo.isDir()) - { - QMessageBox::critical( - this, - tr("Invalid path"), - tr("The selected path exists, but is not a directory."), - QMessageBox::Ok - ); - return; - } - - if (workspace.cd("_MTN")) - { - QMessageBox::critical( - this, - tr("Directory is a workspace"), - tr("The selected directory already contains a monotone workspace."), - QMessageBox::Ok - ); - return; - } - - QMessageBox::StandardButton btn = QMessageBox::question( + workspaceDir = Platform::safeMakePath(workspacePath->text()); + } + catch (GuitoneException & e) + { + QMessageBox::critical( this, - tr("Directory exists"), - tr("The selected directory already exists. " - "Do you want to continue?"), - QMessageBox::Yes | QMessageBox::No + tr("Could not create workspace"), + tr("The directory could not be used / created:\n%1") + .arg(e.what()), + QMessageBox::Ok ); - - if (btn == QMessageBox::No) return; + return; } - if (!WorkspaceCreator::createBookkeepingDirectory(workspace, db, branchName)) + if (!WorkspaceCreator::createBookkeepingDirectory(workspaceDir, db, branchName)) { QMessageBox::critical( this, - tr("Could not create bookkeeping directory"), - tr("Could not create bookkeeping directory - please check the log for details."), + tr("Could not create workspace"), + tr("Could not create bookkeeping directory in '%1' " + "- please check the log for details.") + .arg(workspaceDir.absolutePath()), QMessageBox::Ok ); return; } - emit newProjectCreated(workspace.absolutePath()); + emit newProjectCreated(workspaceDir.absolutePath()); done(0); }