mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-10-01 10:40:20 +03:00
Fix recursive directory removal across platforms
Add FileSystem::dirRemoveAll() to normalize trailing separators and use the non-throwing std::filesystem::remove_all overload. Migrate ecode and unit-test cleanup call sites to the centralized helper, preventing Haiku from crashing when removing directories with trailing slashes during shutdown.
This commit is contained in:
@@ -1046,14 +1046,6 @@ App::App( const size_t& jobs, const std::vector<std::string>& args ) :
|
||||
mFontPickerController( std::make_unique<FontPickerController>( this ) ),
|
||||
mSettingsActions( std::make_unique<SettingsActions>( this ) ) {}
|
||||
|
||||
static void fsRemoveAll( const std::string& fpath ) {
|
||||
#if EE_PLATFORM == EE_PLATFORM_WIN
|
||||
fs::remove_all( std::filesystem::path( String( fpath ).toWideString() ) );
|
||||
#else
|
||||
fs::remove_all( fpath );
|
||||
#endif
|
||||
}
|
||||
|
||||
App::~App() {
|
||||
appInstance = nullptr;
|
||||
mDestroyingApp = true;
|
||||
@@ -1082,7 +1074,8 @@ App::~App() {
|
||||
}
|
||||
mDirTree.reset();
|
||||
|
||||
fsRemoveAll( mPidPath );
|
||||
if ( !FileSystem::dirRemoveAll( mPidPath ) )
|
||||
Log::warning( "Failed to remove directory \"%s\"", mPidPath );
|
||||
|
||||
if ( mFirstInstance )
|
||||
FileSystem::fileRemove( firstInstanceIndicatorPath() );
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#include "settingsmenu.hpp"
|
||||
#include "uitreeviewfs.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace ecode {
|
||||
|
||||
String SettingsMenu::i18n( const std::string& key, const String& def ) {
|
||||
@@ -2866,14 +2863,6 @@ void SettingsMenu::createProjectTreeMenu() {
|
||||
showProjectTreeMenu();
|
||||
}
|
||||
|
||||
static void fsRemoveAll( const std::string& fpath ) {
|
||||
#if EE_PLATFORM == EE_PLATFORM_WIN
|
||||
fs::remove_all( std::filesystem::path( String( fpath ).toWideString() ) );
|
||||
#else
|
||||
fs::remove_all( fpath );
|
||||
#endif
|
||||
}
|
||||
|
||||
void SettingsMenu::createProjectTreeMenu( const std::vector<FileInfo>& files ) {
|
||||
if ( mProjectTreeMenu && mProjectTreeMenu->isVisible() )
|
||||
mProjectTreeMenu->close();
|
||||
@@ -3152,13 +3141,8 @@ void SettingsMenu::deleteFileDialog( const FileInfo& file ) {
|
||||
};
|
||||
|
||||
if ( file.isDirectory() ) {
|
||||
try {
|
||||
std::string fpath( file.getFilepath() );
|
||||
FileSystem::dirRemoveSlashAtEnd( fpath );
|
||||
fsRemoveAll( fpath );
|
||||
} catch ( const fs::filesystem_error& ) {
|
||||
if ( !FileSystem::dirRemoveAll( file.getFilepath() ) )
|
||||
errFn();
|
||||
}
|
||||
} else if ( !FileSystem::fileRemove( file.getFilepath() ) ) {
|
||||
errFn();
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#include <eepp/ui/uimessagebox.hpp>
|
||||
#include <eepp/window/cursormanager.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
namespace ecode {
|
||||
|
||||
static const std::map<KeyBindings::Shortcut, std::string> getDefaultKeybindings() {
|
||||
@@ -405,14 +403,10 @@ void UITreeViewFS::deleteItems( const std::vector<std::string>& paths ) {
|
||||
msgBox->on( Event::OnConfirm, [paths]( const Event* ) {
|
||||
for ( const auto& path : paths ) {
|
||||
FileInfo info( path );
|
||||
try {
|
||||
if ( info.isDirectory() ) {
|
||||
std::filesystem::remove_all( std::filesystem::path( path ) );
|
||||
} else {
|
||||
FileSystem::fileRemove( path );
|
||||
}
|
||||
} catch ( const std::filesystem::filesystem_error& ) {
|
||||
}
|
||||
if ( info.isDirectory() )
|
||||
FileSystem::dirRemoveAll( path );
|
||||
else
|
||||
FileSystem::fileRemove( path );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user