Skip to content

Commit cd1771d

Browse files
committed
* (Apollon77) catched some more file errors in mirror logic (Sentry IOBROKER-JAVASCRIPT-2X, IOBROKER-JAVASCRIPT-3C)
1 parent f9054b9 commit cd1771d

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,19 @@ And then call "npm run build".
3636

3737
## Changelog
3838

39+
### __WORK IN PROGRESS__
40+
* (Apollon77) catched some more file errors in mirror logic (Sentry IOBROKER-JAVASCRIPT-2X, IOBROKER-JAVASCRIPT-3C)
41+
3942
### 4.6.20 (2020-07-26)
40-
* (Apollon77) make sure userdata objects/states are not overwritten on createState
43+
* (Apollon77) make sure 0_userdata.0 objects/states are not overwritten on createState
4144

4245
### 4.6.19 (2020-07-26)
4346
* (Apollon77) Prevent wrong errors when setting "null" values for states
4447
* (Apollon77) Prevent potential crash when no typings could be found (Sentry IOBROKER-JAVASCRIPT-2T)
4548
* (Apollon77) catch an error in mirroring functionality( Sentry IOBROKER-JAVASCRIPT-2V)
4649
* (Apollon77) make sure names are handled correctly if they are not strings (Sentry IOBROKER-JAVASCRIPT-2Y)
4750
* (Apollon77) make sure invalid schedules can not crash adapter (Sentry IOBROKER-JAVASCRIPT-31)
48-
* (Apollon77/paul53) Allow "deleteState" with full javascript.X object I dagain (from same instance only)
51+
* (Apollon77/paul53) Allow "deleteState" with full javascript.X object Id again (from same instance only)
4952
* (bluefox) Revert changes for sync getState, because "on change" detection is broken
5053
* (AlCalzone) Several issues with Typescript, Typings and virtual-tsc optimized and fixed
5154
* (bluefox) Store JS in browser cache by enabling serviceWorkers

lib/mirror.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,15 @@ class Mirror {
326326
file = file.endsWith('/') ? file : file + '/';
327327
if (exists) {
328328
!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('.'));
331332

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+
}
334338
} else {
335339
if (this.watchedFolder[file]) {
336340
this.watchedFolder[file].close();
@@ -493,18 +497,26 @@ class Mirror {
493497
scanDisk(dirPath, list) {
494498
dirPath = dirPath || this.diskRoot;
495499
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(/\.js$|\.ts$/)) {
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(/\.js$|\.ts$/)) {
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);
508520
}
509521
return list;
510522
}

0 commit comments

Comments
 (0)