Show
Ignore:
Timestamp:
07/24/06 14:49:43 (2 years ago)
Author:
bart
Message:

* Make clean routine support dir hashing. Again, this should be tested on win32!
* Use a define for the magic string in the eAccelerator file headers
* Bump up version to 0.9.5-rc1
* Put -O2 back on for -rc1

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eaccelerator/trunk/ea_info.c

    r232 r237  
    107107                closedir (dp); 
    108108        } else { 
    109                 ea_debug_error("eAccelerator: Could not open cachedir %s\n", dir); 
     109                ea_debug_error("[%s] Could not open cachedir %s\n", EACCELERATOR_EXTENSION_NAME, dir); 
    110110        } 
    111111} 
     
    118118   
    119119    memcpy(path, dir, dirlen); 
    120     strcpy(path + dirlen++, "\\*"); 
     120    strcpy(path + dirlen++, "\\eaccelerator*"); 
    121121 
    122122    hFind = FindFirstFile(path, &wfd); 
     
    127127                                clear_filecache(path); 
    128128                        } else if (!DeleteFile(path)) { 
    129                                 zend_error(E_CORE_WARNING, "Can't delete file %s: error %d", path, GetLastError()); 
     129                                ea_debug_error("[%s] Can't delete file %s: error %d\n", EACCELERATOR_EXTENSION_NAME, path, GetLastError()); 
     130                        } 
     131                } while (FindNextFile(hFind, &wfd)); 
     132        } 
     133    FindClose (hFind); 
     134
     135#endif 
     136/* }}} */ 
     137 
     138/* {{{  clean_file: check if the given file is expired */ 
     139static inline void clean_file(char *file, time_t t)  
     140
     141        int f; 
     142 
     143        if ((f = open(file, O_RDONLY | O_BINARY)) > 0) { 
     144                mm_file_header hdr; 
     145                EACCELERATOR_FLOCK (f, LOCK_SH); 
     146                if (read(f, &hdr, sizeof(hdr)) != sizeof(hdr)  
     147                                || strncmp (hdr.magic, EA_MAGIC,        8) != 0  
     148                                || (hdr.mtime != 0 && hdr.mtime < t)) { 
     149                        EACCELERATOR_FLOCK (f, LOCK_UN); 
     150                        close (f); 
     151                        unlink (file); 
     152                } else { 
     153                        EACCELERATOR_FLOCK (f, LOCK_UN); 
     154                        close (f); 
     155                } 
     156        } 
     157
     158/* }}} */ 
     159 
     160/* {{{ clean_filecache(): Helper function for eaccelerator_clean, it will remove all expired entries from the user cache */ 
     161static void clean_filecache(const char* dir, time_t t) 
     162#ifndef ZEND_WIN32 
     163
     164        DIR *dp; 
     165        struct dirent *entry; 
     166        char s[MAXPATHLEN]; 
     167        struct stat dirstat; 
     168         
     169        if ((dp = opendir(dir)) != NULL) { 
     170                while ((entry = readdir(dp)) != NULL) { 
     171                        strncpy(s, dir, MAXPATHLEN - 1); 
     172                        strlcat(s, "/", MAXPATHLEN); 
     173                        strlcat(s, entry->d_name, MAXPATHLEN); 
     174                        if (strstr(entry->d_name, "eaccelerator-user") == entry->d_name) { 
     175                                clean_file(s, t); 
     176                        } 
     177                        if (stat(s, &dirstat) != -1) { 
     178                                if (strcmp(entry->d_name, ".") == 0) 
     179                                        continue; 
     180                                if (strcmp(entry->d_name, "..") == 0) 
     181                                        continue; 
     182                                if (S_ISDIR(dirstat.st_mode)) { 
     183                                        clean_filecache(s, t); 
     184                                } 
     185                        } 
     186                } 
     187                closedir (dp); 
     188        } else { 
     189                ea_debug_error("[%s] Could not open cachedir %s\n", EACCELERATOR_EXTENSION_NAME, dir); 
     190        } 
     191
     192#else 
     193
     194        HANDLE  hFind; 
     195    WIN32_FIND_DATA wfd; 
     196    char path[MAXPATHLEN]; 
     197    size_t dirlen = strlen(dir); 
     198   
     199    memcpy(path, dir, dirlen); 
     200    strcpy(path + dirlen++, "\\eaccelerator-user*"); 
     201 
     202    hFind = FindFirstFile(path, &wfd); 
     203        if (hFind == INVALID_HANDLE_VALUE) { 
     204                do { 
     205                        strcpy(path + dirlen, wfd.cFileName); 
     206                        if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes) { 
     207                                clear_filecache(path); 
     208                        } else { 
     209                                clean_file(path, t); 
    130210                        } 
    131211                } while (FindNextFile(hFind, &wfd)); 
     
    202282 
    203283        /* Remove expired keys (session data, content) from disk cache */ 
    204 #ifndef ZEND_WIN32 
    205         /* clear file cache */ 
    206         { 
    207                 DIR *dp; 
    208                 struct dirent *entry; 
    209                 char s[MAXPATHLEN]; 
    210  
    211                 if ((dp = opendir (EAG (cache_dir))) != NULL) { 
    212                         while ((entry = readdir (dp)) != NULL) { 
    213                                 if (strstr(entry->d_name, "eaccelerator-user") == entry->d_name) { 
    214                                         int f; 
    215                                         strncpy (s, EAG (cache_dir), MAXPATHLEN - 1); 
    216                                         strlcat (s, "/", MAXPATHLEN); 
    217                                         strlcat (s, entry->d_name, MAXPATHLEN); 
    218                                         if ((f = open (s, O_RDONLY | O_BINARY)) > 0) { 
    219                                                 mm_file_header hdr; 
    220                                                 EACCELERATOR_FLOCK (f, LOCK_SH); 
    221                                                 if (read (f, &hdr, sizeof (hdr)) != sizeof (hdr)  
    222                                 || strncmp (hdr.magic, "EACCELERATOR",  8) != 0 || (hdr.mtime != 0 && hdr.mtime < t)) { 
    223                                                         EACCELERATOR_FLOCK (f, LOCK_UN); 
    224                                                         close (f); 
    225                                                         unlink (s); 
    226                                                 } else { 
    227                                                         EACCELERATOR_FLOCK (f, LOCK_UN); 
    228                                                         close (f); 
    229                                                 } 
    230                                         } 
    231                                 } 
    232                         } 
    233                         closedir (dp); 
    234                 } 
    235         } 
    236 #else 
    237         { 
    238                 HANDLE hList; 
    239                 TCHAR szDir[MAXPATHLEN]; 
    240                 WIN32_FIND_DATA FileData; 
    241                 char s[MAXPATHLEN]; 
    242  
    243                 snprintf (szDir, MAXPATHLEN, "%s\\eaccelerator-user*", EAG (cache_dir)); 
    244  
    245                 if ((hList = FindFirstFile (szDir, &FileData)) != INVALID_HANDLE_VALUE) { 
    246                         do { 
    247                                 int f; 
    248                                 strncpy (s, EAG (cache_dir), MAXPATHLEN - 1); 
    249                                 strlcat (s, "\\", MAXPATHLEN); 
    250                                 strlcat (s, FileData.cFileName, MAXPATHLEN); 
    251                                 if ((f = open (s, O_RDONLY | O_BINARY)) > 0) { 
    252                                         mm_file_header hdr; 
    253                                         EACCELERATOR_FLOCK (f, LOCK_SH); 
    254                                         if (read (f, &hdr, sizeof (hdr)) != sizeof (hdr)  
    255                             || strncmp (hdr.magic, "EACCELERATOR", 8) != 0 || (hdr.mtime != 0 && hdr.mtime < t)) { 
    256                                                 EACCELERATOR_FLOCK (f, LOCK_UN); 
    257                                                 close (f); 
    258                                                 unlink (s); 
    259                                         } else { 
    260                                                 EACCELERATOR_FLOCK (f, LOCK_UN); 
    261                                                 close (f); 
    262                                         } 
    263                                 } 
    264                         } 
    265                         while (FindNextFile (hList, &FileData)); 
    266                 } 
    267                 FindClose (hList); 
    268         } 
    269 #endif 
     284        clean_filecache(EAG(cache_dir), t); 
     285 
    270286        /* Remove expired keys (session data, content) from shared memory */ 
    271287        eaccelerator_gc (TSRMLS_C);