Skip to content

Commit

Permalink
Create a unique folder to extract the contents of .mol
Browse files Browse the repository at this point in the history
Fixes ticket:5786 do not mix the contents of .mol while extracting different versions.

Added a boolean parameter to loadEncryptedPackage to skip unziping of .mol
  • Loading branch information
adeas31 committed May 4, 2020
1 parent c83c1ae commit 1a3d110
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -1169,6 +1169,7 @@ end parseEncryptedPackage;
function loadEncryptedPackage
input String fileName;
input String workdir = "<default>" "The output directory for imported encrypted files. <default> will put the files to current working directory.";
input Boolean skipUnzip = false "Skips the unzip of .mol if true. In that case we expect the files are already extracted e.g., because of parseEncryptedPackage() call.";
output Boolean success;
external "builtin";
annotation(Documentation(info="<html>
Expand Down
9 changes: 5 additions & 4 deletions OMCompiler/Compiler/Script/CevalScript.mo
Expand Up @@ -1468,7 +1468,7 @@ algorithm
case (cache,_,"parseEncryptedPackage",Values.STRING(filename)::Values.STRING(workdir)::_,_)
equation
vals = {};
(b, filename_1) = unZipEncryptedPackageAndCheckFile(workdir, filename);
(b, filename_1) = unZipEncryptedPackageAndCheckFile(workdir, filename, false);
if (b) then
// clear the errors before!
Error.clearMessages() "Clear messages";
Expand All @@ -1479,9 +1479,9 @@ algorithm
end if;
then (cache,ValuesUtil.makeArray(vals));

case (_,_,"loadEncryptedPackage",Values.STRING(filename)::Values.STRING(workdir)::_,_)
case (_,_,"loadEncryptedPackage",Values.STRING(filename)::Values.STRING(workdir)::Values.BOOL(bval)::_,_)
equation
(b, filename_1) = unZipEncryptedPackageAndCheckFile(workdir, filename);
(b, filename_1) = unZipEncryptedPackageAndCheckFile(workdir, filename, bval);
if (b) then
execStatReset();
filename_1 = Testsuite.friendlyPath(filename_1);
Expand Down Expand Up @@ -3193,6 +3193,7 @@ end findModelicaPath2;
protected function unZipEncryptedPackageAndCheckFile
input String inWorkdir;
input String filename;
input Boolean skipUnzip;
output Boolean success;
output String outFilename;
protected
Expand All @@ -3203,7 +3204,7 @@ algorithm
if (System.regularFileExists(filename)) then
if (Util.endsWith(filename, ".mol")) then
workdir := if System.directoryExists(inWorkdir) then inWorkdir else System.pwd();
if (0 == System.systemCall("unzip -q -o -d \"" + workdir + "\" \"" + filename + "\"")) then
if (skipUnzip or 0 == System.systemCall("unzip -q -o -d \"" + workdir + "\" \"" + filename + "\"")) then
s1 := System.basename(filename);
s2 := Util.removeLast4Char(s1);
s3 := listGet(Util.stringSplitAtChar(s2," "),1);
Expand Down
7 changes: 7 additions & 0 deletions OMEdit/OMEditLIB/MainWindow.cpp
Expand Up @@ -630,6 +630,13 @@ void MainWindow::beforeClosingMainWindow()
}
mFMUDirectoriesList.clear();
}
// Delete the MOL directories
foreach (QString molDirectory, mMOLDirectoriesList) {
if (QDir().exists(molDirectory)) {
Utilities::removeDirectoryRecursivly(molDirectory);
}
}
mMOLDirectoriesList.clear();
delete pSettings;
// delete the OptionsDialog object
OptionsDialog::destroy();
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/MainWindow.h
Expand Up @@ -253,6 +253,7 @@ class MainWindow : public QMainWindow
const char* variables);

QList<QString> mFMUDirectoriesList;
QList<QString> mMOLDirectoriesList;
private:
bool mDebug;
bool mTestsuiteRunning;
Expand Down
15 changes: 13 additions & 2 deletions OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -4246,7 +4246,17 @@ void LibraryWidget::openEncrytpedModelicaLibrary(QString fileName, QString encod
MainWindow::instance()->getStatusBar()->showMessage(QString(Helper::loading).append(": ").append(fileName));
}

QStringList classesList = MainWindow::instance()->getOMCProxy()->parseEncryptedPackage(fileName, Utilities::tempDirectory());
// create unique directory to extract .mol contents
QFileInfo fileInfo(fileName);
QString tempDirectoryPath = Utilities::tempDirectory();
QString outputDirectory = QString("%1/%2%3").arg(Utilities::tempDirectory(), fileInfo.baseName(), QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
if (!QDir().exists(outputDirectory)) {
QDir().mkpath(outputDirectory);
MainWindow::instance()->mMOLDirectoriesList.append(outputDirectory);
tempDirectoryPath = outputDirectory;
}

QStringList classesList = MainWindow::instance()->getOMCProxy()->parseEncryptedPackage(fileName, tempDirectoryPath);
if (!classesList.isEmpty()) {
if (multipleTopLevelClasses(classesList, fileName)) {
if (showProgress) {
Expand Down Expand Up @@ -4277,7 +4287,8 @@ void LibraryWidget::openEncrytpedModelicaLibrary(QString fileName, QString encod
pMessageBox->exec();
} else { // if no conflicting model found then just load the file simply
// load the encrypted package in OMC
if (MainWindow::instance()->getOMCProxy()->loadEncryptedPackage(fileName, Utilities::tempDirectory())) {
// we pass true for skipUnzip as we have alredy extracted mol with parseEncryptedPackage earlier.
if (MainWindow::instance()->getOMCProxy()->loadEncryptedPackage(fileName, tempDirectoryPath, true)) {
// create library tree nodes for loaded models
int progressvalue = 0;
if (showProgress) {
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditLIB/OMC/OMCProxy.cpp
Expand Up @@ -3175,9 +3175,9 @@ QList<QString> OMCProxy::parseEncryptedPackage(QString fileName, QString working
* \param workingDirectory
* \return
*/
bool OMCProxy::loadEncryptedPackage(QString fileName, QString workingDirectory)
bool OMCProxy::loadEncryptedPackage(QString fileName, QString workingDirectory, bool skipUnzip)
{
bool result = mpOMCInterface->loadEncryptedPackage(fileName, workingDirectory);
bool result = mpOMCInterface->loadEncryptedPackage(fileName, workingDirectory, skipUnzip);
printMessagesStringInternal();
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/OMC/OMCProxy.h
Expand Up @@ -265,7 +265,7 @@ class OMCProxy : public QObject
QList<QList<QString > > getUses(QString className);
bool buildEncryptedPackage(QString className, bool encrypt = true);
QList<QString> parseEncryptedPackage(QString fileName, QString workingDirectory);
bool loadEncryptedPackage(QString fileName, QString workingDirectory);
bool loadEncryptedPackage(QString fileName, QString workingDirectory, bool skipUnzip);
signals:
void commandFinished();
public slots:
Expand Down

0 comments on commit 1a3d110

Please sign in to comment.