summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--imagecache.module24
1 files changed, 12 insertions, 12 deletions
diff --git a/imagecache.module b/imagecache.module
index ba59e6c..11b37fe 100644
--- a/imagecache.module
+++ b/imagecache.module
@@ -128,8 +128,9 @@ function imagecache_cache() {
$destination = file_create_path() . '/imagecache/'. $preset .'/'. $path;
- // Generate a unique file name in the drupal temp directory
- $tmpdestination = tempnam(file_directory_temp(), basename($path));
+ // prepend presetname to tmp file name to prevent namespace clashes when
+ // multiple presets for the same image are called in rapid succession.
+ $tmpdestination = file_directory_temp() . '/' . $preset . str_replace(dirname($path) . '/', '', $path);
$dir = dirname($destination);
//drupal_set_message('$tmpdestination: '. $tmpdestination);
@@ -156,10 +157,10 @@ function imagecache_cache() {
return;
}
- // Check if the finished file has been written to disk since the webserver looked for it
- if (!is_file($destination)) {
+ //check if file exists to prevent multiple apache children from trying to generate.
+ if (!is_file($tmpdestination)) {
$generated = TRUE;
- file_copy($source, $tmpdestination, FILE_EXISTS_REPLACE);
+ file_copy($source, $tmpdestination);
foreach($actions as $action) {
$size = getimagesize($tmpdestination);
@@ -198,8 +199,7 @@ function imagecache_cache() {
}
}
file_move($tmpdestination, $destination);
- }
- else {
+ } else {
$generated = TRUE;
}
@@ -207,11 +207,11 @@ function imagecache_cache() {
if (function_exists('mime_content_type')) {
$mime = mime_content_type($destination);
}
- else {
- $size = getimagesize($destination);
- $mime = $size['mime'];
- }
- file_transfer($destination, array('Content-Type: ' . mime_header_encode($mime), 'Content-Length: ' . filesize($destination)));
+ else {
+ $size = getimagesize($destination);
+ $mime = $size['mime'];
+ }
+ file_transfer($destination, array('Content-Type: ' . mime_header_encode($mime), 'Content-Length: ' . filesize($destination)));
}
else {
// Generate an error if image could not generate.