changeset 348:076c2b3de51b bug_92

Reject only non-empty directories as clone targets: we're happy if the directory exists but is empty
author Chris Cannam
date Wed, 16 Mar 2011 12:10:56 +0000
parents 987a094047c9
children b422d1bcfb3c
files mainwindow.cpp
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mainwindow.cpp	Wed Mar 16 10:46:10 2011 +0000
+++ b/mainwindow.cpp	Wed Mar 16 12:10:56 2011 +0000
@@ -1243,14 +1243,25 @@
 
 QString MainWindow::complainAboutCloneToExistingFolder(QString arg, QString remote)
 {
-    // If the directory "arg" exists but "arg" plus the last path
-    // component of "remote" does not, then offer the latter as an
-    // alternative path
+    // If the directory "arg" exists but is empty, then we accept it.
+
+    // If the directory "arg" exists and is non-empty, but "arg" plus
+    // the last path component of "remote" does not exist, then offer
+    // the latter as an alternative path.
 
     QString offer;
 
     QDir d(arg);
+
     if (d.exists()) {
+
+        if (d.entryList(QDir::Dirs | QDir::Files |
+                        QDir::NoDotAndDotDot |
+                        QDir::Hidden | QDir::System).empty()) {
+            // directory is empty; accept it
+            return arg;
+        }
+
         if (QRegExp("^\\w+://").indexIn(remote) >= 0) {
             QString rpath = QUrl(remote).path();
             if (rpath != "") {