Index: trunk/extensions/Deployment/includes/filesystems/Ssh2Filesystem.php |
— | — | @@ -342,7 +342,66 @@ |
343 | 343 | * @see Filesystem::listDir |
344 | 344 | */ |
345 | 345 | public function listDir( $path, $includeHidden = true, $recursive = false ) { |
| 346 | + if ( $this->isFile( $path ) ) { |
| 347 | + $limit_file = basename( $path ); |
| 348 | + $path = dirname( $path ); |
| 349 | + } else { |
| 350 | + $limit_file = false; |
| 351 | + } |
| 352 | + |
| 353 | + if ( !$this->isDir( $path ) ) { |
| 354 | + return false; |
| 355 | + } |
| 356 | + |
| 357 | + $ret = array(); |
| 358 | + wfSuppressWarnings(); |
| 359 | + $dir = dir( 'ssh2.sftp://' . $this->sftpConnection .'/' . ltrim( $path, '/' ) ); |
| 360 | + wfRestoreWarnings(); |
| 361 | + |
| 362 | + if ( !$dir ) { |
| 363 | + return false; |
| 364 | + } |
| 365 | + |
| 366 | + while (false !== ( $entry = $dir->read() ) ) { |
| 367 | + $struc = array(); |
| 368 | + $struc['name'] = $entry; |
| 369 | + |
| 370 | + if ( |
| 371 | + ('.' == $struc['name'] || '..' == $struc['name'] ) |
| 372 | + || ( !$include_hidden && '.' == $struc['name'][0] ) |
| 373 | + || ( $limit_file && $struc['name'] != $limit_file ) |
| 374 | + ) { |
| 375 | + continue; // Do not care about these folders. |
| 376 | + } |
| 377 | + |
| 378 | + $entryPath = "$path/$entry"; |
| 379 | + |
| 380 | + $struc['perms'] = $this->getChmod( $entryPath ); |
| 381 | + $struc['number'] = false; |
| 382 | + $struc['owner'] = $this->getOwner( $entryPath ); |
| 383 | + $struc['group'] = $this->getGroup( $entryPath ); |
| 384 | + $struc['size'] = $this->getSize( $entryPath ); |
| 385 | + $struc['lastmodunix']= $this->getModificationTime( $entryPath ); |
| 386 | + $struc['lastmod'] = date( 'M j', $struc['lastmodunix'] ); |
| 387 | + $struc['time'] = date( 'h:i:s', $struc['lastmodunix'] ); |
| 388 | + $struc['type'] = $this->isDir( $entryPath ) ? 'd' : 'f'; |
| 389 | + |
| 390 | + if ( 'd' == $struc['type'] ) { |
| 391 | + if ( $recursive ) { |
| 392 | + $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive ); |
| 393 | + } |
| 394 | + else { |
| 395 | + $struc['files'] = array(); |
| 396 | + } |
| 397 | + } |
| 398 | + |
| 399 | + $ret[$struc['name']] = $struc; |
| 400 | + } |
346 | 401 | |
| 402 | + $dir->close(); |
| 403 | + unset( $dir ); |
| 404 | + |
| 405 | + return $ret; |
347 | 406 | } |
348 | 407 | |
349 | 408 | /** |