Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x]: folder rename issue in assets control panel page #16215

Closed
ps-paxxion opened this issue Nov 26, 2024 · 5 comments
Closed

[5.x]: folder rename issue in assets control panel page #16215

ps-paxxion opened this issue Nov 26, 2024 · 5 comments
Labels

Comments

@ps-paxxion
Copy link
Contributor

What happened?

Description

Renaming a folder in the control panel page changes the physical location of the renamed folder from its defined filesystem to the @webroot of the app.
This creates issues when re-indexing assets from the assets index control panel because the re-indexing cannot find the physical renamed folder.

Steps to reproduce

  1. create local filesystem named "Test" and set base path to "@webroot/test"
  2. create volume named "Test" and attach it to the "Test" filesytem
  3. go to Assets > Test
  4. create folder named "test-01"
  5. check its physical location, it will be in @webroot/test/test-01
  6. rename the folder "test-01" to "test-02"
  7. check its physical location, it will be @webroot/test-02 instead of @webroot/test/test-02

Expected behavior

The renamed folder should stay in its original parent path

Actual behavior

The renamed folder gets moved to the @webroot of the app

Craft CMS version

5.5.3

PHP version

8.2.26

Operating system and version

WINNT 10.0

Database type and version

MariaDB 10.6.17

Image driver and version

GD 8.2.26

Installed plugins and versions

@ps-paxxion ps-paxxion added the bug label Nov 26, 2024
@i-just
Copy link
Contributor

i-just commented Nov 27, 2024

Hi, thanks for getting in touch!
I can’t reproduce this on a clean install. Are you overwriting the webroot alias (via config/general.php, .env, etc.)?
Could you also enable safeMode and check if you’re experiencing the same behaviour?

@ps-paxxion
Copy link
Contributor Author

Hi, thanks for getting in touch! I can’t reproduce this on a clean install. Are you overwriting the webroot alias (via config/general.php, .env, etc.)? Could you also enable safeMode and check if you’re experiencing the same behaviour?

Hello,
I tried with safeMode enabled via config/general.php and still getting the same behaviour.

I do have the @webroot alias overwritten via config/general.php.
My app structure consists of 2 folders:

  • private_html
  • public_html

And in my config/general.php I have
'@webroot' => realpath(dirname(__DIR__) . '/../public_html'),

I tried also with a clean install, without changing the folder structure and following the steps listed in my first post and I do get the same behaviour.

@ps-paxxion
Copy link
Contributor Author

ps-paxxion commented Nov 28, 2024

@i-just I found the problem by debugging the renaming procedure in the codebase.

The behaviour I reported is reproducible only on a windows machine.
The problem is that paths in windows use \ character as folder separators instead of /

In the renameDirectory method in /src/fs/Local.php the explode is on the / character, so the array_pop resets the entire file path.

public function renameDirectory(string $path, string $newName): void
    {
        if (!is_dir($this->prefixPath($path))) {
            throw new FsObjectNotFoundException('No folder exists at path: ' . $path);
        }

        $components = explode("/", $this->prefixPath($path));
        array_pop($components);
        $components[] = $newName;
        $newPath = implode("/", $components);

        @rename($this->prefixPath($path), $newPath);
    }

DIRECTORY_SEPARATOR should be used instead of the hardcoded /
Created a PR: #16231

@brandonkelly
Copy link
Member

Thanks! Fixed via cbdf803 / #16231.

@brandonkelly
Copy link
Member

Craft 4.13.4 and 5.5.4 are out with that fix. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants