From 7c35d2d56a2afe9d172b704ee670841b2cb6a1b6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 2 Nov 2019 21:11:29 +1100 Subject: [PATCH] AP_Filesystem: make unlink do both directories and files on posix match FATFS behaviour --- libraries/AP_Filesystem/AP_Filesystem_posix.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/AP_Filesystem/AP_Filesystem_posix.cpp b/libraries/AP_Filesystem/AP_Filesystem_posix.cpp index 10e64cd232..6c7b4cca05 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_posix.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_posix.cpp @@ -67,7 +67,13 @@ int AP_Filesystem::stat(const char *pathname, struct stat *stbuf) int AP_Filesystem::unlink(const char *pathname) { - return ::unlink(pathname); + // we match the FATFS interface and use unlink + // for both files and directories + int ret = ::rmdir(pathname); + if (ret == -1) { + ret = ::unlink(pathname); + } + return ret; } int AP_Filesystem::mkdir(const char *pathname)