From 4934df5291525deba1f014b3b0c92ee692733a90 Mon Sep 17 00:00:00 2001 From: zsx Date: Sat, 2 Feb 2019 14:18:17 +0800 Subject: [PATCH] scan_dir::rmdir_callback: rmdir the empty directory as default --- lib_acl_cpp/include/acl_cpp/stdlib/scan_dir.hpp | 9 +++------ lib_acl_cpp/src/stdlib/scan_dir.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib_acl_cpp/include/acl_cpp/stdlib/scan_dir.hpp b/lib_acl_cpp/include/acl_cpp/stdlib/scan_dir.hpp index be585d7f8..9275a97c8 100644 --- a/lib_acl_cpp/include/acl_cpp/stdlib/scan_dir.hpp +++ b/lib_acl_cpp/include/acl_cpp/stdlib/scan_dir.hpp @@ -23,15 +23,12 @@ public: bool open(const char* path, bool recursive = true, bool rmdir_on = false); /** - * 虚方法,当需要删除空目录时,子类可以实现此虚方法来删除传入的目录 + * 虚方法,当需要删除空目录时,子类可以实现此虚方法来删除传入的目录, + * 本虚方法内部会自动调用 rmdir 删除空目录 * @param path {const char*} 需要被删除的空目录 * @return {bool} 删除目录是否成功 */ - virtual bool rmdir_callback(const char* path) - { - (void) path; - return false; - } + virtual bool rmdir_callback(const char* path); /** * 关闭目录,同时释放内部资源 diff --git a/lib_acl_cpp/src/stdlib/scan_dir.cpp b/lib_acl_cpp/src/stdlib/scan_dir.cpp index 59731e3b6..eb6b333dc 100644 --- a/lib_acl_cpp/src/stdlib/scan_dir.cpp +++ b/lib_acl_cpp/src/stdlib/scan_dir.cpp @@ -88,6 +88,21 @@ int scan_dir::rmdir_def(ACL_SCAN_DIR*, const char* path, void* ctx) return me->rmdir_callback(path) ? 0 : -1; } +bool scan_dir::rmdir_callback(const char* path) +{ +#ifdef ACL_WINDOWS + if (_rmdir(path) == 0) { + return true; +#else + if (rmdir(path) == 0) { + return true; +#endif + } else { + logger_error("rmdir error=%s, path=%s", last_serror(), path); + return false; + } +} + const char* scan_dir::next_file(bool full /* = false */) { if (scan_ == NULL) {