Skip to content

Commit 5bc4042

Browse files
committed
MAGETWO-95629: Filesystem Directory Improvement
1 parent 2497ed6 commit 5bc4042

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,25 @@ public function move($fileName, $renameFileOff = false)
172172
$read = $this->_readFactory->create($url, DriverPool::HTTPS);
173173
}
174174

175+
if ($this->getTmpDir()) {
176+
$filePath = $this->getTmpDir() . '/';
177+
} else {
178+
$filePath = '';
179+
}
175180
$fileName = preg_replace('/[^a-z0-9\._-]+/i', '', $fileName);
181+
$filePath = $this->_directory->getRelativePath($filePath . $fileName);
176182
$this->_directory->writeFile(
177-
$this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName),
183+
$filePath,
178184
$read->readAll()
179185
);
180186
}
181187

182-
$filePath = $this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName);
188+
if ($this->getTmpDir()) {
189+
$filePath = $this->getTmpDir() . '/';
190+
} else {
191+
$filePath = '';
192+
}
193+
$filePath = $this->_directory->getRelativePath($filePath . $fileName);
183194
$this->_setUploadFile($filePath);
184195
$destDir = $this->_directory->getAbsolutePath($this->getDestDir());
185196
$result = $this->save($destDir);

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected function setUp()
119119
public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName)
120120
{
121121
$destDir = 'var/dest/dir';
122-
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $expectedFileName;
122+
$expectedRelativeFilePath = $expectedFileName;
123123
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
124124
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);
125125
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)
@@ -155,7 +155,7 @@ public function testMoveFileName()
155155
{
156156
$destDir = 'var/dest/dir';
157157
$fileName = 'test_uploader_file';
158-
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $fileName;
158+
$expectedRelativeFilePath = $fileName;
159159
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
160160
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);
161161
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)

app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Delete.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public function execute()
5353
$sitemap->load($id);
5454
// delete file
5555
$sitemapPath = $sitemap->getSitemapPath();
56+
if ($sitemapPath && $sitemapPath[0] === DIRECTORY_SEPARATOR) {
57+
$sitemapPath = mb_substr($sitemapPath, 1);
58+
}
5659
$sitemapFilename = $sitemap->getSitemapFilename();
5760

5861
$path = $directory->getRelativePath($sitemapPath . $sitemapFilename);

app/code/Magento/Sitemap/Test/Unit/Controller/Adminhtml/Sitemap/DeleteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function testExecute()
135135
$this->sitemapFactoryMock->expects($this->once())->method('create')->willReturn($sitemapMock);
136136
$writeDirectoryMock->expects($this->any())
137137
->method('getRelativePath')
138-
->with($sitemapPath . $sitemapFilename)
138+
->with($sitemapFilename)
139139
->willReturn($relativePath);
140140
$writeDirectoryMock->expects($this->once())->method('isFile')->with($relativePath)->willReturn(true);
141141
$writeDirectoryMock->expects($this->once())->method('delete')->with($relativePath)->willReturn(true);

0 commit comments

Comments
 (0)