wecodemore / wpstarter

Easily bootstrap whole site Composer packages for WordPress.
https://wecodemore.github.io/wpstarter/
MIT License
246 stars 35 forks source link

EnvExampleStep concatenates two absolute paths #105

Closed dnaber-de closed 1 year ago

dnaber-de commented 3 years ago

Describe the bug When I run composer install I see WPStarter responding with an error message:

  /var/www/templates/.env.example  
  is not a valid valid relative path to env-example file.

To Reproduce I'm using wpstarter at dev-version-3 constraint so basically the latest development version.

This is my wpstarter config in composer.json:

"wpstarter": {
    "register-theme-folder": false,
    "prevent-overwrite": [
        ".gitignore"
    ],
    "env-example": "templates/.env.example"
}

When I step debug EnvExampleStep::run() I see that $source already contains the absolute path /var/www/templates/.env.example. But it seems that $paths->root() expect a relative path and returns /var/www/var/www/templates/.env.example which causes realpath() to return false of course.

public function run(Config $config, Paths $paths): int
{
    /** @var string|bool $source */
    $source = $this->config[Config::ENV_EXAMPLE]->unwrapOrFallback(false);
    if (!$source) {
        return Step::NONE;
    }

    $destination = $this->targetPath($paths);

    if (is_string($source) && filter_var($source, FILTER_VALIDATE_URL)) {
        return $this->download($source, $destination);
    }

    $isAsk = $source === OptionalStep::ASK;

    if (!$isAsk && is_string($source)) {
        $realpath = realpath($paths->root($source));
        if (!$realpath) {
            $this->error = "{$source} is not a valid valid relative path to env-example file.";

            return Step::ERROR;
        }

        return $this->copy($paths, $destination, $realpath);
    }

    return $this->copy($paths, $destination);
}

Expected behavior I would expect that templates/.env.example to .env.

gmazzap commented 2 years ago

@dnaber-de can you verify 73e66b2 fixed it?

gmazzap commented 1 year ago

This is merged, and I'm closing for lack of activity. I think the issue should be solved, by the way.