function javascript_libraries_file_unmanaged_save_data in JavaScript Libraries Manager 7
More atomic replacement for file_unmanaged_save_data().
Aims to minimize the time in which a destination file is partially complete.
file_unmanaged_save_data performs a file_copy from wherever the temporary directory is to wherever the destination directory is. These can be on different filesystems and if one of the 2 is slow, results in the end destination file being in an inconsistent state for some time (an uncomfortably large number of millisec). When core aggregation attempts to access the file during this time, it can pull and cache a corrupt file. We need to move the file into a temporary location on the same filesystem and move instead of copying the file to reduce the duration of this inconsistency.
Note: this function can currently only be used where $replace is FILE_EXISTS_REPLACE.
1 call to javascript_libraries_file_unmanaged_save_data()
- javascript_libraries_cache in ./
javascript_libraries.module - Download/Synchronize/Cache tracking code file locally.
File
- ./
javascript_libraries.module, line 354 - Toggle the inclusion of Drupal system libraries. Upload and reference custom libraries as well.
Code
function javascript_libraries_file_unmanaged_save_data($data, $destination) {
// Create a temporary file and then move it in place.
$destination_tmp = $destination . '-tmp-' . uniqid(getmypid(), TRUE);
if (file_unmanaged_save_data($data, $destination_tmp, FILE_EXISTS_REPLACE)) {
return @rename($destination_tmp, $destination);
}
return FALSE;
}