@@ -1315,15 +1315,25 @@ ngx_http_purge_file_cache_delete_file(ngx_tree_ctx_t *ctx, ngx_str_t *path) {
1315
1315
}
1316
1316
1317
1317
1318
+ typedef struct {
1319
+ u_char * key_partial ;
1320
+ u_char * key_in_file ;
1321
+ ngx_uint_t key_len ;
1322
+ } ngx_http_cache_purge_partial_ctx_t ;
1323
+
1318
1324
static ngx_int_t
1319
1325
ngx_http_purge_file_cache_delete_partial_file (ngx_tree_ctx_t * ctx , ngx_str_t * path ) {
1326
+ ngx_http_cache_purge_partial_ctx_t * data ;
1320
1327
u_char * key_partial ;
1321
1328
u_char * key_in_file ;
1322
1329
ngx_uint_t len ;
1323
1330
ngx_flag_t remove_file = 0 ;
1324
1331
1325
- key_partial = ctx -> data ;
1326
- len = ngx_strlen (key_partial );
1332
+ data = ctx -> data ;
1333
+
1334
+ key_partial = data -> key_partial ;
1335
+ key_in_file = data -> key_in_file ;
1336
+ len = data -> key_len ;
1327
1337
1328
1338
/* if key_partial is empty always match, because is a '*' */
1329
1339
if (len == 0 ) {
@@ -1342,9 +1352,7 @@ ngx_http_purge_file_cache_delete_partial_file(ngx_tree_ctx_t *ctx, ngx_str_t *pa
1342
1352
}
1343
1353
file .log = ctx -> log ;
1344
1354
1345
- /* I don't know if it's a good idea to use the ngx_cycle pool for this,
1346
- but the request is not available here */
1347
- key_in_file = ngx_pcalloc (ngx_cycle -> pool , sizeof (u_char ) * (len + 1 ));
1355
+ ngx_memzero (key_in_file , sizeof (u_char ) * len );
1348
1356
1349
1357
/* KEY: /proxy/passwd */
1350
1358
/* since we don't need the "KEY: " ignore 5 + 1 extra u_char from last
@@ -1807,18 +1815,21 @@ ngx_http_cache_purge_partial(ngx_http_request_t *r, ngx_http_file_cache_t *cache
1807
1815
"purge_partial http in %s" ,
1808
1816
cache -> path -> name .data );
1809
1817
1810
- u_char * key_partial ;
1811
- ngx_str_t * key ;
1812
- ngx_http_cache_t * c ;
1813
- ngx_uint_t len ;
1818
+ ngx_str_t * keys ;
1819
+ ngx_str_t key ;
1814
1820
1815
- c = r -> cache ;
1816
- key = c -> keys .elts ;
1817
- len = key [0 ].len ;
1821
+ /* Only check the first key, and discard '*' at the end */
1822
+ keys = r -> cache -> keys .elts ;
1823
+ key = keys [0 ];
1824
+ key .len -- ;
1818
1825
1819
- /* Only check the first key */
1820
- key_partial = ngx_pcalloc (r -> pool , sizeof (u_char ) * len );
1821
- ngx_memcpy (key_partial , key [0 ].data , sizeof (u_char ) * (len - 1 ));
1826
+ ngx_http_cache_purge_partial_ctx_t * ctx ;
1827
+ ctx = ngx_palloc (r -> pool , sizeof (ngx_http_cache_purge_partial_ctx_t ));
1828
+ ctx -> key_len = key .len ;
1829
+ if (key .len > 0 ) {
1830
+ ctx -> key_partial = key .data ;
1831
+ ctx -> key_in_file = ngx_pnalloc (r -> pool , sizeof (u_char ) * key .len );
1832
+ }
1822
1833
1823
1834
/* Walk the tree and remove all the files matching key_partial */
1824
1835
ngx_tree_ctx_t tree ;
@@ -1827,7 +1838,7 @@ ngx_http_cache_purge_partial(ngx_http_request_t *r, ngx_http_file_cache_t *cache
1827
1838
tree .pre_tree_handler = ngx_http_purge_file_cache_noop ;
1828
1839
tree .post_tree_handler = ngx_http_purge_file_cache_noop ;
1829
1840
tree .spec_handler = ngx_http_purge_file_cache_noop ;
1830
- tree .data = key_partial ;
1841
+ tree .data = ctx ;
1831
1842
tree .alloc = 0 ;
1832
1843
tree .log = ngx_cycle -> log ;
1833
1844
0 commit comments