SqlDatabase: Ask freeSpace for directory, fix for Windows
authorChristian Kamm <mail@ckamm.de>
Wed, 26 Apr 2017 08:12:26 +0000 (10:12 +0200)
committerckamm <mail@ckamm.de>
Wed, 26 Apr 2017 10:38:04 +0000 (12:38 +0200)
See owncloud/enterprise#1955

src/libsync/ownsql.cpp
src/libsync/utility.h

index e4cebd7935852f46bfb8cb99db55bf0620d60d61..7008ccf52b6419d2bf0e24cfe57b561cd781a628 100644 (file)
@@ -17,6 +17,8 @@
 #include <QString>
 #include <QDebug>
 #include <QFile>
+#include <QFileInfo>
+#include <QDir>
 
 #include "ownsql.h"
 #include "utility.h"
@@ -101,8 +103,8 @@ bool SqlDatabase::openOrCreateReadWrite( const QString& filename )
 
     if( !checkDb() ) {
         // When disk space is low, checking the db may fail even though it's fine.
-        qint64 freeSpace = Utility::freeDiskSpace(filename);
-        if (freeSpace < 1000000) {
+        qint64 freeSpace = Utility::freeDiskSpace(QFileInfo(filename).dir().absolutePath());
+        if (freeSpace != -1 && freeSpace < 1000000) {
             qDebug() << "Consistency check failed, disk space is low, aborting" << freeSpace;
             close();
             return false;
index 5fb60c7292866cd09b41270f124601694b8a37d7..95febc9117b20854f423629639f6fc72faefe100 100644 (file)
@@ -43,6 +43,12 @@ namespace Utility
     OWNCLOUDSYNC_EXPORT QByteArray userAgentString();
     OWNCLOUDSYNC_EXPORT bool hasLaunchOnStartup(const QString &appName);
     OWNCLOUDSYNC_EXPORT void setLaunchOnStartup(const QString &appName, const QString& guiName, bool launch);
+
+    /**
+     * Return the amount of free space available.
+     *
+     * \a path must point to a directory
+     */
     OWNCLOUDSYNC_EXPORT qint64 freeDiskSpace(const QString &path);
 
     /**