@@ -664,42 +664,52 @@ static void zend_file_cache_serialize(zend_persistent_script *script,
664
664
new_script -> mem = NULL ;
665
665
}
666
666
667
- int zend_file_cache_script_store ( zend_persistent_script * script , int in_shm )
667
+ static char * zend_file_cache_get_bin_file_path ( zend_string * script_path )
668
668
{
669
669
size_t len ;
670
- int fd ;
671
670
char * filename ;
672
- zend_file_cache_metainfo info ;
673
- #ifndef ZEND_WIN32
674
- struct iovec vec [3 ];
675
- #endif
676
- void * mem , * buf ;
677
671
678
672
len = strlen (ZCG (accel_directives ).file_cache );
679
- filename = emalloc (len + 33 + ZSTR_LEN (script -> full_path ) + sizeof (SUFFIX ));
673
+ filename = emalloc (len + 33 + ZSTR_LEN (script_path ) + sizeof (SUFFIX ));
680
674
memcpy (filename , ZCG (accel_directives ).file_cache , len );
681
675
#ifndef ZEND_WIN32
682
676
filename [len ] = '/' ;
683
677
memcpy (filename + len + 1 , ZCG (system_id ), 32 );
684
- memcpy (filename + len + 33 , ZSTR_VAL (script -> full_path ), ZSTR_LEN (script -> full_path ));
685
- memcpy (filename + len + 33 + ZSTR_LEN (script -> full_path ), SUFFIX , sizeof (SUFFIX ));
678
+ memcpy (filename + len + 33 , ZSTR_VAL (script_path ), ZSTR_LEN (script_path ));
679
+ memcpy (filename + len + 33 + ZSTR_LEN (script_path ), SUFFIX , sizeof (SUFFIX ));
686
680
#else
687
681
filename [len ] = '\\' ;
688
682
memcpy (filename + len + 1 , ZCG (system_id ), 32 );
689
- if (ZSTR_LEN (script -> full_path ) >= 2 && ':' == ZSTR_VAL (script -> full_path )[1 ]) {
683
+ if (ZSTR_LEN (script_path ) >= 2 && ':' == ZSTR_VAL (script_path )[1 ]) {
690
684
/* local fs */
691
685
* (filename + len + 33 ) = '\\' ;
692
- * (filename + len + 34 ) = ZSTR_VAL (script -> full_path )[0 ];
693
- memcpy (filename + len + 35 , ZSTR_VAL (script -> full_path ) + 2 , ZSTR_LEN (script -> full_path ) - 2 );
694
- memcpy (filename + len + 35 + ZSTR_LEN (script -> full_path ) - 2 , SUFFIX , sizeof (SUFFIX ));
686
+ * (filename + len + 34 ) = ZSTR_VAL (script_path )[0 ];
687
+ memcpy (filename + len + 35 , ZSTR_VAL (script_path ) + 2 , ZSTR_LEN (script_path ) - 2 );
688
+ memcpy (filename + len + 35 + ZSTR_LEN (script_path ) - 2 , SUFFIX , sizeof (SUFFIX ));
695
689
} else {
696
690
/* network path */
697
- memcpy (filename + len + 33 , ZSTR_VAL (script -> full_path ), ZSTR_LEN (script -> full_path ));
698
- memcpy (filename + len + 33 + ZSTR_LEN (script -> full_path ), SUFFIX , sizeof (SUFFIX ));
691
+ memcpy (filename + len + 33 , ZSTR_VAL (script_path ), ZSTR_LEN (script_path ));
692
+ memcpy (filename + len + 33 , ZSTR_VAL (script_path ), ZSTR_LEN (script_path ));
693
+ memcpy (filename + len + 33 + ZSTR_LEN (script_path ), SUFFIX , sizeof (SUFFIX ));
699
694
}
700
695
#endif
701
696
702
- if (zend_file_cache_mkdir (filename , len ) != SUCCESS ) {
697
+ return filename ;
698
+ }
699
+
700
+ int zend_file_cache_script_store (zend_persistent_script * script , int in_shm )
701
+ {
702
+ int fd ;
703
+ char * filename ;
704
+ zend_file_cache_metainfo info ;
705
+ #ifndef ZEND_WIN32
706
+ struct iovec vec [3 ];
707
+ #endif
708
+ void * mem , * buf ;
709
+
710
+ filename = zend_file_cache_get_bin_file_path (script -> full_path );
711
+
712
+ if (zend_file_cache_mkdir (filename , strlen (ZCG (accel_directives ).file_cache )) != SUCCESS ) {
703
713
zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot create directory for file '%s'\n" , filename );
704
714
efree (filename );
705
715
return FAILURE ;
@@ -1178,7 +1188,6 @@ static void zend_file_cache_unserialize(zend_persistent_script *script,
1178
1188
zend_persistent_script * zend_file_cache_script_load (zend_file_handle * file_handle )
1179
1189
{
1180
1190
zend_string * full_path = file_handle -> opened_path ;
1181
- size_t len ;
1182
1191
int fd ;
1183
1192
char * filename ;
1184
1193
zend_persistent_script * script ;
@@ -1190,13 +1199,7 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
1190
1199
if (!full_path ) {
1191
1200
return NULL ;
1192
1201
}
1193
- len = strlen (ZCG (accel_directives ).file_cache );
1194
- filename = emalloc (len + 33 + ZSTR_LEN (full_path ) + sizeof (SUFFIX ));
1195
- memcpy (filename , ZCG (accel_directives ).file_cache , len );
1196
- filename [len ] = '/' ;
1197
- memcpy (filename + len + 1 , ZCG (system_id ), 32 );
1198
- memcpy (filename + len + 33 , ZSTR_VAL (full_path ), ZSTR_LEN (full_path ));
1199
- memcpy (filename + len + 33 + ZSTR_LEN (full_path ), SUFFIX , sizeof (SUFFIX ));
1202
+ filename = zend_file_cache_get_bin_file_path (full_path );
1200
1203
1201
1204
fd = open (filename , O_RDONLY | O_BINARY );
1202
1205
if (fd < 0 ) {
@@ -1342,16 +1345,9 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
1342
1345
1343
1346
void zend_file_cache_invalidate (zend_string * full_path )
1344
1347
{
1345
- size_t len ;
1346
1348
char * filename ;
1347
1349
1348
- len = strlen (ZCG (accel_directives ).file_cache );
1349
- filename = emalloc (len + 33 + ZSTR_LEN (full_path ) + sizeof (SUFFIX ));
1350
- memcpy (filename , ZCG (accel_directives ).file_cache , len );
1351
- filename [len ] = '/' ;
1352
- memcpy (filename + len + 1 , ZCG (system_id ), 32 );
1353
- memcpy (filename + len + 33 , ZSTR_VAL (full_path ), ZSTR_LEN (full_path ));
1354
- memcpy (filename + len + 33 + ZSTR_LEN (full_path ), SUFFIX , sizeof (SUFFIX ));
1350
+ filename = zend_file_cache_get_bin_file_path (full_path );
1355
1351
1356
1352
unlink (filename );
1357
1353
efree (filename );
0 commit comments