From 0d85d0a777024ad795f3dd34705f9ac07b13fad0 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 22 Jun 2010 11:53:49 +0000 Subject: [PATCH] Free disk space calculation also works if the destination path does not exist --- src/misc.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/misc.cpp b/src/misc.cpp index 75a6a4267..24689a5cd 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -134,9 +134,15 @@ QString misc::QDesktopServicesCacheLocation() { long long misc::freeDiskSpaceOnPath(QString path) { if(path.isEmpty()) return -1; + path = path.replace("\\", "/"); QDir dir_path(path); if(!dir_path.exists()) { - if(!dir_path.cdUp()) return -1; + QStringList parts = path.split("/"); + while (parts.size() > 1 && !QDir(parts.join("/")).exists()) { + parts.removeLast(); + } + dir_path = QDir(parts.join("/")); + if(!dir_path.exists()) return -1; } Q_ASSERT(dir_path.exists()); #ifndef Q_WS_WIN