If a theme in /sites/sitename.com/themes/ is named the same as another theme in /themes/ you may have template_c mashed

dgtlmoon - August 16, 2006 - 01:21
Project:Smarty theme engine
Version:4.7.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:sun
Status:closed
Description

If you have say /sites/sitename.com/themes/default and /themes/default , sometimes ive noticed smarty's compiled templates getting "mashed" across both sites, which is a real pain in multi-homed commercial environments.

Attached is a patch that suffix's the MD5 sum of the current sites config_path to the templates_c/ subdirectory, which ensures smarty cache paths dont get mashed across theme names/site installations

I think the ultimate way would be to move the templates_c to under the /sites/sitename.com/templates_c directory so each site carries its own compiled smarty cache

Attached patch is for smartytemplate.php from CVS @ 1.6 2005/12/31 09:24:02 diffed against my patches to smartytemplate.php @ ,v 1.1.1.1 2006-05-04 01:36:11

AttachmentSize
smarty-cache-isolation.patch.txt794 bytes

#1

tclineks - August 16, 2006 - 01:28
Version:HEAD» 4.7.x-1.x-dev
Assigned to:Anonymous» tclineks

Thanks dgtlmoon, that was an oversight on my part, I'll get it committed.

#2

dgtlmoon - August 17, 2006 - 05:14

Just a thought - this could also be a security issue

#3

sun - August 21, 2006 - 22:42

-1 for /sites/<sitename>/themes/templates_c
(each templates_c directory must have proper permissions - this wouldn't really be maintainable)

+1 for using .../templates_c/<themename>_<MD5>
(although a bit long)

+2 for using .../templates_c/sites/default/<themename> and .../templates_c/themes/<themename>
(/themes/smarty/templates_c/ and anything below is writable anyway)

#4

tclineks - August 21, 2006 - 23:16

I should have looked a bit closer at the original solution.

+2 for using .../templates_c/sites/default/<themename> and .../templates_c/themes/<themename>
(/themes/smarty/templates_c/ and anything below is writable anyway)

I don't understand your second suggestion there.

I'm inclined to do smarty/templates_c/site_name/theme_name

I dont think there are very serious security considerations so I'll wait for feedback on this before committing (and repackaging).

#5

dgtlmoon - August 21, 2006 - 23:39

my two cents: compiled templates _shouldnt_ be important to the sysop or the browser, so long as they dont overlap and are tucked away somewhere, its one of those things where if its working you really dont have much reason to be looking at it

+1 for leaving it in themes/engines/smarty/templates_c/[someUUID]/

#6

sun - August 23, 2006 - 18:22
Status:active» needs work

I'm inclined to do smarty/templates_c/site_name/theme_name

seems to solve this issue, too. My proposal was to add the full path to the theme after /themes/engines/smarty/templates_c, but I think the proposal of site_name/theme_name is enough to prevent garbled output. We should go for that.

#7

dgtlmoon - August 28, 2006 - 05:11

Sitename?


  • Do you mean domain name? What if it the site runs on a subdirectory?

  • Any other wierd char's that might not like to be a path

#9

sun - August 28, 2006 - 14:37

Yes, the name of each site is unique and based on the folder name located in /sites. With that prefix each templates_c directory will also be unique.
F.e.

  • /sites/exampledomain.com with a theme in /themes/example will be compiled in /themes/engines/smarty/templates_c/exampledomain.com/example, whereas
  • /sites/exampledomain.org with a theme in /sites/exampledomain.org/themes/example will be compiled in /themes/engines/smarty/templates_c/exampledomain.org/example and even
  • /sites/exampledomain.com with a theme in /sites/exampledomain.com/themes/other will be compiled in /themes/engines/smarty/templates_c/exampledomain.com/other.

The only thing which would not be supported is

  • /sites/exampledomain.com with a theme in /themes/example while having also
  • /sites/exampledomain.com with a theme in /sites/exampledomain.com/themes/example
  • which both would be compiled in /themes/engines/smarty/templates_c/exampledomain.com/example

I don't know if we should care about the latter case, too. IMHO, a notice in README.TXT or INSTALL.TXT should be enough.

#10

tclineks - August 28, 2006 - 16:24

Thanks for the input sun

As for the latter situtation, I considered this. It's not a problem since a single site can only be using one of the locations at a time.

#11

sun - August 29, 2006 - 22:10
Status:needs work» reviewed & tested by the community

Attached patch creates a Smarty compile dir in /themes/engines/smarty/templates_c/$confdir_$themedir for each site running on one Drupal installation.

I've decided to not use subdirectories because mkdir() does not support creation of subdirectories in PHP < 5 - and IMHO there shouldn't be much more needless subdirectories at this point.

AttachmentSize
smartytemplate.compiledir.patch 590 bytes

#12

sun - September 21, 2006 - 01:37

Patch stills works like a breeze.

#13

sun - January 23, 2007 - 23:08

Travis, is it possible to commit this one-liner?

#14

recidive - February 2, 2007 - 05:56

+1. I've tested this patch and it worked well in a multisite environment.

#15

sun - September 4, 2007 - 04:57
Assigned to:tclineks» sun
Status:reviewed & tested by the community» fixed

Committed to HEAD and DRUPAL-4-7.

#16

Anonymous - September 18, 2007 - 05:01
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.