Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Has been running now for a while without showing crashes on object / deletion, whether from in-game destroy() or from the exterior (e.g. manual file removal). We get a warning log in both cases.
  • Loading branch information
Omikhleia committed Sep 4, 2016
1 parent 92c02de commit f0783f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 13 additions & 2 deletions src/lib/fs-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ class FsDb {
this.watcher
.on('add', this.onFileAdded.bind(this))
.on('change', this.onFileChanged.bind(this))
.on('unlink', this.onFileRemoved.bind(this));
.on('unlink', this.onFileRemoved.bind(this))
.on('error', (error) => {
// On Windows notabbly, when a file is deleted from an extern process, an EPERM status may occur here, due to a temporary system file lock. Attempt at gracefully ignore the error, to avoid an uncaught exception.
this.logger.warn({ error }, 'file watcher error caught');
});
this.emit('ready');
});
}
Expand Down Expand Up @@ -187,7 +191,14 @@ class FsDb {

rmDir(relpath) {
const filepath = this.toFilepath(relpath);
fs.rmdirSync(filepath);
try {
fs.rmdirSync(filepath);
} catch (error) {
// At least two observed cases here:
// - ENOTEMPTY
// - ENOENT
this.logger.warn({ relpath, error }, 'file directory deletion failed');
}
}

// input expected to be a path to a directory only
Expand Down
8 changes: 1 addition & 7 deletions src/lib/moo-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,7 @@ class MooDB {
}
}
this.fsdb.rm(this.filenameForObj(id));
try {
this.fsdb.rmDir(this.filepathToObj(id)); // cleanup; FsDb should do this for us, but it doesn't.
} catch (err) {
// DO NOTHING
// This is acceptable, since we allow objects to be organized in directories.
// HOWEVER, an empty directory might remain, if underlying objects are later destroyed.
}
this.fsdb.rmDir(this.filepathToObj(id)); // cleanup; FsDb should do this for us, but it doesn't.
}

markObjectDirty(id) {
Expand Down

0 comments on commit f0783f5

Please sign in to comment.