@@ -302,39 +302,37 @@ static int ps_files_cleanup_dir(const zend_string *dirname, zend_long maxlifetim
302302
303303 if (remaining_depth == 0 ) {
304304 time (& now );
305- while ((entry = readdir (dir ))) {
306- if (!strncmp (entry -> d_name , FILE_PREFIX , sizeof (FILE_PREFIX ) - 1 )) {
307- size_t entry_len = strlen (entry -> d_name );
308- if (entry_len + ZSTR_LEN (dirname ) + 2 < MAXPATHLEN ) {
309- memcpy (buf + ZSTR_LEN (dirname ) + 1 , entry -> d_name , entry_len );
310- buf [ZSTR_LEN (dirname ) + entry_len + 1 ] = '\0' ;
311- if (VCWD_STAT (buf , & sbuf ) == 0 &&
312- (now - sbuf .st_mtime ) > maxlifetime ) {
313- VCWD_UNLINK (buf );
314- nrdels ++ ;
315- }
316- }
317- }
305+ }
306+
307+ while ((entry = readdir (dir ))) {
308+ if (entry -> d_name [0 ] == '.' &&
309+ (entry -> d_name [1 ] == '\0' ||
310+ (entry -> d_name [1 ] == '.' && entry -> d_name [2 ] == '\0' ))) {
311+ continue ;
318312 }
319- } else {
320- while ((entry = readdir (dir ))) {
321- if (entry -> d_name [0 ] == '.' &&
322- (entry -> d_name [1 ] == '\0' ||
323- (entry -> d_name [1 ] == '.' && entry -> d_name [2 ] == '\0' ))) {
324- continue ;
313+ if (remaining_depth == 0 && strncmp (entry -> d_name , FILE_PREFIX , sizeof (FILE_PREFIX ) - 1 ) != 0 ) {
314+ continue ;
315+ }
316+ size_t entry_len = strlen (entry -> d_name );
317+ if (ZSTR_LEN (dirname ) + 1 + entry_len >= MAXPATHLEN ) {
318+ continue ;
319+ }
320+ memcpy (buf + ZSTR_LEN (dirname ) + 1 , entry -> d_name , entry_len );
321+ buf [ZSTR_LEN (dirname ) + 1 + entry_len ] = '\0' ;
322+ if (VCWD_STAT (buf , & sbuf ) != 0 ) {
323+ continue ;
324+ }
325+ if (remaining_depth == 0 ) {
326+ if ((now - sbuf .st_mtime ) > maxlifetime ) {
327+ VCWD_UNLINK (buf );
328+ nrdels ++ ;
325329 }
326- size_t entry_len = strlen (entry -> d_name );
327- if (ZSTR_LEN (dirname ) + 1 + entry_len < MAXPATHLEN ) {
328- memcpy (buf + ZSTR_LEN (dirname ) + 1 , entry -> d_name , entry_len );
329- buf [ZSTR_LEN (dirname ) + 1 + entry_len ] = '\0' ;
330- if (VCWD_STAT (buf , & sbuf ) == 0 && S_ISDIR (sbuf .st_mode )) {
331- zend_string * subdir = zend_string_init (buf , ZSTR_LEN (dirname ) + 1 + entry_len , 0 );
332- int n = ps_files_cleanup_dir (subdir , maxlifetime , remaining_depth - 1 );
333- zend_string_release (subdir );
334- if (n >= 0 ) {
335- nrdels += n ;
336- }
337- }
330+ } else if (S_ISDIR (sbuf .st_mode )) {
331+ zend_string * subdir = zend_string_init (buf , ZSTR_LEN (dirname ) + 1 + entry_len , 0 );
332+ int n = ps_files_cleanup_dir (subdir , maxlifetime , remaining_depth - 1 );
333+ zend_string_release (subdir );
334+ if (n >= 0 ) {
335+ nrdels += n ;
338336 }
339337 }
340338 }
0 commit comments