Skip to content

Commit

Permalink
Fix salesagility#10505 Rebuild and repair can lead to malformed group…
Browse files Browse the repository at this point in the history
…ed JS files

Make other processes (web users) wait to read the grouped JS files until AFTER they're completely concatenated and written out to disk.
  • Loading branch information
chris001 authored Aug 22, 2024
1 parent 1a114a9 commit 3e676c8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions jssource/minify_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ function ConcatenateFiles($from_path)

//make sure we have handles to both source and target file
if ($trgt_handle) {
// Acquire exclusive lock on the target file.
flock($trgt_handle, LOCK_EX);

if ($already_minified || isset($excludedFiles[dirname((string) $loc)])) {
$buffer = file_get_contents($loc);
} else {
Expand All @@ -179,6 +182,8 @@ function ConcatenateFiles($from_path)
//log error, file did not get appended
echo "Error while concatenating file $loc to target file $trgt \n";
}
// Release the lock on the target file.
flock($trgt_handle, LOCK_UN);
//close file opened.
fclose($trgt_handle);
}
Expand Down

0 comments on commit 3e676c8

Please sign in to comment.