Skip to content

Commit b6a552d

Browse files
authored
fix(unlink): deleting symlinks should not delete file contents (#30)
1 parent b6ac6b7 commit b6a552d

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/PromisifiedFS.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,11 @@ module.exports = class PromisifiedFS {
172172
}
173173
async unlink(filepath, opts) {
174174
;[filepath, opts] = cleanParams(filepath, opts);
175-
const stat = this._cache.stat(filepath);
175+
const stat = this._cache.lstat(filepath);
176176
this._cache.unlink(filepath);
177-
await this._idb.unlink(stat.ino)
177+
if (stat.type !== 'symlink') {
178+
await this._idb.unlink(stat.ino)
179+
}
178180
return null
179181
}
180182
async readdir(filepath, opts) {

src/__tests__/fs.promises.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,10 @@ describe("fs.promises module", () => {
346346
fs.readdir("/symlink/del").then(data => {
347347
expect(data.includes("file.txt")).toBe(true)
348348
expect(data.includes("file2.txt")).toBe(false)
349-
done();
349+
fs.readFile("/symlink/del/file.txt", "utf8").then(data => {
350+
expect(data).toBe("data")
351+
done();
352+
})
350353
});
351354
});
352355
});

src/__tests__/fs.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,11 @@ describe("fs module", () => {
377377
expect(err).toBe(null)
378378
expect(data.includes("file.txt")).toBe(true)
379379
expect(data.includes("file2.txt")).toBe(false)
380-
done();
380+
fs.readFile("/symlink/del/file.txt", "utf8", (err, data) => {
381+
expect(err).toBe(null)
382+
expect(data).toBe("data")
383+
done();
384+
})
381385
});
382386
});
383387
});

0 commit comments

Comments
 (0)