File Engine - Add valid file name checking to key generation (Specifically the $appendix)
greg.harvey - December 16, 2008 - 14:54
| Project: | Cache Router |
| Version: | 6.x-1.0-beta8 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Every time I hit a page with cacherouter running filecache installed in Windows (XAMPP Lite, PHP 5) I get nastiness. Here's a sample:
Cache write error, failed to open file "/filecache/cache_menu/1/1513383a9707139407a946e759ea9b65--links:primary-links:tree-data:c39c11153626a0b00b817797c0db368e"I get it about a dozen times per page load. Tried setting permissions on c:\tmp\filecache to Everyone => Full Control to no avail. Seems there's something PHP for Windows doesn't like. =(

#1
I've tried using this module on Windows too.
Paid attention to the error messages - seems the Drupal cache keys (filenames if using the 'file' engine) include colons and stars (':' and '*') which are illegal pathname characters on Windows..
Solution would be to patch ALL cache-related Drupal code to use some valid Windows characters instead..
I'll stick to the better solution - use Drupal in a proper LAMP stack set-up :-)
I hope this helps..
#2
Hello,
I've tried using this module on Windows too.
Posible solution:
All in file.php:
1.- Add new method:
function appendix($key){
return str_replace(array(':'), array('-'), $key); // Can be '-' or other, but should be valid for NTFS ;)
}
2.- Change this line in function key at line ~157 after TODO ;)
// TODO make sure we always get valid filenames in the appendix
$appendix = $this->appendix(str_replace(array('/'), array('-'), $key));
3.- Change this line in function delete:
$look_for = explode('*', $this->appendix($key));
4.- a NEW BUG fixed:
Change this line in function delete: Failed if $key = "*"
if (!(strrpos($key, '*')===FALSE)) {
Enjoy!
#3
We've run into a similar issue in the LAMP stack when the URL of the page is fairly long.
When the appendix is generated, it will be longer than the supported Linux ext3 file name length of 255 bytes.
The attached patch trims the appendix to be less than 255 and also handles the NTFS and FAT filesystem limits of 255 characters.
In addition, it handles removing all invalid file name characters for NTFS and FAT.
#4
#5
The previously posted patch is currently broken as either CacheRouter or Drupal's caching mechanisms require the : to be in place for key lookups.
I'll have to find another way to handle this issue. For now, the patch will continue to work on *nix systems if the ":" is removed from the str_replace() call
#6
Updated the patch to work on Windows systems. Patch also now correctly updates the delete() function to correctly clear cache as needed.
#7
Cache clear now seems to work. Thanks. =)
Still getting #495736: Unwanted undefined index notice, which is preventing production usage right now on anything that matters. =/
#8
I tackled filenames a fair bit over at #578522: File engine: Performance of cache flushes, and related cleanup, but otherwise it seems like rc1 did have this fixed already.
#9
It looks like slantview committed this patch, so the patch will most likely no longer work with rc1.
I think my patch might have left out the fix for the 'delete' key lookup. I'll test and report back.
#10
Looks like delete() now calls key(), so his commit into trunk (and in rc1) will work great.
Suggest this issues be closed.
#11
It obviously got in with the big pack of fixes, although it's modified a little too.
So unless there are further concerns, this may be probably marked as "fixed".
#12
Automatically closed -- issue fixed for 2 weeks with no activity.