]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Register temporary files in the container; automatically remove temporary files on...
authorvsr <vsr@opencascade.com>
Tue, 13 Mar 2012 14:14:56 +0000 (14:14 +0000)
committervsr <vsr@opencascade.com>
Tue, 13 Mar 2012 14:14:56 +0000 (14:14 +0000)
src/Container/Container_i.cxx
src/Container/SALOME_Container_i.hxx

index 30a91f44daabc127752495b5e249b1fa480ad41d..ca31feb8ef08951148c9f5d4b26c4de442067471 100644 (file)
@@ -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<std::string>::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();
+}
index 52b293c396a5b0463c79a3b6359e9abc80785ae1..a11efb9e1d3c72c0f342492b8a6d612556d9e08c 100644 (file)
@@ -44,6 +44,7 @@
 #include <sys/types.h>
 #include <omnithread.h>
 #include <map>
+#include <list>
 #include <string>
 
 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<std::string, int> _cntInstances_map;
@@ -149,6 +154,7 @@ protected:
   std::map<std::string,Engines::EngineComponent_var> _listInstances_map;
   std::map<std::string,Engines::fileRef_var> _fileRef_map;
   std::map<std::string,Engines::Salome_file_var> _Salome_file_map;
+  std::list<std::string> _tmp_files;
   Engines::fileTransfer_var _fileTransfer;
 
   int    _argc ;