From cd670260a9b0a156fadcaf99bd9ab8a336a01930 Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 13 Mar 2012 14:14:56 +0000 Subject: [PATCH] Register temporary files in the container; automatically remove temporary files on shutdown. --- src/Container/Container_i.cxx | 29 ++++++++++++++++++++++++++++ src/Container/SALOME_Container_i.hxx | 6 ++++++ 2 files changed, 35 insertions(+) diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 30a91f44d..ca31feb8e 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -335,6 +335,9 @@ void Engines_Container_i::Shutdown() { MESSAGE("Engines_Container_i::Shutdown()"); + // Clear registered temporary files + clearTemporaryFiles(); + /* For each component contained in this container * tell it to self-destroy */ @@ -1733,3 +1736,29 @@ int findpathof(const std::string& path, std::string& pth, const std::string& fil } return found; } + +void Engines_Container_i::registerTemporaryFile( const std::string& fileName ) +{ + _tmp_files.remove( fileName ); + _tmp_files.push_back( fileName ); +} + +void Engines_Container_i::unregisterTemporaryFile( const std::string& fileName ) +{ + _tmp_files.remove( fileName ); +} + +void Engines_Container_i::clearTemporaryFiles() +{ + std::list::const_iterator it; + for ( it = _tmp_files.begin(); it != _tmp_files.end(); ++it ) { +#ifdef WIN32 + std::string command = "del /F "; +#else + std::string command = "rm -f "; +#endif + command += *it; + system( command.c_str() ); + } + _tmp_files.clear(); +} diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 52b293c39..a11efb9e1 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -44,6 +44,7 @@ #include #include #include +#include #include class SALOME_NamingService; @@ -129,6 +130,10 @@ public: int getArgc() { return _argc; } char **getArgv() { return _argv; } + void registerTemporaryFile( const std::string& fileName ); + void unregisterTemporaryFile( const std::string& fileName ); + void clearTemporaryFiles(); + protected: static std::map _cntInstances_map; @@ -149,6 +154,7 @@ protected: std::map _listInstances_map; std::map _fileRef_map; std::map _Salome_file_map; + std::list _tmp_files; Engines::fileTransfer_var _fileTransfer; int _argc ; -- 2.39.2