Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit a7cb770

Browse files
committed
Fixed concurrency issue
1 parent 058cd76 commit a7cb770

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/main/java/com/mathworks/ci/tools/MatlabInstaller.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,24 @@ private void getFreshCopyOfExecutables(String platform, FilePath expectedPath)
173173
throw new InstallationFailedException("Unsupported OS");
174174
}
175175

176-
synchronized(this){
177-
mpmPath.copyFrom(mpmUrl.openStream());
178-
mpmPath.chmod(0777);
179-
matlabBatchPath.copyFrom(matlabBatchUrl.openStream());
180-
matlabBatchPath.chmod(0777);
176+
//Handle the concurrency issues due to same name.
177+
FilePath tempMatlabBatchPath = new FilePath(expectedPath, "temp-matlab-batch");
178+
FilePath tempMpmPath = new FilePath(expectedPath, "temp-mpm");
179+
try{
180+
tempMpmPath.copyFrom(mpmUrl.openStream());
181+
tempMpmPath.chmod(0777);
182+
tempMatlabBatchPath.copyFrom(matlabBatchUrl.openStream());
183+
tempMatlabBatchPath.chmod(0777);
184+
185+
tempMpmPath.renameTo(mpmPath);
186+
tempMatlabBatchPath.renameTo(matlabBatchPath);
187+
188+
} catch(IOException | InterruptedException e){
189+
e.printStackTrace();
190+
} finally {
191+
// Clean up temporary files if they exist
192+
tempMatlabBatchPath.delete();
193+
tempMpmPath.delete();
181194
}
182195
}
183196

0 commit comments

Comments
 (0)