From 2f417ee12f25aa5e1121cbc666111b90ed1d1054 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 6 Apr 2018 22:48:55 +1000 Subject: 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 --- src/loslib.js | 14 +++++++++----- 1 file 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); }; -- cgit v1.2.3-70-g09d2