Skip to content

Commit 065f28e

Browse files
Corrected error message with lastSync: https://github.com/ioBroker/… (#2115)
* Corrected error message with `lastSync`: #2065 * README.md
1 parent a621dd2 commit 065f28e

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Executes Javascript, Typescript Scripts.
2626
<!--
2727
### **WORK IN PROGRESS**
2828
-->
29+
### **WORK IN PROGRESS**
30+
* (@GermanBluefox) Corrected error message with `lastSync`
31+
* (@klein0r) Corrected JavaScript filter
32+
2933
### 9.0.17 (2025-12-14)
3034
* (@GermanBluefox) Added possibility to encrypt scripts with password (only for vendors)
3135

src/lib/mirror.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class Mirror {
3333
private watchedFolder: Record<string, FSWatcher> = {};
3434
private readonly diskList: Record<string, { ts: number; source: string; name: string }>;
3535
private dbList: Record<string, ioBroker.BaseObject> = {};
36+
private ready = false;
3637

3738
constructor(options: { diskRoot: string; adapter: ioBroker.Adapter; log?: ioBroker.Logger }) {
3839
if (!options.adapter) {
@@ -64,7 +65,7 @@ export class Mirror {
6465
error: text => console.error(text),
6566
};
6667
}
67-
if (!options.diskRoot || options.adapter.namespace !== 'javascript.0') {
68+
if (!options.diskRoot?.trim() || this.adapter.namespace !== 'javascript.0') {
6869
// only instance 0 can sync objects
6970
return;
7071
}
@@ -79,17 +80,18 @@ export class Mirror {
7980
}
8081

8182
this.diskList = this.scanDisk();
82-
this.checkLastSyncObject(lastSyncTime => {
83+
this.checkLastSyncObject(lastSyncTime =>
8384
this.scanDB(list => {
8485
this.dbList = list;
8586
this.sync(lastSyncTime);
8687

8788
this.adapter.setForeignState(this.lastSyncID, Date.now(), true);
8889

90+
this.ready = true;
8991
// monitor all folders
9092
this.watchFolders(this.diskRoot);
91-
});
92-
});
93+
}),
94+
);
9395
}
9496

9597
watchFolders(root_: string): void {
@@ -170,10 +172,10 @@ export class Mirror {
170172
};
171173

172174
this.adapter.setForeignObject(this.lastSyncID, obj, () =>
173-
this.adapter.setForeignState(this.lastSyncID, 0, true, () => cb && cb(0)),
175+
this.adapter.setForeignState(this.lastSyncID, 0, true, () => cb?.(0)),
174176
);
175177
} else {
176-
void this.adapter.getForeignState(this.lastSyncID, (_err, state) => cb && cb(state?.val as number));
178+
void this.adapter.getForeignState(this.lastSyncID, (_err, state) => cb?.(state?.val as number));
177179
}
178180
});
179181
}
@@ -412,6 +414,9 @@ export class Mirror {
412414
}
413415

414416
onFileChange(event: 'change' | 'create' | 'delete' | 'rename', file: string): void {
417+
if (!this.ready) {
418+
return;
419+
}
415420
let stats: Stats | undefined;
416421
const exists = existsSync(file);
417422
if (exists) {
@@ -542,13 +547,14 @@ export class Mirror {
542547
}
543548

544549
onObjectChange(id: string, obj: ioBroker.ScriptObject | null | undefined): void {
545-
if (!this.dbList || !id) {
550+
if (!this.dbList || !id || !this.ready) {
546551
return;
547552
}
548553

549554
const file = this._scriptId2FileName(id, obj?.common?.engineType as ScriptType);
550555

551-
if (!obj || !obj.common) {
556+
if (!obj?.common) {
557+
// File was deleted
552558
if (this.dbList[id]) {
553559
delete this.dbList[id];
554560
const folderId = Mirror.getDBFolder(id);
@@ -570,6 +576,7 @@ export class Mirror {
570576
}
571577
} else if (obj.type === 'script' && id.startsWith('script.js.')) {
572578
if (this.dbList[id]) {
579+
// File changed
573580
if (this.dbList[id].common.source !== obj.common.source) {
574581
this.dbList[id] = obj;
575582
this.log.debug(`Update ${file} on disk`);
@@ -691,9 +698,7 @@ export class Mirror {
691698
}
692699
}
693700
}
694-
if (cb) {
695-
cb(list);
696-
}
701+
cb?.(list);
697702
},
698703
);
699704
},

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ class JavaScript extends Adapter {
14571457
}
14581458
}
14591459

1460-
if (this.config.mirrorPath) {
1460+
if (this.config.mirrorPath?.trim()) {
14611461
this.config.mirrorInstance = parseInt(this.config.mirrorInstance as unknown as string, 10) || 0;
14621462
if (this.instance === this.config.mirrorInstance) {
14631463
const ioBDataDir = getAbsoluteDefaultDataDir() + sep;

0 commit comments

Comments
 (0)