Skip to content

Commit

Permalink
Add a safety check for file existence
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Shirokov committed Mar 10, 2020
1 parent 3b29edd commit 3a97088
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs';
import util from 'util';

export default {
existsSync: fs.existsSync,
readFile: util.promisify(fs.readFile),
readFileSync: fs.readFileSync,
watch: fs.watch,
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const open = async <T>(
};

fs.watch(filepath, watcherOptions, async () => {
if (!fs.existsSync(filepath)) {
return;
}
const updateDatabase = await fs.readFile(filepath);
reader.load(updateDatabase, opts);
if (opts.watchForUpdatesHook) {
Expand Down

0 comments on commit 3a97088

Please sign in to comment.