application: --confdir option with invalid direcotry now exit
authorOlivier Goffart <ogoffart@woboq.com>
Mon, 23 Mar 2015 13:59:29 +0000 (14:59 +0100)
committerOlivier Goffart <ogoffart@woboq.com>
Mon, 23 Mar 2015 14:02:27 +0000 (15:02 +0100)
Show an error and exit if an invalid directory (eg, a file) is passed to --confdir

Fixes: #2453
src/gui/application.cpp
src/libsync/configfile.cpp
src/libsync/configfile.h

index eb2fac6ee4bf1db5c7597afffef4f6a0cb718b92..1e554cdcae767077e423734236ed84923fdbd4dd 100644 (file)
@@ -403,7 +403,10 @@ void Application::parseOptions(const QStringList &options)
         } else if (option == QLatin1String("--confdir")) {
             if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
                 QString confDir = it.next();
-                ConfigFile::setConfDir( confDir );
+                if (!ConfigFile::setConfDir( confDir )) {
+                    std::cerr << "Invalid path passed to --confdir" << std::endl;
+                    std::exit(1);
+                }
             } else {
                 showHelp();
             }
index 47850aa8edfe64b697fb9b4176f8a38a38769246..ba63864cd06aa2cda9fd2fcc0666c631e2ff3666 100644 (file)
@@ -85,10 +85,10 @@ ConfigFile::ConfigFile()
     // qDebug() << Q_FUNC_INFO << "Loading config: " << config << " (URL is " << settings.value("url").toString() << ")";
 }
 
-void ConfigFile::setConfDir(const QString &value)
+bool ConfigFile::setConfDir(const QString &value)
 {
     QString dirPath = value;
-    if( dirPath.isEmpty() ) return;
+    if( dirPath.isEmpty() ) return false;
 
     QFileInfo fi(dirPath);
     if ( !fi.exists() && !fi.isAbsolute() ) {
@@ -101,7 +101,9 @@ void ConfigFile::setConfDir(const QString &value)
         dirPath = fi.absoluteFilePath();
         qDebug() << "** Using custom config dir " << dirPath;
         _confDir=dirPath;
+        return true;
     }
+    return false;
 }
 
 bool ConfigFile::optionalDesktopNotifications() const
index 4572c9fcc0789a9b793d19975959be6752eb7c00..54652b6c97c7f4ea187238a3d671ae66752532bf 100644 (file)
@@ -96,7 +96,7 @@ public:
     void setUploadLimit(int kbytes);
     void setDownloadLimit(int kbytes);
 
-    static void setConfDir(const QString &value);
+    static bool setConfDir(const QString &value);
 
     bool optionalDesktopNotifications() const;
     void setOptionalDesktopNotifications(bool show);