summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
};