From e344d379d274f91850e8ca7c0f450a82b3c04c86 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 27 Sep 2015 12:44:54 +0200 Subject: [PATCH] update semantics of PBD::remove_directory() Remove the directory recursively including itself. The function is used in two places only: * LV2Plugin::add_state() -- no change, remove tmp. state * Session::save_as() -- on error, remove target In both cases removing the folder itself is correct. --- libs/pbd/file_utils.cc | 1 + libs/pbd/pbd/file_utils.h | 4 ++-- libs/pbd/test/filesystem_test.cc | 9 +-------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc index 950880c0bf..3cd0689f4b 100644 --- a/libs/pbd/file_utils.cc +++ b/libs/pbd/file_utils.cc @@ -476,6 +476,7 @@ void remove_directory (const std::string& dir) { remove_directory_internal (dir, 0, 0, false); + g_rmdir (dir.c_str()); } string diff --git a/libs/pbd/pbd/file_utils.h b/libs/pbd/pbd/file_utils.h index b55b9fd4e4..876f1148d5 100644 --- a/libs/pbd/pbd/file_utils.h +++ b/libs/pbd/pbd/file_utils.h @@ -235,9 +235,9 @@ LIBPBD_API int clear_directory (const std::string& dir, size_t* size = 0, /** * Remove all the contents of a directory recursively. - * @note dir will not be removed + * including the dir itself (`rm -rf $dir`) * - * @param dir The directory to remove files from. + * @param dir The directory to remove recursively */ LIBPBD_API void remove_directory (const std::string& dir); diff --git a/libs/pbd/test/filesystem_test.cc b/libs/pbd/test/filesystem_test.cc index 1eaba54968..ccd4deab65 100644 --- a/libs/pbd/test/filesystem_test.cc +++ b/libs/pbd/test/filesystem_test.cc @@ -335,14 +335,7 @@ FilesystemTest::testRemoveDirectory () PBD::remove_directory (output_dir_path); - // doesn't actually remove directory though...just contents - CPPUNIT_ASSERT (Glib::file_test (output_dir_path, Glib::FILE_TEST_IS_DIR)); - - files_in_output_dir.clear (); - - PBD::get_paths (files_in_output_dir, output_dir_path, false, true); - - CPPUNIT_ASSERT (files_in_output_dir.size () == 0); + CPPUNIT_ASSERT (!Glib::file_test (output_dir_path, Glib::FILE_TEST_EXISTS)); } void