Skip to content

Commit

Permalink
Merge branch 'bugfix/16215-rename-directory' into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Nov 29, 2024
2 parents e8082f6 + efd819a commit cbdf803
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fixed an error that could occur when duplicating an element with an Assets field that had a dynamic subpath. ([#16214](https://github.com/craftcms/cms/issues/16214))
- Reduced the likelihood of a deadlock error occurring when updating search indexes. ([#15221](https://github.com/craftcms/cms/issues/15221))
- Fixed a bug where renaming asset folders could move them to the webroot on Windows. ([#16215](https://github.com/craftcms/cms/issues/16215))

## 4.13.3 - 2024-11-22

Expand Down
12 changes: 7 additions & 5 deletions src/fs/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,18 @@ public function deleteDirectory(string $path): void
*/
public function renameDirectory(string $path, string $newName): void
{
if (!is_dir($this->prefixPath($path))) {
$fullPath = $this->prefixPath($path);

if (!is_dir($fullPath)) {
throw new FsObjectNotFoundException('No folder exists at path: ' . $path);
}

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

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

/**
Expand Down Expand Up @@ -413,7 +415,7 @@ protected function prefixPath(string $path = ''): string
throw new FsException("The path `$path` is not contained.");
}

return $this->getRootPath() . DIRECTORY_SEPARATOR . $path;
return $this->getRootPath() . DIRECTORY_SEPARATOR . FileHelper::normalizePath($path);
}

/**
Expand Down

0 comments on commit cbdf803

Please sign in to comment.