forked from qt-creator/qt-creator
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:
@@ -49,6 +49,11 @@ class QWidget;
|
|||||||
|
|
||||||
QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug dbg, const Utils::FileName &c);
|
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
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
@@ -121,6 +126,28 @@ public:
|
|||||||
static QString resolvePath(const QString &baseDir, const QString &fileName);
|
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
|
class QTCREATOR_UTILS_EXPORT FileReader
|
||||||
{
|
{
|
||||||
Q_DECLARE_TR_FUNCTIONS(Utils::FileUtils) // sic!
|
Q_DECLARE_TR_FUNCTIONS(Utils::FileUtils) // sic!
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "exampleslistmodel.h"
|
#include "exampleslistmodel.h"
|
||||||
#include "screenshotcropper.h"
|
#include "screenshotcropper.h"
|
||||||
|
|
||||||
|
#include <utils/fileutils.h>
|
||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
#include <utils/winutils.h>
|
#include <utils/winutils.h>
|
||||||
|
|
||||||
@@ -199,13 +200,16 @@ void ExamplesWelcomePage::openProject(const ExampleItem &item)
|
|||||||
if (!proFileInfo.exists())
|
if (!proFileInfo.exists())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QFileInfo pathInfo(proFileInfo.path());
|
|
||||||
// If the Qt is a distro Qt on Linux, it will not be writable, hence compilation will fail
|
// If the Qt is a distro Qt on Linux, it will not be writable, hence compilation will fail
|
||||||
if (!proFileInfo.isWritable()
|
// Same if it is installed in non-writable location for other reasons
|
||||||
|| !pathInfo.isWritable() /* path of .pro file */
|
const bool needsCopy = withNTFSPermissions<bool>([proFileInfo] {
|
||||||
|| !QFileInfo(pathInfo.path()).isWritable() /* shadow build directory */) {
|
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);
|
proFile = copyToAlternativeLocation(proFileInfo, filesToOpen, item.dependencies);
|
||||||
}
|
|
||||||
|
|
||||||
// don't try to load help and files if loading the help request is being cancelled
|
// don't try to load help and files if loading the help request is being cancelled
|
||||||
if (proFile.isEmpty())
|
if (proFile.isEmpty())
|
||||||
|
|||||||
Reference in New Issue
Block a user