Changeset 232

Show
Ignore:
Timestamp:
07/22/06 15:28:11 (2 years ago)
Author:
bart
Message:

Also rewrite clean code for cache files on win32 for directory

hashing. This hasn't been tested on windows!!!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eaccelerator/trunk/ChangeLog

    r231 r232  
    22 
    33        * Some zval macro's differ for php4 and 5, this fixes #146. 
     4        * Also rewrite clean code for cache files on win32 for directory  
     5          hashing. This hasn't been tested on windows!!! 
    46 
    572006-07-19  Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
  • eaccelerator/trunk/ea_info.c

    r227 r232  
    3333#include "zend.h" 
    3434#include "fopen_wrappers.h" 
     35#include "debug.h" 
    3536#include <fcntl.h> 
    3637 
     
    7879 
    7980/* {{{ clear_filecache(): Helper function to eaccelerator_clear which finds diskcache entries in the hashed dirs and removes them */ 
    80 static void clear_filecache(TSRMLS_D
     81static void clear_filecache(const char* dir
    8182#ifndef ZEND_WIN32 
    8283{ 
     
    8485        struct dirent *entry; 
    8586        char s[MAXPATHLEN]; 
    86         char cwd[MAXPATHLEN]; 
    8787        struct stat dirstat; 
    88  
    89         if (getcwd(cwd, MAXPATHLEN)) { 
    90                 if ((dp = opendir (".")) != NULL) { 
    91                         while ((entry = readdir (dp)) != NULL) { 
    92                                 if (strstr (entry->d_name, "eaccelerator") == entry->d_name) { 
    93                                         strncpy (s, cwd, MAXPATHLEN - 1); 
    94                                         strlcat (s, "/", MAXPATHLEN); 
    95                                         strlcat (s, entry->d_name, MAXPATHLEN); 
    96                                         unlink(s); 
     88         
     89        if ((dp = opendir(dir)) != NULL) { 
     90                while ((entry = readdir(dp)) != NULL) { 
     91                        strncpy(s, dir, MAXPATHLEN - 1); 
     92                        strlcat(s, "/", MAXPATHLEN); 
     93                        strlcat(s, entry->d_name, MAXPATHLEN); 
     94                        if (strstr(entry->d_name, "eaccelerator") == entry->d_name) { 
     95                                unlink(s); 
     96                        } 
     97                        if (stat(s, &dirstat) != -1) { 
     98                                if (strcmp(entry->d_name, ".") == 0) 
     99                                        continue; 
     100                                if (strcmp(entry->d_name, "..") == 0) 
     101                                        continue; 
     102                                if (S_ISDIR(dirstat.st_mode)) { 
     103                                        clear_filecache(s); 
    97104                                } 
    98                                 if (stat(entry->d_name, &dirstat) != -1) { 
    99                                         if (strcmp(entry->d_name, ".") ==0) 
    100                                                 continue; 
    101                                         if (strcmp(entry->d_name, "..") ==0) 
    102                                                 continue; 
    103  
    104                                         if (S_ISDIR(dirstat.st_mode)) { 
    105                                                 chdir(entry->d_name); 
    106                                                 clear_filecache(TSRMLS_C); 
    107                                                 chdir(".."); 
    108                                         } 
    109                                 } 
    110                         } 
    111                         closedir (dp); 
    112                 } 
     105                        } 
     106                } 
     107                closedir (dp); 
     108        } else { 
     109                ea_debug_error("eAccelerator: Could not open cachedir %s\n", dir); 
    113110        } 
    114111} 
    115112#else 
    116 /* WIN32 TODO: rewrite this for hashed cache dirs */ 
    117 
    118         HANDLE hList; 
    119         TCHAR szDir[MAXPATHLEN]; 
    120         WIN32_FIND_DATA FileData; 
    121         char s[MAXPATHLEN]; 
    122  
    123         snprintf (szDir, MAXPATHLEN, "%s\\eaccelerator*", EAG (cache_dir)); 
    124  
    125         if ((hList = FindFirstFile (szDir, &FileData)) != INVALID_HANDLE_VALUE) { 
     113
     114        HANDLE  hFind; 
     115    WIN32_FIND_DATA wfd; 
     116    char path[MAXPATHLEN]; 
     117    size_t dirlen = strlen(dir); 
     118   
     119    memcpy(path, dir, dirlen); 
     120    strcpy(path + dirlen++, "\\*"); 
     121 
     122    hFind = FindFirstFile(path, &wfd); 
     123        if (hFind == INVALID_HANDLE_VALUE) { 
    126124                do { 
    127                         strncpy (s, EAG (cache_dir), MAXPATHLEN - 1); 
    128                         strlcat (s, "\\", MAXPATHLEN); 
    129                         strlcat (s, FileData.cFileName, MAXPATHLEN); 
    130                         unlink (s); 
    131                 } 
    132                 while (FindNextFile (hList, &FileData)); 
    133         } 
    134  
    135        FindClose (hList); 
     125                        strcpy(path + dirlen, wfd.cFileName); 
     126                        if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes) { 
     127                               clear_filecache(path); 
     128                        } else if (!DeleteFile(path)) { 
     129                               zend_error(E_CORE_WARNING, "Can't delete file %s: error %d", path, GetLastError()); 
     130                       } 
     131               } while (FindNextFile(hFind, &wfd)); 
     132        } 
     133    FindClose (hFind); 
    136134} 
    137135#endif 
     
    317315        EACCELERATOR_UNLOCK_RW (); 
    318316        EACCELERATOR_PROTECT (); 
    319          
    320         chdir(EAG (cache_dir)); 
    321         clear_filecache(TSRMLS_C); 
     317 
     318        clear_filecache(EAG(cache_dir)); 
    322319         
    323320    RETURN_NULL();