Skip to content

Commit

Permalink
[BUGFIX] Do not try to create symlinks on Windows
Browse files Browse the repository at this point in the history
When a junction already exists on Windows, it is tried
to create a symlink, because of a missing OS check.

While this works as errors are ignored, it is
an unnecessary filesystem call.

Therefore the code is changed to only emit
the appropriate filesystem operations per OS.

Resolves: #101871
Related: #98434
Related: #98447
Releases: main, 12.4, 11.5
Change-Id: Ifafadceae3742da23fd1a40e5aab50074e60313c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80904
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benjamin Franzke <ben@bnf.dev>
Reviewed-by: Benjamin Franzke <ben@bnf.dev>
  • Loading branch information
helhum authored and bnf committed Sep 8, 2023
1 parent 12367f3 commit 119c4d9
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions typo3/sysext/core/Classes/Composer/PackageArtifactBuilder.php
Expand Up @@ -275,11 +275,31 @@ private function publishResources(array $installedTypo3Packages): void
[$relativePrefix] = explode('Resources/Public', $relativePath);
$publicResourcesPath = $this->fileSystem->normalizePath($this->config->get('web-dir') . '/_assets/' . md5($relativePrefix));
$this->fileSystem->ensureDirectoryExists(dirname($publicResourcesPath));
if (Platform::isWindows() && !$this->fileSystem->isJunction($publicResourcesPath)) {
$this->fileSystem->junction($fileSystemResourcesPath, $publicResourcesPath);
} elseif (!$this->fileSystem->isSymlinkedDirectory($publicResourcesPath)) {
$this->fileSystem->relativeSymlink($fileSystemResourcesPath, $publicResourcesPath);
if (Platform::isWindows()) {
$this->ensureJunctionExists($fileSystemResourcesPath, $publicResourcesPath);
} else {
$this->ensureSymlinkExists($fileSystemResourcesPath, $publicResourcesPath);
}
}
}

private function ensureJunctionExists(string $target, string $junction): void
{
if (!$this->fileSystem->isJunction($junction)) {
// Cleanup a possible symlink that might have been installed by ourselves prior to #98434
// Note: Unprivileged deletion of symlinks is allowed, even if they were created by a
// privileged user
if (is_link($junction)) {
$this->fileSystem->unlink($junction);
}
$this->fileSystem->junction($target, $junction);
}
}

private function ensureSymlinkExists(string $target, string $link): void
{
if (!$this->fileSystem->isSymlinkedDirectory($link)) {
$this->fileSystem->relativeSymlink($target, $link);
}
}
}

0 comments on commit 119c4d9

Please sign in to comment.