Skip to content

Commit 743fce0

Browse files
MAGETWO-68928: Fatal error after disabling module
1 parent 5fb3c26 commit 743fce0

File tree

2 files changed

+14
-47
lines changed

2 files changed

+14
-47
lines changed

lib/internal/Magento/Framework/Console/GenerationDirectoryAccess.php

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
use Magento\Framework\App\Bootstrap;
99
use Magento\Framework\App\Filesystem\DirectoryList;
10-
use Magento\Framework\Filesystem\DriverInterface;
10+
use Magento\Framework\Filesystem\Directory\WriteFactory;
1111
use Magento\Framework\Filesystem\DriverPool;
12-
use Magento\Framework\Filesystem\File\WriteFactory;
13-
use Magento\Framework\Filesystem\Directory\Write;
1412
use Zend\ServiceManager\ServiceManager;
1513
use Magento\Setup\Mvc\Bootstrap\InitParamListener;
1614

@@ -34,7 +32,7 @@ public function __construct(
3432
}
3533

3634
/**
37-
* Check generated/code read and write access
35+
* Check write permissions to generation folders
3836
*
3937
* @return bool
4038
*/
@@ -47,8 +45,6 @@ public function check()
4745
$directoryList = new DirectoryList(BP, $filesystemDirPaths);
4846
$driverPool = new DriverPool();
4947
$fileWriteFactory = new WriteFactory($driverPool);
50-
/** @var \Magento\Framework\Filesystem\DriverInterface $driver */
51-
$driver = $driverPool->getDriver(DriverPool::FILE);
5248

5349
$generationDirs = [
5450
DirectoryList::GENERATED,
@@ -58,50 +54,21 @@ public function check()
5854

5955
foreach ($generationDirs as $generationDirectory) {
6056
$directoryPath = $directoryList->getPath($generationDirectory);
57+
$directoryWrite = $fileWriteFactory->create($directoryPath);
6158

62-
if (!$this->checkDirectory($fileWriteFactory, $driver, $directoryPath)) {
63-
return false;
59+
if (!$directoryWrite->isExist()) {
60+
try {
61+
$directoryWrite->create();
62+
} catch (\Exception $e) {
63+
return false;
64+
}
6465
}
65-
}
66-
67-
return true;
68-
}
6966

70-
/**
71-
* Checks the permissions to specific directory
72-
*
73-
* @param WriteFactory $fileWriteFactory The factory of file writers
74-
* @param DriverInterface $driver The driver
75-
* @param string $directoryPath The directory path
76-
* @return bool
77-
*/
78-
private function checkDirectory(
79-
WriteFactory $fileWriteFactory,
80-
DriverInterface $driver,
81-
$directoryPath
82-
) {
83-
$directoryWrite = new Write($fileWriteFactory, $driver, $directoryPath);
84-
85-
if (!$directoryWrite->isExist()) {
86-
try {
87-
$directoryWrite->create();
88-
} catch (\Exception $e) {
67+
if (!$directoryWrite->isWritable()) {
8968
return false;
9069
}
9170
}
9271

93-
if (!$directoryWrite->isDirectory() || !$directoryWrite->isReadable()) {
94-
return false;
95-
}
96-
97-
try {
98-
$probeFilePath = $directoryPath . DIRECTORY_SEPARATOR . uniqid(mt_rand()) . 'tmp';
99-
$fileWriteFactory->create($probeFilePath, DriverPool::FILE, 'w');
100-
$driver->deleteFile($probeFilePath);
101-
} catch (\Exception $e) {
102-
return false;
103-
}
104-
10572
return true;
10673
}
10774
}

setup/src/Magento/Setup/Console/CompilerPreparation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public function handleCompilerEnvironment()
7272
return;
7373
}
7474

75+
if (!$this->getGenerationDirectoryAccess()->check()) {
76+
throw new GenerationDirectoryAccessException();
77+
}
78+
7579
$mageInitParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM);
7680
$mageDirs = isset($mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS])
7781
? $mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]
@@ -82,10 +86,6 @@ public function handleCompilerEnvironment()
8286
$directoryList->getPath(DirectoryList::GENERATED_METADATA),
8387
];
8488

85-
if (!$this->getGenerationDirectoryAccess()->check()) {
86-
throw new GenerationDirectoryAccessException();
87-
}
88-
8989
foreach ($compileDirList as $compileDir) {
9090
if ($this->filesystemDriver->isExists($compileDir)) {
9191
$this->filesystemDriver->deleteDirectory($compileDir);

0 commit comments

Comments
 (0)