@@ -286,11 +286,11 @@ public static function mkSubDirs(string $parentDir, array $subDirs, int $mode =
286286 public static function copy (string $ oldDir , string $ newDir , array $ options = []): bool
287287 {
288288 if (!is_dir ($ oldDir )) {
289- throw new FileNotFoundException ("copy error: source dir does not exist!path: $ oldDir " );
289+ throw new FileNotFoundException ("Copy error: source dir does not exist!path: $ oldDir " );
290290 }
291291
292292 self ::doCopy ($ oldDir , $ newDir , array_merge ([
293- 'skipExist ' => true ,
293+ 'skipExist ' => true , // skip exist file
294294 'filterFn ' => null ,
295295 'beforeFn ' => null ,
296296 'afterFn ' => null ,
@@ -310,7 +310,7 @@ private static function doCopy(string $oldDir, string $newDir, array $options):
310310 {
311311 self ::create ($ newDir );
312312 $ beforeFn = $ options ['beforeFn ' ];
313- $ filterFn = $ options ['filterFn ' ];
313+ $ filterFn = $ options ['filterFn ' ]; // filter file or dir.
314314
315315 // use '{,.}*' match hidden files
316316 foreach (glob ($ oldDir . '/{,.}* ' , GLOB_BRACE ) as $ old ) {
@@ -319,15 +319,14 @@ private static function doCopy(string $oldDir, string $newDir, array $options):
319319 continue ;
320320 }
321321
322- $ new = self ::joinPath ($ newDir , $ name );
323-
324- if (is_dir ($ old )) {
325- self ::doCopy ($ old , $ new , $ options );
322+ // return false to skip copy
323+ if ($ filterFn && !$ filterFn ($ old )) {
326324 continue ;
327325 }
328326
329- // return false to skip copy
330- if ($ filterFn && !$ filterFn ($ old )) {
327+ $ new = self ::joinPath ($ newDir , $ name );
328+ if (is_dir ($ old )) {
329+ self ::doCopy ($ old , $ new , $ options );
331330 continue ;
332331 }
333332
@@ -361,7 +360,6 @@ private static function doCopy(string $oldDir, string $newDir, array $options):
361360 public static function delete (string $ path , bool $ delSelf = true ): bool
362361 {
363362 $ dirPath = self ::pathFormat ($ path );
364-
365363 if (is_file ($ dirPath )) {
366364 return unlink ($ dirPath );
367365 }
0 commit comments