7
7
8
8
use Magento \Framework \App \Bootstrap ;
9
9
use Magento \Framework \App \Filesystem \DirectoryList ;
10
- use Magento \Framework \Filesystem \DriverInterface ;
10
+ use Magento \Framework \Filesystem \Directory \ WriteFactory ;
11
11
use Magento \Framework \Filesystem \DriverPool ;
12
- use Magento \Framework \Filesystem \File \WriteFactory ;
13
- use Magento \Framework \Filesystem \Directory \Write ;
14
12
use Zend \ServiceManager \ServiceManager ;
15
13
use Magento \Setup \Mvc \Bootstrap \InitParamListener ;
16
14
@@ -34,7 +32,7 @@ public function __construct(
34
32
}
35
33
36
34
/**
37
- * Check generated/code read and write access
35
+ * Check write permissions to generation folders
38
36
*
39
37
* @return bool
40
38
*/
@@ -47,8 +45,6 @@ public function check()
47
45
$ directoryList = new DirectoryList (BP , $ filesystemDirPaths );
48
46
$ driverPool = new DriverPool ();
49
47
$ fileWriteFactory = new WriteFactory ($ driverPool );
50
- /** @var \Magento\Framework\Filesystem\DriverInterface $driver */
51
- $ driver = $ driverPool ->getDriver (DriverPool::FILE );
52
48
53
49
$ generationDirs = [
54
50
DirectoryList::GENERATED ,
@@ -58,50 +54,21 @@ public function check()
58
54
59
55
foreach ($ generationDirs as $ generationDirectory ) {
60
56
$ directoryPath = $ directoryList ->getPath ($ generationDirectory );
57
+ $ directoryWrite = $ fileWriteFactory ->create ($ directoryPath );
61
58
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
+ }
64
65
}
65
- }
66
-
67
- return true ;
68
- }
69
66
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 ()) {
89
68
return false ;
90
69
}
91
70
}
92
71
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
-
105
72
return true ;
106
73
}
107
74
}
0 commit comments