Fix creating directory hierarchy for WinRT

mkpath was not working consistently on WinRT. The reason is that
createDirectory() starts from C:/ which is outside the sandbox and an
illegal access error has been returned.

In case the chunk is still inside the "known" writable area, we continue
to the next chunk. Known writable is derived from QStandardPaths. All
but Temp are children of the DataLocation on WinRT.

Task-number: QTBUG-35472
Change-Id: I3b4ab390bd321285da51d02f5eeaf06da4d56298
Reviewed-by: Andrew Knight <andrew.knight@digia.com>
bb10
Maurice Kalinowski 2014-03-19 15:20:06 +01:00 committed by The Qt Project
parent d2da291c93
commit d7eb3d1280
1 changed files with 14 additions and 0 deletions

View File

@ -74,6 +74,8 @@
# define SECURITY_WIN32
# include <security.h>
#else // !Q_OS_WINRT
# include "qstandardpaths.h"
# include "qthreadstorage.h"
# include <wrl.h>
# include <windows.foundation.h>
# include <windows.storage.h>
@ -1151,6 +1153,18 @@ bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool crea
bool existed = false;
if (isDirPath(chunk, &existed) && existed)
continue;
#ifdef Q_OS_WINRT
static QThreadStorage<QString> dataLocation;
if (!dataLocation.hasLocalData())
dataLocation.setLocalData(QDir::toNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::DataLocation)));
static QThreadStorage<QString> tempLocation;
if (!tempLocation.hasLocalData())
tempLocation.setLocalData(QDir::toNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::TempLocation)));
// We try to create something outside the sandbox, which is forbidden
// However we could still try to pass into the sandbox
if (dataLocation.localData().startsWith(chunk) || tempLocation.localData().startsWith(chunk))
continue;
#endif
}
return false;
}