|
37 | 37 | #include "zend_API.h"
|
38 | 38 | #include "zend_ini.h"
|
39 | 39 | #include "TSRM/tsrm_virtual_cwd.h"
|
| 40 | +#include "ext/phar/php_phar.h" |
40 | 41 | #include "zend_accelerator_util_funcs.h"
|
41 | 42 | #include "zend_accelerator_hash.h"
|
42 | 43 |
|
@@ -144,6 +145,21 @@ static inline int is_cacheable_stream_path(const char *filename)
|
144 | 145 | memcmp(filename, "phar://", sizeof("phar://") - 1) == 0;
|
145 | 146 | }
|
146 | 147 |
|
| 148 | +static inline int is_phar_relative_alias_path(const char *filename, char **alias, int *alias_len) |
| 149 | +{ |
| 150 | + if (memcmp(filename, "phar://", sizeof("phar://") - 1) == 0 |
| 151 | + && filename[sizeof("phar://") - 1] != '\0' && filename[sizeof("phar://") - 1] != '/') { |
| 152 | + char *slash; |
| 153 | + *alias = filename + sizeof("phar://") - 1; |
| 154 | + slash = strstr(*alias, "/"); |
| 155 | + if (slash) { |
| 156 | + *alias_len = slash - *alias; |
| 157 | + return 1; |
| 158 | + } |
| 159 | + } |
| 160 | + return 0; |
| 161 | +} |
| 162 | + |
147 | 163 | /* O+ overrides PHP chdir() function and remembers the current working directory
|
148 | 164 | * in ZCG(cwd) and ZCG(cwd_len). Later accel_getcwd() can use stored value and
|
149 | 165 | * avoid getcwd() call.
|
@@ -1028,15 +1044,33 @@ char *accel_make_persistent_key_ex(zend_file_handle *file_handle, int path_lengt
|
1028 | 1044 | }
|
1029 | 1045 | memcpy(ZCG(key) + cur_len, include_path, include_path_len);
|
1030 | 1046 | ZCG(key)[key_length] = '\0';
|
1031 |
| - } else { |
1032 |
| - /* not use_cwd */ |
1033 |
| - key_length = path_length; |
| 1047 | + } else { |
| 1048 | + /* not use_cwd */ |
| 1049 | + key_length = path_length; |
1034 | 1050 | if ((size_t)key_length >= sizeof(ZCG(key))) {
|
1035 | 1051 | ZCG(key_len) = 0;
|
1036 | 1052 | return NULL;
|
| 1053 | + } else { |
| 1054 | + char *alias; |
| 1055 | + int alias_len; |
| 1056 | + if (is_phar_relative_alias_path(file_handle->filename, &alias, &alias_len)) { |
| 1057 | + char *phar_path; |
| 1058 | + int phar_path_len; |
| 1059 | + if (phar_resolve_alias(alias, alias_len, &phar_path, &phar_path_len TSRMLS_CC) == SUCCESS) { |
| 1060 | + int filename_len = strlen(file_handle->filename); |
| 1061 | + memcpy(ZCG(key), "phar://", sizeof("phar://") -1); |
| 1062 | + memcpy(ZCG(key) + sizeof("phar://") - 1, phar_path, phar_path_len); |
| 1063 | + memcpy(ZCG(key) + sizeof("phar://") - 1 + phar_path_len, |
| 1064 | + alias + alias_len, filename_len - alias_len - sizeof("phar://") + 2); |
| 1065 | + key_length = filename_len + (phar_path_len - alias_len); |
| 1066 | + } else { |
| 1067 | + memcpy(ZCG(key), file_handle->filename, key_length + 1); |
| 1068 | + } |
| 1069 | + } else { |
| 1070 | + memcpy(ZCG(key), file_handle->filename, key_length + 1); |
| 1071 | + } |
1037 | 1072 | }
|
1038 |
| - memcpy(ZCG(key), file_handle->filename, key_length + 1); |
1039 |
| - } |
| 1073 | + } |
1040 | 1074 |
|
1041 | 1075 | *key_len = ZCG(key_len) = key_length;
|
1042 | 1076 | return ZCG(key);
|
|
0 commit comments