@@ -308,19 +308,12 @@ public function remove($source, $dest)
308
308
309
309
// If source doesn't exist, check if it's a glob expression, otherwise we have nothing we can do
310
310
if (!file_exists ($ sourcePath )) {
311
- // Handle globing
312
- $ matches = glob ($ sourcePath );
313
- if ($ matches ) {
314
- foreach ($ matches as $ match ) {
315
- $ newDest = substr ($ destPath . '/ ' . basename ($ match ), strlen ($ this ->getDestDir ()));
316
- $ newDest = ltrim ($ newDest , ' \\/ ' );
317
- $ this ->remove (substr ($ match , strlen ($ this ->getSourceDir ())+1 ), $ newDest );
318
- }
319
- return ;
320
- }
321
-
322
- // Source file isn't a valid file or glob
323
- throw new \ErrorException ("Source $ sourcePath does not exist " );
311
+ $ this ->removeContentOfCategory ($ sourcePath , $ destPath );
312
+ return ;
313
+ } elseif (file_exists ($ sourcePath ) && is_dir ($ sourcePath )) {
314
+ $ this ->removeContentOfCategory ($ sourcePath . '/* ' , $ destPath );
315
+ @rmdir ($ destPath );
316
+ return ;
324
317
}
325
318
326
319
// MP Avoid removing whole folders in case the modman file is not 100% well-written
@@ -331,6 +324,33 @@ public function remove($source, $dest)
331
324
self ::rmdirRecursive ($ destPath );
332
325
}
333
326
327
+ /**
328
+ * Search and remove content of category
329
+ *
330
+ * @param string $sourcePath
331
+ * @param string $destPath
332
+ * @throws \ErrorException
333
+ */
334
+ protected function removeContentOfCategory ($ sourcePath , $ destPath )
335
+ {
336
+ $ sourcePath = preg_replace ('#/\*$# ' , '/{,.}* ' , $ sourcePath );
337
+ $ matches = glob ($ sourcePath , GLOB_BRACE );
338
+ if ($ matches ) {
339
+ foreach ($ matches as $ match ) {
340
+ if (preg_match ("#/\.{1,2}$# " , $ match )) {
341
+ continue ;
342
+ }
343
+ $ newDest = substr ($ destPath . '/ ' . basename ($ match ), strlen ($ this ->getDestDir ()));
344
+ $ newDest = ltrim ($ newDest , ' \\/ ' );
345
+ $ this ->remove (substr ($ match , strlen ($ this ->getSourceDir ())+1 ), $ newDest );
346
+ }
347
+ return ;
348
+ }
349
+
350
+ // Source file isn't a valid file or glob
351
+ throw new \ErrorException ("Source $ sourcePath does not exist " );
352
+ }
353
+
334
354
/**
335
355
* Remove an empty directory branch up to $stopDir, or stop at the first non-empty parent.
336
356
*
0 commit comments