Skip to content

Commit b90e799

Browse files
committed
Add an option to override the filename
This is useful when replacing the file with a temporarily generated name.
1 parent 11833e8 commit b90e799

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

wcfsetup/install/files/lib/system/file/command/ReplaceFileSource.class.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ final class ReplaceFileSource
2525
public function __construct(
2626
private readonly File $file,
2727
private readonly string $pathname,
28+
private readonly ?string $filename = null,
2829
) {}
2930

3031
public function __invoke(): File
@@ -70,7 +71,7 @@ private function replaceSource(): File
7071
[$width, $height] = \getimagesize($this->pathname);
7172
}
7273

73-
$filename = \basename($this->pathname);
74+
$filename = $this->filename ? $this->filename : \basename($this->pathname);
7475
$fileSize = \filesize($this->pathname);
7576
$fileHash = \hash_file('sha256', $this->pathname);
7677
$fileExtension = File::getSafeFileExtension($mimeType, $filename);
@@ -105,6 +106,9 @@ private function replaceSource(): File
105106

106107
$updatedFile = new File($this->file->fileID);
107108

109+
$path = \dirname($updatedFile->getPathname());
110+
FileUtil::makePath($path);
111+
108112
\rename(
109113
$this->pathname,
110114
$updatedFile->getPathname(),

0 commit comments

Comments
 (0)