From 7b8c7632e9069089d9d88dddf8c0d13e6a023b7a Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Tue, 26 Dec 2023 17:47:07 +1300 Subject: [PATCH] fix up fs --- lfs.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lfs.c b/lfs.c index 4625204..1a9c664 100644 --- a/lfs.c +++ b/lfs.c @@ -384,8 +384,17 @@ recursiveremove(lua_State *L, const char *path) char *fullname; size_t len, nlen, plen; - if ((d = opendir(path)) == NULL) - return lfail(L); + if ((d = opendir(path)) == NULL) { + if (errno != ENOTDIR) + return lfail(L); + + /* if it's a file... */ + if (remove(path) == -1) + return lfail(L); + + lua_pushboolean(L, 1); + return 1; + } while ((ent = readdir(d)) != NULL) { if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) @@ -402,7 +411,6 @@ recursiveremove(lua_State *L, const char *path) fullname[plen + 1] = 0; strlcat(fullname, ent->d_name, len); - printf("fullname: %s\n", fullname); if (ent->d_type == DT_DIR) { /* if rmdir succeeded, free fullname and * proceed with next entry */ @@ -456,7 +464,7 @@ fs_remove(lua_State *L) * On success, returns true. Otherwise returns nil, an error * message and a platform-dependent error code. * - * @function mkdir + * @function rmdir * @usage fs.rmdir("yourdirectory") * @tparam string dir The path of the directory to remove. */