Fix check if example location is writable on Windows

The normal permission check done by QFileInfo is not sufficient in many
cases.

Task-number: QTCREATORBUG-18184
Change-Id: Icab92c592e6d3c8610304e0b987eded6142f4ab3
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2017-05-24 15:31:40 +02:00
parent 2307e4d2cc
commit a834c5104d
2 changed files with 36 additions and 5 deletions

View File

@@ -49,6 +49,11 @@ class QWidget;
QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug dbg, const Utils::FileName &c);
// for withNTFSPermissions
#ifdef Q_OS_WIN
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
#endif
QT_END_NAMESPACE
namespace Utils {
@@ -121,6 +126,28 @@ public:
static QString resolvePath(const QString &baseDir, const QString &fileName);
};
// for actually finding out if e.g. directories are writable on Windows
#ifdef Q_OS_WIN
template <typename T>
static T withNTFSPermissions(const std::function<T()> &task)
{
qt_ntfs_permission_lookup++;
T result = task();
qt_ntfs_permission_lookup--;
return result;
}
#else // Q_OS_WIN
template <typename T>
static T withNTFSPermissions(const std::function<T()> &task)
{
return task();
}
#endif // Q_OS_WIN
class QTCREATOR_UTILS_EXPORT FileReader
{
Q_DECLARE_TR_FUNCTIONS(Utils::FileUtils) // sic!

View File

@@ -28,6 +28,7 @@
#include "exampleslistmodel.h"
#include "screenshotcropper.h"
#include <utils/fileutils.h>
#include <utils/pathchooser.h>
#include <utils/winutils.h>
@@ -199,13 +200,16 @@ void ExamplesWelcomePage::openProject(const ExampleItem &item)
if (!proFileInfo.exists())
return;
QFileInfo pathInfo(proFileInfo.path());
// If the Qt is a distro Qt on Linux, it will not be writable, hence compilation will fail
if (!proFileInfo.isWritable()
|| !pathInfo.isWritable() /* path of .pro file */
|| !QFileInfo(pathInfo.path()).isWritable() /* shadow build directory */) {
// Same if it is installed in non-writable location for other reasons
const bool needsCopy = withNTFSPermissions<bool>([proFileInfo] {
QFileInfo pathInfo(proFileInfo.path());
return !proFileInfo.isWritable()
|| !pathInfo.isWritable() /* path of .pro file */
|| !QFileInfo(pathInfo.path()).isWritable() /* shadow build directory */;
});
if (needsCopy)
proFile = copyToAlternativeLocation(proFileInfo, filesToOpen, item.dependencies);
}
// don't try to load help and files if loading the help request is being cancelled
if (proFile.isEmpty())