Skip to content

Commit 505c53a

Browse files
committed
#29373: Hardcoded path causes collisions
1 parent 11c679b commit 505c53a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

app/code/Magento/Analytics/Model/ExportDataHandler.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
1010
use Magento\Framework\Archive;
11+
use Magento\Framework\Exception\FileSystemException;
1112
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\Filesystem;
1314
use Magento\Framework\Filesystem\Directory\WriteInterface;
@@ -89,8 +90,7 @@ public function __construct(
8990
public function prepareExportData()
9091
{
9192
try {
92-
$tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
93-
93+
$tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::TMP);
9494
$this->prepareDirectory($tmpDirectory, $this->getTmpFilesDirRelativePath());
9595
$this->reportWriter->write($tmpDirectory, $this->getTmpFilesDirRelativePath());
9696

@@ -106,8 +106,10 @@ public function prepareExportData()
106106
$this->cryptographer->encode($tmpDirectory->readFile($this->getArchiveRelativePath()))
107107
);
108108
} finally {
109-
$tmpDirectory->delete($this->getTmpFilesDirRelativePath());
110-
$tmpDirectory->delete($this->getArchiveRelativePath());
109+
if (isset($tmpDirectory)) {
110+
$tmpDirectory->delete($this->getTmpFilesDirRelativePath());
111+
$tmpDirectory->delete($this->getArchiveRelativePath());
112+
}
111113
}
112114

113115
return true;

app/code/Magento/Analytics/Test/Unit/Model/ExportDataHandlerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Magento\Framework\Archive;
1616
use Magento\Framework\Filesystem;
1717
use Magento\Framework\Filesystem\Directory\WriteInterface;
18-
use Magento\Framework\Filesystem\DirectoryList;
18+
use Magento\Framework\App\Filesystem\DirectoryList;
1919
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
2020
use PHPUnit\Framework\MockObject\MockObject;
2121
use PHPUnit\Framework\TestCase;
@@ -127,7 +127,7 @@ public function testPrepareExportData($isArchiveSourceDirectory)
127127
$this->filesystemMock
128128
->expects($this->once())
129129
->method('getDirectoryWrite')
130-
->with(DirectoryList::SYS_TMP)
130+
->with(DirectoryList::TMP)
131131
->willReturn($this->directoryMock);
132132
$this->directoryMock
133133
->expects($this->exactly(4))
@@ -228,7 +228,7 @@ public function testPrepareExportDataWithLocalizedException()
228228
$this->filesystemMock
229229
->expects($this->once())
230230
->method('getDirectoryWrite')
231-
->with(DirectoryList::SYS_TMP)
231+
->with(DirectoryList::TMP)
232232
->willReturn($this->directoryMock);
233233
$this->reportWriterMock
234234
->expects($this->once())

0 commit comments

Comments
 (0)