Skip to content

Commit 1637cf5

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-88432: Filesystem Directory Improvement
1 parent 7a1cbcc commit 1637cf5

File tree

3 files changed

+16
-3
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import
  • dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import
  • lib/internal/Magento/Framework/Filesystem/Directory

3 files changed

+16
-3
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Uploader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,12 @@ public function move($fileName, $renameFileOff = false)
177177
);
178178
}
179179

180-
$filePath = $this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName);
180+
if ($this->getTmpDir()) {
181+
$filePath = $this->getTmpDir() . '/';
182+
} else {
183+
$filePath = '';
184+
}
185+
$filePath = $this->_directory->getRelativePath($filePath . $fileName);
181186
$this->_setUploadFile($filePath);
182187
$destDir = $this->_directory->getAbsolutePath($this->getDestDir());
183188
$result = $this->save($destDir);

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/UploaderTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ protected function setUp()
4848
$mediaPath = $appParams[DirectoryList::MEDIA][DirectoryList::PATH];
4949
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
5050
$tmpDir = $this->directory->getRelativePath($mediaPath . '/import');
51-
$this->uploader->setTmpDir($tmpDir);
51+
if (!$this->directory->create($tmpDir)) {
52+
throw new \RuntimeException('Failed to create temporary directory');
53+
}
54+
if (!$this->uploader->setTmpDir($tmpDir)) {
55+
throw new \RuntimeException(
56+
'Failed to set temporary directory for files.'
57+
);
58+
}
5259

5360
parent::setUp();
5461
}
@@ -70,6 +77,7 @@ public function testMoveWithValidFile(): void
7077
* @magentoAppIsolation enabled
7178
* @return void
7279
* @expectedException \Exception
80+
* @expectedExceptionMessage Disallowed file type
7381
*/
7482
public function testMoveWithInvalidFile(): void
7583
{

lib/internal/Magento/Framework/Filesystem/Directory/Read.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function __construct(
6767
*
6868
* @return void
6969
*/
70-
protected final function validatePath(
70+
protected function validatePath(
7171
?string $path,
7272
?string $scheme = null,
7373
bool $absolutePath = false

0 commit comments

Comments
 (0)