aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-04-06 22:48:55 +1000
committerdaurnimator <quae@daurnimator.com>2018-04-06 22:48:55 +1000
commit2f417ee12f25aa5e1121cbc666111b90ed1d1054 (patch)
tree227eeb4be16099518f6ab6aa6f1ca4df0cd24ba9 /src
parent3fdb709d2c65659180150bc4253945fd0ac5fbad (diff)
downloadfengari-2f417ee12f25aa5e1121cbc666111b90ed1d1054.tar.gz
fengari-2f417ee12f25aa5e1121cbc666111b90ed1d1054.tar.bz2
fengari-2f417ee12f25aa5e1121cbc666111b90ed1d1054.zip
src/loslib.js: In os.remove, try unlink and on EISDIR try rmdir
This is what glibc does, it's better than trying to stat beforehand
Diffstat (limited to 'src')
-rw-r--r--src/loslib.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/loslib.js b/src/loslib.js
index 6fec903..6c6b2f4 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -251,13 +251,17 @@ if (typeof process === "undefined") {
syslib.remove = function(L) {
let filename = luaL_checkstring(L, 1);
try {
- if (fs.lstatSync(filename).isDirectory()) {
- fs.rmdirSync(filename);
+ fs.unlinkSync(filename);
+ } catch (e) {
+ if (e.code === 'EISDIR') {
+ try {
+ fs.rmdirSync(filename);
+ } catch (e) {
+ return luaL_fileresult(L, false, filename, e);
+ }
} else {
- fs.unlinkSync(filename);
+ return luaL_fileresult(L, false, filename, e);
}
- } catch (e) {
- return luaL_fileresult(L, false, filename, e);
}
return luaL_fileresult(L, true);
};