Ticket #34976: 34976.2.diff
File 34976.2.diff, 2.1 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/class-wp-filesystem-ftpext.php
class WP_Filesystem_FTPext extends WP_Fi 322 322 if ( !empty($filelist) ) 323 323 foreach ( $filelist as $delete_file ) 324 324 $this->delete( trailingslashit($file) . $delete_file['name'], $recursive, $delete_file['type'] ); 325 325 return @ftp_rmdir($this->link, $file); 326 326 } 327 327 328 328 /** 329 329 * @access public 330 330 * 331 331 * @param string $file 332 332 * @return bool 333 333 */ 334 334 public function exists( $file ) { 335 335 $path = dirname( $file ); 336 336 $filename = basename( $file ); 337 $hidden = ( '.' === substr( $filename, 0, 1 ) ); 337 338 338 $file_list = @ftp_nlist( $this->link, '-a ' . $path ); 339 // Attempt an NLST, conditionally including -a if it's a hidden file 340 $file_list = @ftp_nlist( $this->link, ( $hidden ? '-a ' : '' ) . $path ); 339 341 if ( $file_list ) { 340 342 $file_list = array_map( 'basename', $file_list ); 343 if ( in_array( $filename, $file_list ) ) { 344 return true; 345 } 341 346 } 342 347 343 return $file_list && in_array( $filename, $file_list ); 348 // For hidden files, perform a few extra checks for compat. 349 if ( $hidden ) { 350 // Try LIST -a 351 $file_list = @ftp_rawlist( $this->link, '-a ' . $file ); 352 if ( empty( $file_list ) && $this->is_dir( $file ) ) { 353 // File is an empty directory. 354 return true; 355 } 356 // Empty list = no file, so invert. 357 if ( ! empty( $file_list ) ) { 358 return true; 359 } 360 361 // Try NLIST without -a, some servers will return hidden files this way which don't get caught by LIST -a 362 $file_list = @ftp_nlist( $this->link, $path ); 363 if ( $file_list ) { 364 $file_list = array_map( 'basename', $file_list ); 365 if ( in_array( $filename, $file_list ) ) { 366 return true; 367 } 368 } 369 } 370 371 return false; 344 372 } 345 373 346 374 /** 347 375 * @access public 348 376 * 349 377 * @param string $file 350 378 * @return bool 351 379 */ 352 380 public function is_file($file) { 353 381 return $this->exists($file) && !$this->is_dir($file); 354 382 } 355 383 356 384 /** 357 385 * @access public 358 386 *