Skip to content

Commit

Permalink
Prevent race condition in executable "generation"
Browse files Browse the repository at this point in the history
  • Loading branch information
a-schild committed Sep 3, 2021
1 parent a5b98d6 commit 5cec8b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Added constructor for color filter which allows string expressions
- Added support for multiple video filters in one conversion pass
- Added enhanced meta data detection in MultiMedia object
- Implement critical section in executable location+creation to prevent race condition (Issue #163)
- **3.1.0**
- Added support for arm32 bit (Thanks to jmformenti)
- Added option to use a specific quote character for command line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,25 @@ public DefaultFFMPEGLocator() {
File ffmpegFile = new File(dirFolder, "ffmpeg-" + arch + "-" + Version.getVersion() + suffix);
LOG.debug("Executable path: {}", ffmpegFile.getAbsolutePath());

// Check the version of existing .exe file
if (ffmpegFile.exists()) {
// OK, already present
LOG.debug("Executable exists in <{}>", ffmpegFile.getAbsolutePath());
} else {
LOG.debug("Need to copy executable to <{}>", ffmpegFile.getAbsolutePath());
copyFile("ffmpeg-" + arch + suffix, ffmpegFile);
}
synchronized(this)

This comment has been minimized.

Copy link
@naffan2014

naffan2014 Sep 3, 2021

only way to solve race conditon by synchronized?

{
// Check the version of existing .exe file
if (ffmpegFile.exists()) {
// OK, already present
LOG.debug("Executable exists in <{}>", ffmpegFile.getAbsolutePath());
} else {
LOG.debug("Need to copy executable to <{}>", ffmpegFile.getAbsolutePath());
copyFile("ffmpeg-" + arch + suffix, ffmpegFile);
}

// Need a chmod?
if (!isWindows) {
try {
Runtime.getRuntime().exec(new String[] {"/bin/chmod", "755", ffmpegFile.getAbsolutePath()});
} catch (IOException e) {
LOG.error("Error setting executable via chmod", e);
}
// Need a chmod?
if (!isWindows) {
try {
Runtime.getRuntime().exec(new String[] {"/bin/chmod", "755", ffmpegFile.getAbsolutePath()});
} catch (IOException e) {
LOG.error("Error setting executable via chmod", e);
}
}
}

// Everything seems okay
Expand Down

0 comments on commit 5cec8b1

Please sign in to comment.