|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
c960657 Smarty Regular
Joined: 07 May 2003 Posts: 75 Location: Copenhagen, Denmark
|
Posted: Mon Jun 28, 2004 2:10 pm Post subject: $smarty->compile_dir is not created, if it does not exist |
|
|
Currently, if $smarty->compile_dir does not exist when $smarty->display() is called, it will not be created.
We have a webserver farm that hosts a lot of sites using Smarty. Each site has its own compile dir in /tmp/smarty/sitename. When we put a new site online, we sometimes forget to create the compile_dir. I know that we could check for this in our own code and create the dir. However, it would be convenient if Smarty could do this automatically.
This behaviour can be supported, if Smarty::_get_auto_filename() is changed so that it returns an absolute path in the case the compile_dir does not exists and the compiled file does not exist in the include path either (currently it returns a relative path).
Code: |
@@ -1728,14 +1728,14 @@
{
$_compile_dir_sep = $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';
- if(@is_dir($auto_base)) {
- $_return = $auto_base . DIRECTORY_SEPARATOR;
- } else {
+ $_return = $auto_base . DIRECTORY_SEPARATOR;
+ if(!@is_dir($auto_base)) {
// auto_base not found, try include_path
$_params = array('file_path' => $auto_base);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');
- smarty_core_get_include_path($_params, $this);
- $_return = isset($_params['new_file_path']) ? $_params['new_file_path'] . DIRECTORY_SEPARATOR : null;
+ if (smarty_core_get_include_path($_params, $this)) {
+ $_return = $_params['new_file_path'] . DIRECTORY_SEPARATOR;
+ }
}
|
Also the if(!@is_writable($smarty->compile_dir)) { block should be removed from smarty_core_write_compiled_resource.
The same might be relevant for cache_dir.[/code] |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jun 28, 2004 2:42 pm Post subject: |
|
|
It is not Smarty's responsibility to create the top-level directories. Ideally, Smarty would not have permission to create them anyways. It is up to you to create directories that are safe for Smarty to work within. |
|
Back to top |
|
c960657 Smarty Regular
Joined: 07 May 2003 Posts: 75 Location: Copenhagen, Denmark
|
Posted: Mon Jun 28, 2004 6:19 pm Post subject: |
|
|
Well, ok.
The fix for Smarty::_get_auto_filename() might still be worth applying, though. Not that it seems terribly important, but I think the semantics after the fix makes more sence, i.e. if a non-existing path is returned, it is always a path in the compile dir.
Currently, if you for some weird reason set $compile_dir to a file instead of a directory, and this file is writable by the webserver, then new compiled templates are written to subdirs of the document root, if this is writable, instead of to subdirs of compile_dir. This will be fixed by the change to _get_auto_filename(), so that smarty_core_create_dir_structure() triggers an error when trying to create a subdir of the file.
This is probably not a very common error, but maybe other less obscure errors exist due to the current behaviour of _get_auto_filename(). |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Jun 28, 2004 10:28 pm Post subject: |
|
|
Its better to do this from your custom Smarty class. I have a function that not only checks/creates the temp directories but also keeps track of the running Smarty version compared to the version used in the compiled/cached dirs and automatically clears them out when it detects an upgrade. |
|
Back to top |
|
c960657 Smarty Regular
Joined: 07 May 2003 Posts: 75 Location: Copenhagen, Denmark
|
Posted: Tue Jun 29, 2004 5:29 pm Post subject: |
|
|
Unrelated to the original issue raised in this bug, I spent some more time looking at Smarty::_get_auto_filename(), and I am confused.
I don't understand why it uses the include path. The function is used to "get a concrete filename for automagically created content", i.e. compiled templates and cache files. Why would these files be present in the include path?
The behaviour was added in CVS version 1.285 of Smarty.class.php when the method _get_include_path() was introduced. With this new method, Smarty would look for config files, files included with {include_php} etc. in the include path, and that seems reasonable.
However, a call to the method was also added to _get_auto_filename() - but I think that was a mistake. At least I don't see why it makes sense to look for automatically created files in the include path.
Have I missed something?
http://cvs.php.net/co.php/smarty/libs/Smarty.class.php?r=1.285
http://cvs.php.net/diff.php/smarty/libs/Smarty.class.php?r1=1.284&r2=1.285&ty=h |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Jun 29, 2004 5:57 pm Post subject: |
|
|
_get_include_path() is not really used to get automatic filenames, but to get the auto_base if it wasn't supplied as absolute path.
like $smarty->compile_dir = 'templates_c'
if _get_auto_filename() cannot find 'templates_c' in the cwd it searches php's include_path for it. |
|
Back to top |
|
c960657 Smarty Regular
Joined: 07 May 2003 Posts: 75 Location: Copenhagen, Denmark
|
Posted: Tue Jun 29, 2004 6:34 pm Post subject: |
|
|
messju wrote: | like $smarty->compile_dir = 'templates_c'
if _get_auto_filename() cannot find 'templates_c' in the cwd it searches php's include_path for it. |
That's an undocumented feature, right? And is this really a sensible thing to do? The include path usually contains stuff like the PEAR libraries and probably other code shared by multiple sites. It doesn't seem right to me to look for compiled templates there.
If believe Smarty only writes compiled templates to either a directory specified by an absolute path or to a directory specified relative to the directory containing the current PHP script. So why look for compiled templates outside these two places? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Jul 01, 2004 8:56 am Post subject: |
|
|
c960657 wrote: | messju wrote: | like $smarty->compile_dir = 'templates_c'
if _get_auto_filename() cannot find 'templates_c' in the cwd it searches php's include_path for it. |
That's an undocumented feature, right? |
which doesn't mean not used. we are likely to break many people's setups if we just rip it off after more than 2 years working good for everyone except for you.
Quote: | And is this really a sensible thing to do? The include path usually contains stuff like the PEAR libraries and probably other code shared by multiple sites. It doesn't seem right to me to look for compiled templates there. |
not everybody uses smarty the way you do. having control over template_dir and compile_dir via include_path and without the need to touch php-code can be a useful thing.
Quote: | If believe Smarty only writes compiled templates to either a directory specified by an absolute path or to a directory specified relative to the directory containing the current PHP script. |
it does in the first place, but if it can't it takes further measures to get it's job done. |
|
Back to top |
|
c960657 Smarty Regular
Joined: 07 May 2003 Posts: 75 Location: Copenhagen, Denmark
|
Posted: Thu Jul 01, 2004 12:07 pm Post subject: |
|
|
messju wrote: | c960657 wrote: | If believe Smarty only writes compiled templates to either a directory specified by an absolute path or to a directory specified relative to the directory containing the current PHP script. |
it does in the first place, but if it can't it takes further measures to get it's job done. |
I am not sure I understand you correctly, but are you saying that Smarty will try to write to other directories that the two, I mentioned above? I don't see how this can happen. In smarty_core_write_compiled_resource() and smarty_core_write_cache_file() the write is aborted, if $smarty->compile_dir/cache_dir (specified by either an absolute path or a path relative to the directory of the current script, but not relative to the include path) is not writable.
So if I am right about that, templates will never be written outside the specified compile_dir, and that's why I am wondering why it makes sense to looks for them outside the compile_dir?
messju wrote: |
Quote: | That's an undocumented feature, right? |
which doesn't mean not used. we are likely to break many people's setups if we just rip it off after more than 2 years working good for everyone except for you. |
I am aware of the problems with respect to backwards compatibility. Currently, I am not suggesting any change to Smarty. I am just trying to understand the code. It is my impression that there is a bug (or at least a very subtle, undocumented feature), but I am not sure I fully understand the code, so bear with me |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Jul 01, 2004 12:16 pm Post subject: |
|
|
c960657 wrote: | I am not sure I understand you correctly, but are you saying that Smarty will try to write to other directories that the two, I mentioned above? I don't see how this can happen. In smarty_core_write_compiled_resource() and smarty_core_write_cache_file() the write is aborted, if $smarty->compile_dir/cache_dir (specified by either an absolute path or a path relative to the directory of the current script, but not relative to the include path) is not writable. |
ah, you are correct, i missed these.
i think the _get_include_path() call inside _get_auto_filename() is useless legacy then. call it a bug if you want to be that harsh. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Jul 01, 2004 3:48 pm Post subject: |
|
|
finally convinced i committed a fix to this.
thanks for catching this one, c960657! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|