@@ -2249,8 +2249,11 @@ private static function log_run_times_after_scenario( $scope ): void {
22492249 /**
22502250 * List the files and directories within a directory, relative to it.
22512251 *
2252+ * Symbolic links are listed, but not followed.
2253+ *
22522254 * @param string $dir
2253- * @return array<string> Relative paths, directories after their contents. Empty if the directory does not exist.
2255+ * @return array<string, bool> Whether each entry is a symbolic link, keyed by relative path, directories after
2256+ * their contents. Empty if the directory does not exist.
22542257 */
22552258 private static function list_dir ( $ dir ): array {
22562259 if ( ! is_dir ( $ dir ) ) {
@@ -2267,7 +2270,7 @@ private static function list_dir( $dir ): array {
22672270 * @var \SplFileInfo $item
22682271 */
22692272 foreach ( $ iterator as $ item ) {
2270- $ paths [] = substr ( $ item ->getPathname (), strlen ( $ dir ) + 1 );
2273+ $ paths [ substr ( $ item ->getPathname (), strlen ( $ dir ) + 1 ) ] = $ item -> isLink ( );
22712274 }
22722275
22732276 return $ paths ;
@@ -2276,14 +2279,19 @@ private static function list_dir( $dir ): array {
22762279 /**
22772280 * Remove the given files from a directory, as well as the given directories once they are empty.
22782281 *
2279- * @param string $dir
2280- * @param array<string> $paths Relative paths, directories after their contents.
2282+ * A copy of what a symbolic link pointed to is removed with all its contents.
2283+ *
2284+ * @param string $dir
2285+ * @param array<string, bool> $paths Whether each entry was a symbolic link, keyed by relative path, directories
2286+ * after their contents.
22812287 */
22822288 private static function remove_from_dir ( $ dir , array $ paths ): void {
2283- foreach ( $ paths as $ path ) {
2289+ foreach ( $ paths as $ path => $ was_link ) {
22842290 $ full_path = "{$ dir }/ {$ path }" ;
22852291
2286- if ( is_dir ( $ full_path ) && ! is_link ( $ full_path ) ) {
2292+ if ( $ was_link && is_dir ( $ full_path ) && ! is_link ( $ full_path ) ) {
2293+ self ::remove_dir ( $ full_path );
2294+ } elseif ( is_dir ( $ full_path ) && ! is_link ( $ full_path ) ) {
22872295 // Only succeeds for directories that are empty by now.
22882296 @rmdir ( $ full_path );
22892297 } elseif ( file_exists ( $ full_path ) || is_link ( $ full_path ) ) {
0 commit comments