Removed a bug: temporary files were not removed.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Sun, 14 Nov 2010 19:13:40 +0000 (21:13 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Sun, 14 Nov 2010 19:13:40 +0000 (21:13 +0200)
src/utils/emuhelper.cpp
src/utils/unziphelper.cpp

index 5eb5d92..6642a40 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <QDebug>
 #include <QFile>
+#include <QDir>
 #include <QMessageBox>
 #include "emuhelper.h"
 #include "unziphelper.h"
@@ -83,6 +84,7 @@ void EmuHelper::launch(const Executable * ex, QList<MediaImageContainer *> micLi
         fp.append(mic->getFilePath()->getName());
         if (!fp.endsWith('/')) fp.append("/");
         fp.append(mic->getName());
+        qDebug() << "Extracting " << fp;
         int ret = unzipHelper->extractAll(fp, tmp);
         if (ret) {
             qDebug() << "Failed unzipping " << fp << ".";
@@ -109,14 +111,29 @@ void EmuHelper::launch(const Executable * ex, QList<MediaImageContainer *> micLi
     // for the moment, we'll wait for the process to be finished until we continue
     waitForFinished(-1);
 
+    try {
+    QDir ftmp(tmp);
+    if (!ftmp.exists()) {
+        throw EmuFrontException(tr("Trying to remove temporary files. "
+            "Directory %s doesn't exist!").arg(tmp));
+    }
     // clean the temp dir
     foreach(EmuFrontObject *ob, miList) {
-        QString fp = " \"";
-        fp.append(tmp);
-        fp.append(ob->getName());
-        fp.append("\"");
-        if (!QFile::remove(fp))
+        if (!ftmp.exists(ob->getName())) {
+            qDebug() << "File " << ob->getName() << " doesn't exist in " << tmp;
+            continue;
+        }
+        QString fp = ftmp.filePath(ob->getName());
+        QFile f(fp);
+        if (!f.exists()) {
+            qDebug() << "File " << fp << " doesn't exist!";
+        }
+        if (!f.remove()) {
             qDebug() << "Removing " << fp << " failed.";
+        }
+    }
+    } catch (EmuFrontException e) {
+        qDebug() << e.what();
     }
     delete ex;
     qDeleteAll(micList);
index 787ea60..af489a1 100644 (file)
@@ -174,7 +174,7 @@ int UnzipHelper::extractAll(QString filePath, QString targetPath)
     command.append(targetPath);
     //qDebug() << "Starting unzip command: " << command;
     start(command);
-    bool procOk = waitForFinished(); // TODO: set timeout, now using default 30000ms
+    bool procOk = waitForFinished( ); // TODO: set timeout, now using default 30000ms
     if (!procOk) {
         throw EmuFrontException(tr("Failed unzipping file '%1' to '%2'.").arg(filePath).arg(targetPath));
     }