From: san Date: Wed, 21 Dec 2005 12:28:53 +0000 (+0000) Subject: Deletion of a temporary directory implemented X-Git-Tag: CTH_V1_0_3~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6af0c46cf5eba60c076fbdca708a6c5b6b5b8f4d;p=modules%2Fgui.git Deletion of a temporary directory implemented --- diff --git a/src/LightApp/LightApp_Driver.cxx b/src/LightApp/LightApp_Driver.cxx index 2212357e7..122890390 100644 --- a/src/LightApp/LightApp_Driver.cxx +++ b/src/LightApp/LightApp_Driver.cxx @@ -38,6 +38,7 @@ /*! Constructor.*/ LightApp_Driver::LightApp_Driver() +: myIsTemp( false ) { } @@ -354,6 +355,10 @@ LightApp_Driver::ListOfFiles LightApp_Driver::PutStreamToFiles( const unsigned c // Create a temporary directory for the component's data files std::string aDir = GetTmpDir(); + // Remember that the files are in a temporary location that should be deleted + // when a study is closed + SetIsTemporary( true ); + //Get a temporary directory for saving a file TCollection_AsciiString aTmpDir(const_cast(aDir.c_str())); @@ -430,9 +435,17 @@ void LightApp_Driver::RemoveFiles( const ListOfFiles& theFiles, const bool IsDir if(IsDirDeleted) { OSD_Path aPath(aDirName); OSD_Directory aDir(aPath); - OSD_FileIterator anIterator(aPath, '*'); - - if(aDir.Exists() && !anIterator.More()) aDir.Remove(); + // san -- Using a special code block below is essential - it ensures that + // OSD_FileIterator instance is destroyed by the moment when + // OSD_Directory::Remove() is called. + // Otherwise, the directory remains locked (at least on Windows) + // by the iterator and cannot be removed. + { + OSD_FileIterator anIterator(aPath, '*'); + if(!aDir.Exists() || anIterator.More()) + return; + } + aDir.Remove(); } } @@ -461,9 +474,13 @@ void LightApp_Driver::ClearDriverContents() for ( it = myMap.begin(); it != myMap.end(); ++it ) { const char* aModuleName = const_cast(it->first.c_str()); - RemoveTemporaryFiles( aModuleName, false ); + // If the driver contains temporary files - + // remove them along with the temporary directory + RemoveTemporaryFiles( aModuleName, IsTemporary() ); } - myMap.clear(); + myMap.clear(); + // Reset the "temporary" flag + SetIsTemporary( false ); } //============================================================================ diff --git a/src/LightApp/LightApp_Driver.h b/src/LightApp/LightApp_Driver.h index 917918e5a..f995ce27d 100644 --- a/src/LightApp/LightApp_Driver.h +++ b/src/LightApp/LightApp_Driver.h @@ -60,10 +60,16 @@ protected: std::string GetTmpDir(); std::string GetDirFromPath(const std::string& thePath); + void SetIsTemporary( bool theFlag ) { myIsTemp = theFlag; } + bool IsTemporary() const { return myIsTemp; } + protected: typedef std::map MapOfListOfFiles; MapOfListOfFiles myMap; std::string myTmpDir; + +private: + bool myIsTemp; }; #endif