Skip to content

Commit c66edba

Browse files
committed
fix: bind methods to fs instance
1 parent 7a8c8f6 commit c66edba

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CacheFS.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module.exports = class CacheFS {
8282
let dir = this._root;
8383
for (let part of path.split(filepath)) {
8484
dir = dir.get(part);
85-
if (!dir) throw new ENOENT();
85+
if (!dir) throw new ENOENT(filepath);
8686
}
8787
return dir;
8888
}

src/Stat.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ module.exports = class Stat {
2727
isDirectory() {
2828
return this.type === "dir";
2929
}
30+
isSymbolicLink() {
31+
return this.type === "symlink";
32+
}
3033
};

src/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module.exports = class FS {
1515
this._backend = new IdbBackend(name);
1616
this._cache = new CacheFS(name);
1717
this.saveSuperblock = debounce(() => {
18-
console.log("saving superblock");
1918
this._saveSuperblock();
2019
}, 500);
2120
if (url) {
@@ -26,6 +25,15 @@ module.exports = class FS {
2625
} else {
2726
this.superblockPromise = this._loadSuperblock();
2827
}
28+
// Needed so things don't break if you pass individual functions to `pify` etc
29+
this.readFile = this.readFile.bind(this)
30+
this.writeFile = this.writeFile.bind(this)
31+
this.unlink = this.unlink.bind(this)
32+
this.mkdir = this.mkdir.bind(this)
33+
this.rmdir = this.rmdir.bind(this)
34+
this.readdir = this.readdir.bind(this)
35+
this.stat = this.stat.bind(this)
36+
this.lstat = this.lstat.bind(this)
2937
}
3038
_cleanParams(filepath, opts, cb, stopClock = null, save = false) {
3139
filepath = path.normalize(filepath);
@@ -104,9 +112,7 @@ module.exports = class FS {
104112
cb(null, data);
105113
})
106114
.catch(err => {
107-
console.log("filepath", filepath);
108-
console.log(err);
109-
console.log("readFile: stat data out of sync with db");
115+
console.log("ERROR: readFile: stat data out of sync with db:", filepath);
110116
});
111117
})
112118
.catch(cb);
@@ -127,10 +133,7 @@ module.exports = class FS {
127133
try {
128134
this._cache.writeFile(filepath, data, { mode });
129135
} catch (err) {
130-
console.log("filepath", filepath);
131-
console.log(err);
132-
console.log("writeFile: cache corrupted - unable to keep cache in sync with db");
133-
return cb(new ENOENT());
136+
return cb(err);
134137
}
135138
this._backend.writeFile(filepath, data)
136139
.then(() => cb(null))

0 commit comments

Comments
 (0)