@@ -326,11 +326,15 @@ class Mirror {
326
326
file = file . endsWith ( '/' ) ? file : file + '/' ;
327
327
if ( exists ) {
328
328
! this . watchedFolder [ file ] && this . watchFolders ( file ) ;
329
- // scan folder anew
330
- const files = fs . readdirSync ( file ) . filter ( name => ! name . startsWith ( '.' ) ) ;
329
+ try {
330
+ // scan folder anew
331
+ const files = fs . readdirSync ( file ) . filter ( name => ! name . startsWith ( '.' ) ) ;
331
332
332
- // update all files in this directory
333
- files . forEach ( f => this . onFileChange ( 'change' , path . join ( file , f ) . replace ( / \\ / g, '/' ) ) ) ;
333
+ // update all files in this directory
334
+ files . forEach ( f => this . onFileChange ( 'change' , path . join ( file , f ) . replace ( / \\ / g, '/' ) ) ) ;
335
+ } catch ( err ) {
336
+ this . log . error ( 'Error while checking files in directory ' + file + ': ' + err ) ;
337
+ }
334
338
} else {
335
339
if ( this . watchedFolder [ file ] ) {
336
340
this . watchedFolder [ file ] . close ( ) ;
@@ -493,18 +497,26 @@ class Mirror {
493
497
scanDisk ( dirPath , list ) {
494
498
dirPath = dirPath || this . diskRoot ;
495
499
list = list || { } ;
496
- if ( fs . existsSync ( dirPath ) ) {
497
- const files = fs . readdirSync ( dirPath ) . filter ( name => ! name . startsWith ( '.' ) ) ;
498
- files . forEach ( file => {
499
- const fullName = path . join ( dirPath , file ) ;
500
- const stats = fs . statSync ( fullName ) ;
501
- if ( stats . isDirectory ( ) ) {
502
- this . scanDisk ( fullName . replace ( / \\ / g, '/' ) , list ) ;
503
- } else if ( file . match ( / \. j s $ | \. t s $ / ) ) {
504
- let f = this . _fileName2scriptId ( fullName ) ;
505
- list [ f ] = { ts : Math . round ( stats . mtime ) , source : fs . readFileSync ( fullName ) . toString ( ) , name : fullName } ;
506
- }
507
- } ) ;
500
+ try {
501
+ if ( fs . existsSync ( dirPath ) ) {
502
+ const files = fs . readdirSync ( dirPath ) . filter ( name => ! name . startsWith ( '.' ) ) ;
503
+ files . forEach ( file => {
504
+ const fullName = path . join ( dirPath , file ) ;
505
+ const stats = fs . statSync ( fullName ) ;
506
+ if ( stats . isDirectory ( ) ) {
507
+ this . scanDisk ( fullName . replace ( / \\ / g, '/' ) , list ) ;
508
+ } else if ( file . match ( / \. j s $ | \. t s $ / ) ) {
509
+ let f = this . _fileName2scriptId ( fullName ) ;
510
+ list [ f ] = {
511
+ ts : Math . round ( stats . mtime ) ,
512
+ source : fs . readFileSync ( fullName ) . toString ( ) ,
513
+ name : fullName
514
+ } ;
515
+ }
516
+ } ) ;
517
+ }
518
+ } catch ( err ) {
519
+ this . log . error ( 'Error while checking files in directory ' + dirPath + ': ' + err ) ;
508
520
}
509
521
return list ;
510
522
}
0 commit comments