Skip to content

Commit fbb024f

Browse files
committed
bugfix + prevent unnecessary saving on startup
1 parent 48a70e2 commit fbb024f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/sys/backup/SysBackupService.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ protected void declareDefaults() {
4747

4848
@Override
4949
protected void onStable() {
50-
DSRuntime.run(this);
50+
File nodes = getLink().getConfig().getNodesFile();
51+
if (nodes.exists()) {
52+
synchronized (lock) {
53+
scheduleNextSave();
54+
}
55+
} else {
56+
DSRuntime.run(this);
57+
}
5158
}
5259

5360
private DSLink getLink() {
@@ -140,7 +147,7 @@ public void save() {
140147
} else {
141148
writer = new JsonWriter(nodes);
142149
}
143-
NodeEncoder.encode(writer, this);
150+
NodeEncoder.encode(writer, getLink());
144151
writer.close();
145152
trimBackups();
146153
time = System.currentTimeMillis() - time;
@@ -206,14 +213,18 @@ public boolean accept(File dir, String name) {
206213
backups[i].delete();
207214
}
208215
}
216+
217+
private void scheduleNextSave() {
218+
long saveInterval = interval.getElement().toLong();
219+
saveInterval *= 60000;
220+
nextSave = DSRuntime.runDelayed(this, saveInterval);
221+
}
209222

210223
@Override
211224
public void run() {
212225
synchronized(lock) {
213226
save();
214-
long saveInterval = interval.getElement().toLong();
215-
saveInterval *= 60000;
216-
nextSave = DSRuntime.runDelayed(this, saveInterval);
227+
scheduleNextSave();
217228
}
218229
}
219230

0 commit comments

Comments
 (0)