@@ -175,6 +175,7 @@ public function createSymlink($path, $destination, WriteInterface $targetDirecto
175
175
*/
176
176
public function delete ($ path = null )
177
177
{
178
+ $ exceptionMessages = [];
178
179
$ this ->validatePath ($ path );
179
180
if (!$ this ->isExist ($ path )) {
180
181
return true ;
@@ -183,11 +184,54 @@ public function delete($path = null)
183
184
if ($ this ->driver ->isFile ($ absolutePath )) {
184
185
$ this ->driver ->deleteFile ($ absolutePath );
185
186
} else {
186
- $ this ->driver ->deleteDirectory ($ absolutePath );
187
+ try {
188
+ $ this ->deleteFilesRecursively ($ absolutePath );
189
+ $ this ->driver ->deleteDirectory ($ absolutePath );
190
+ } catch (FileSystemException $ e ) {
191
+ $ exceptionMessages [] = $ e ->getMessage ();
192
+ }
193
+ }
194
+ if (!empty ($ exceptionMessages )) {
195
+ throw new FileSystemException (
196
+ new \Magento \Framework \Phrase (
197
+ \implode (' ' , $ exceptionMessages )
198
+ )
199
+ );
187
200
}
188
201
return true ;
189
202
}
190
203
204
+ /**
205
+ * Delete files recursively
206
+ *
207
+ * Implemented in order to delete as much files as possible and collect all exceptions
208
+ *
209
+ * @param string $path
210
+ * @return void
211
+ * @throws FileSystemException
212
+ */
213
+ private function deleteFilesRecursively (string $ path )
214
+ {
215
+ $ exceptionMessages = [];
216
+ $ entitiesList = $ this ->driver ->readDirectoryRecursively ($ path );
217
+ foreach ($ entitiesList as $ entityPath ) {
218
+ if (!$ this ->driver ->isDirectory ($ entityPath )) {
219
+ try {
220
+ $ this ->driver ->deleteFile ($ entityPath );
221
+ } catch (FileSystemException $ e ) {
222
+ $ exceptionMessages [] = $ e ->getMessage ();
223
+ }
224
+ }
225
+ }
226
+ if (!empty ($ exceptionMessages )) {
227
+ throw new FileSystemException (
228
+ new \Magento \Framework \Phrase (
229
+ \implode (' ' , $ exceptionMessages )
230
+ )
231
+ );
232
+ }
233
+ }
234
+
191
235
/**
192
236
* Change permissions of given path
193
237
*
0 commit comments