Safeguard against file corruption

This is what could be a temporary (or permanent) fix to users trying to
delete important files on their computer through JS
This commit is contained in:
elisa-lj11 2016-08-17 11:10:38 -07:00
parent 5d2fb68924
commit 5d19267d00
2 changed files with 20 additions and 0 deletions

View file

@ -39,6 +39,11 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url) {
QString tempDir = path;
tempDir.remove(fileName);
qDebug() << "Temporary directory at: " + tempDir;
if (!isTempDir(tempDir)) {
qDebug() << "Temporary directory mismatch; risk of losing files";
return;
}
QString file = unzipFile(path, tempDir);
if (file != "") {
qDebug() << "file to upload: " + file;
@ -52,6 +57,20 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url) {
QDir(tempDir).removeRecursively();
}
// fix to check that we are only referring to a temporary directory
bool FileScriptingInterface::isTempDir(QString tempDir) {
QString folderName = "/" + tempDir.section("/", -1);
QString tempContainer = tempDir;
tempContainer.remove(folderName);
QTemporaryDir test;
QString testDir = test.path();
folderName = "/" + testDir.section("/", -1);
QString testContainer = testDir;
testContainer.remove(folderName);
if (testContainer == tempContainer) return true;
return false;
}
bool FileScriptingInterface::isZippedFbx(QUrl url) {
if (url.toString().contains(".zip") && url.toString().contains("fbx")) return true;
qDebug() << "This model is not a .fbx packaged in a .zip. Please try with another model.";

View file

@ -33,6 +33,7 @@ signals:
void unzipSuccess(QString url);
private:
bool isTempDir(QString tempDir);
QString unzipFile(QString path, QString tempDir);
void recursiveFileScan(QFileInfo file, QString* dirName);
void downloadZip(QString path, const QString link);