Skip to content

Commit 0fe6dad

Browse files
authored
Fix handling of multi segment directory creation (#11257)
- mkdir now returns true when the directory exists - Util.createDirectories checks if the directory exists and returns true if so - libraries/install-index.mos checks if directory exists before creating it
1 parent 3dd2800 commit 0fe6dad

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

OMCompiler/Compiler/Util/Util.mo

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,8 @@ algorithm
13951395

13961396
case _
13971397
equation
1398+
// this is because System.dirname(".openmodelica") != ".openmodelica"
1399+
// System.dirname(".openmodelica") = "." on Windows!
13981400
true = stringEqual(parentDir, System.dirname(parentDir));
13991401
b = System.createDirectory(inString);
14001402
then b;
@@ -1421,9 +1423,14 @@ protected
14211423
String parentDir;
14221424
Boolean parentDirExists;
14231425
algorithm
1424-
parentDir := System.dirname(inString);
1425-
parentDirExists := System.directoryExists(parentDir);
1426-
outBool := createDirectoryTreeH(inString,parentDir,parentDirExists);
1426+
// if is already there, just retrun true!
1427+
if System.directoryExists(inString) then
1428+
outBool := true;
1429+
else
1430+
parentDir := System.dirname(inString);
1431+
parentDirExists := System.directoryExists(parentDir);
1432+
outBool := createDirectoryTreeH(inString,parentDir,parentDirExists);
1433+
end if;
14271434
end createDirectoryTree;
14281435

14291436
public function nextPowerOf2

OMCompiler/Compiler/runtime/systemimpl.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,10 @@ extern int SystemImpl__createDirectory(const char *str)
945945
#endif
946946
if (rv == -1)
947947
{
948-
return 0;
948+
if (errno == EEXIST) // directory exists, return success!
949+
return 1;
950+
else
951+
return 0;
949952
}
950953
else
951954
{

libraries/install-index.mos

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ setModelicaPath(OpenModelica.Scripting.cd() + "/.openmodelica/libraries/");
77
getModelicaPath();
88
echo(false);
99
OpenModelica.Scripting.mkdir(".openmodelica");
10-
if not OpenModelica.Scripting.mkdir(".openmodelica/libraries/") then
11-
print("\nmkdir failed\n");
12-
print(getErrorString());
13-
exit(1);
10+
if not OpenModelica.Scripting.directoryExists(".openmodelica/libraries/") then
11+
if not OpenModelica.Scripting.mkdir(".openmodelica/libraries/") then
12+
print("\nmkdir failed\n");
13+
print(getErrorString());
14+
exit(1);
15+
end if;
1416
end if;
1517
vers:=OpenModelica.Scripting.getAvailablePackageVersions(Modelica, "3.2.3");
1618
if size(vers,1) <> 1 then

0 commit comments

Comments
 (0)