wp-cli / wp-cli-tests

WP-CLI testing framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect temp dir check on macOS

swissspidy opened this issue · comments

I'm running macOS High Sierra (10.13) and PHP 7.2.6 (installed via Homebrew).

I noticed in wp-cli/language-command#38 that on macOS the following check always fails:

if ( 0 !== strpos( $dir, sys_get_temp_dir() ) ) {
throw new RuntimeException( sprintf( "Attempted to delete directory '%s' that is not in the temp directory '%s'. " . __FILE__ . ':' . __LINE__, $dir, sys_get_temp_dir() ) );
}

In my case, sys_get_temp_dir() points to /private/var/some-path-to-wp-cli.../.

$dir on the other hand points to /var/some-path-to-wp-cli.../. That's why I get an exception every time.

However, on macOS, /var is a symlink to /private/var though, so these paths are actually equal.

To solve this, realpath() needs to be used to resolve the symlinks before comparing the paths.

PR imminent.