From 089a67c53f14939c47b6d30989dbd64a47e6041d Mon Sep 17 00:00:00 2001 From: Brecht Sanders Date: Thu, 19 Aug 2021 15:05:09 +0200 Subject: [PATCH] --- Changelog.txt | 10 ++++++++++ include/dirtrav_version.h | 2 +- src/dirtrav.c | 31 ++++++++++++++++--------------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 09c98fc..da89d76 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,5 +1,15 @@ +0.2.12 + +2021-08-19 Brecht Sanders https://github.com/brechtsanders/ + + * fix dirtrav_recursive_delete() and dirtravw_recursive_delete() to delete as much as possible on failure + 0.2.11 +2021-08-18 Brecht Sanders https://github.com/brechtsanders/ + + * fix build for non-Windows operating systems + 0.2.10 2021-08-18 Brecht Sanders https://github.com/brechtsanders/ diff --git a/include/dirtrav_version.h b/include/dirtrav_version.h index 311db60..816d919 100644 --- a/include/dirtrav_version.h +++ b/include/dirtrav_version.h @@ -47,7 +47,7 @@ THE SOFTWARE. /*! \brief minor version number */ #define DIRTRAV_VERSION_MINOR 2 /*! \brief micro version number */ -#define DIRTRAV_VERSION_MICRO 11 +#define DIRTRAV_VERSION_MICRO 12 /*! @} */ /*! \cond PRIVATE */ diff --git a/src/dirtrav.c b/src/dirtrav.c index 1495d5c..62f09b7 100644 --- a/src/dirtrav.c +++ b/src/dirtrav.c @@ -480,39 +480,40 @@ DLL_EXPORT_DIRTRAV int DIRTRAVFN(traverse_path_parts) (const DIRCHAR* startpath, int DIRTRAVFN(recursive_delete_file_callback) (DIRTRAVFN(entry) info) { #ifdef _WIN32 - if (DIRWINFN(DeleteFile)(info->fullpath)) + if (!DIRWINFN(DeleteFile)(info->fullpath)) #else - if (unlink(info->fullpath) == 0) + if (unlink(info->fullpath) != 0) #endif - return 0; - return 1; + *((int*)info->callbackdata) |= 1; + return 0; } int DIRTRAVFN(recursive_delete_folder_callback) (DIRTRAVFN(entry) info) { #ifdef _WIN32 - if (DIRWINFN(RemoveDirectory)(info->fullpath)) + if (!DIRWINFN(RemoveDirectory)(info->fullpath)) #else - if (rmdir(info->fullpath) == 0) + if (rmdir(info->fullpath) != 0) #endif - return 0; - return 2; + *((int*)info->callbackdata) |= 2; + return 0; } int DIRTRAVFN(recursive_delete) (const DIRCHAR* path) { - int result; + int status = 0; if (!path || !*path) return -2; - if ((result = DIRTRAVFN(traverse_directory)(path, DIRTRAVFN(recursive_delete_file_callback), NULL, DIRTRAVFN(recursive_delete_folder_callback), NULL)) == 0) { + DIRTRAVFN(traverse_directory)(path, DIRTRAVFN(recursive_delete_file_callback), NULL, DIRTRAVFN(recursive_delete_folder_callback), (void*)&status); + if (status != 0) + return status; #ifdef _WIN32 - if (!DIRWINFN(RemoveDirectory)(path)) + if (!DIRWINFN(RemoveDirectory)(path)) #else - if (rmdir(path) != 0) + if (rmdir(path) != 0) #endif - return -1; - } - return result; + return (2 | 4); + return 0; } int DIRTRAVFN(make_full_path_callback) (DIRTRAVFN(entry) info)