File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -150,35 +150,41 @@ protected function externalTemplatePath(string $path): ?string
150
150
return $ resultPath ;
151
151
}
152
152
153
- private function recursiveClearDirectory (string $ dir , int $ level = 0 )
153
+ private function recursiveClearDirectory (string $ dir , int $ level = 0 , string $ baseDir = '' ): bool
154
154
{
155
155
if (!$ dir ) {
156
- return ;
156
+ return true ;
157
157
}
158
158
159
159
if ($ level === 0 && !is_dir ($ dir )) {
160
160
mkdir ($ dir , 0755 , true );
161
161
}
162
162
163
+ $ disableDeleteDir = false ;
163
164
foreach (scandir ($ dir ) as $ fileWithoutDir ) {
164
165
if (in_array ($ fileWithoutDir , ['.. ' , '. ' ])) {
165
166
continue ;
166
167
}
167
168
$ file = $ dir . "/ " . $ fileWithoutDir ;
169
+ $ pathFromBase = $ baseDir ? $ baseDir . '/ ' . $ fileWithoutDir : $ fileWithoutDir ;
170
+
171
+ if (in_array ($ pathFromBase , $ this ->filesToIgnoreDuringCleanup )) {
172
+ $ disableDeleteDir = true ;
168
173
169
- if ($ level === 0 && in_array ($ fileWithoutDir , $ this ->filesToIgnoreDuringCleanup )) {
170
174
continue ;
171
175
}
172
176
173
177
if (is_dir ($ file )) {
174
- $ this ->recursiveClearDirectory ($ file , $ level + 1 ) ;
178
+ $ disableDeleteDir = $ this ->recursiveClearDirectory ($ file , $ level + 1 , $ pathFromBase ) || $ disableDeleteDir ;
175
179
} else {
176
180
unlink ($ file );
177
181
}
178
182
}
179
183
180
- if ($ level > 0 ) {
184
+ if ($ level > 0 && ! $ disableDeleteDir ) {
181
185
rmdir ($ dir );
182
186
}
187
+
188
+ return $ disableDeleteDir ;
183
189
}
184
190
}
Original file line number Diff line number Diff line change @@ -76,7 +76,18 @@ private function patchEnums(): void
76
76
RegexIterator::MATCH
77
77
);
78
78
79
+ $ filesOrFoldersToIgnore = array_map (
80
+ fn ($ fileOfFolder ) => $ this ->outputDir . '/ ' . $ fileOfFolder ,
81
+ $ this ->filesToIgnoreDuringCleanup
82
+ );
83
+
79
84
foreach ($ files as $ file ) {
85
+ foreach ($ filesOrFoldersToIgnore as $ fileOrFolderToIgnore ) {
86
+ if (str_contains ($ file , $ fileOrFolderToIgnore )) {
87
+ continue 2 ;
88
+ }
89
+ }
90
+
80
91
try {
81
92
$ patcher = new PhpEnumPatcher ($ file );
82
93
$ patcher ->patch ();
You can’t perform that action at this time.
0 commit comments