/*! Constructor.*/
LightApp_Driver::LightApp_Driver()
+: myIsTemp( false )
{
}
// 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<char*>(aDir.c_str()));
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();
}
}
for ( it = myMap.begin(); it != myMap.end(); ++it )
{
const char* aModuleName = const_cast<char*>(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 );
}
//============================================================================