Bug #19422 [Fbk]: _read truncates cache files
| From: | fletcher dot moore at comm dot gatech dot edu | Date: | Fri, 18 May 2012 15:48:51 +0000 |
| Subject: | Bug #19422 [Fbk]: _read truncates cache files | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-8672@lists.php.net to get a copy of this message | ||
Edit report at https://pear.php.net/bugs/bug.php?id=19422&edit=1
ID: 19422
Updated by: fletcher.moore@comm.gatech.edu
Reported By: fletcher dot moore at comm dot gatech dot edu
Summary: _read truncates cache files
Status: Feedback
Type: Bug
Package: Cache_Lite
Operating System: OS X 10.7.3
Package Version: 1.7.12
PHP Version: 5.3.12
Roadmap Versions:
New Comment:
Sure thing. Here's the relevant part of the function:
function hg_reader_cacheHandler($id, $type='feed', $cacheTime=3600) {
$xml = array();
$cacheOpt = array();
$cacheOpt['cacheDir'] = variable_get('hg_cache_location',
file_default_scheme() .
'://hg/cache' . '/');
$cacheOpt['cache_time'] = $cacheTime;
$cl = new Cache_Lite($cacheOpt);
$cl->setToDebug();
if (($data = $cl->get($id . $type)) AND
(!array_key_exists('clearcache', $_GET)))
{
$xml['err'] = '';
$xml['data'] = $data;
} else {
// Pull XML for feed
if ($type == 'feed') {
$xml_url = HG_URL . '/xml/' . $id;
} else {
// Pull XML for node
$xml_url = HG_URL . '/node/' . $id . '/xml';
}
}
A couple notes: variable_get() and file_default_scheme() are Drupal API
functions.
The line those appear in set $cacheOpt['cacheDir'] to
"public://hg/cache/" which is
writeable and all that. The cache files appear there, they just don't
ever get used.
The code that registers the public stream wrapper is in Drupal's
file.inc:
http://api.drupal.org/api/drupal/includes%21stream_wrappers.inc/class/DrupalPubli
cStreamWrapper/7
I think it would also be possible to loop the fread() function within
_read so that it
pulls the whole file. Someone mentioned that in a Cache_lite bug report
long ago,
but the thread (http://pear.php.net/bugs/bug.php?id=9836) was closed
when the
guy failed to produce a patch. I could probably write one â I haven't
tried that
approach yet, but it does seem to me better for backward compatibility
purposes.
Previous Comments:
------------------------------------------------------------------------
[2012-05-18 08:30:47] tacker
-Status: Open
+Status: Feedback
Hoi crackwilding,
thank you for the report.
Please provide the relevant code sections of your app which reproduces
this error.
Thanks!
------------------------------------------------------------------------
[2012-05-17 23:08:24] crackwilding
Description:
------------
I'm trying to read and write cache files to a directory specified
by a stream wrapper generated by Drupal 7. The _read
function is truncating the files to 16,352 characters, which
renders them useless, not least of which because they fail
checksum comparisons.
This can be fixed by changing line 734 to:
$data = @stream_get_contents($fp);
This renders the $length variable sort of pointless, and of
course it causes some issues with backward compatibility, but
I wanted to know whether I'm missing something before
diving into it any deeper.
------------------------------------------------------------------------
--
Edit this bug report at https://pear.php.net/bugs/bug.php?id=19422&edit=1