#ifdef WIN32
#include <time.h>
+#else
+#include <cstdio>
+#include <unistd.h>
+#include <fcntl.h>
+#include <cerrno>
#endif
#include <TCollection_AsciiString.hxx>
myFileNameSizes( 0 ),
myCurrOFile( 0 ),
myNbFilles( 0 ),
- myBloc( 0 )
+ myBloc( 0 ),
+ myBlocFcntl( 0 )
{
}
QString fName = Qtx::addSlash( theListOfFiles.front().c_str() ) + "used_by_salome";
myBloc = fopen( fName.toLatin1().constData(), "w" );
+
+#ifndef WIN32
+ fName += ".fcntl";
+ myBlocFcntl = fopen( fName.toLatin1().constData(), "w" );
+#endif
+ lockFcntl( QString() );
+
}
+/*
+ * Lock theLF or myBlockFcntl if empty
+ * returns 0 on success
+ */
+int LightApp_Driver::lockFcntl( QString theLF )
+{
+#ifdef WIN32
+ return 0;
+#else
+ if ( theLF.isEmpty() && !myBlocFcntl )
+ return -2;
+
+ FILE* aFD;
+ if ( theLF.isEmpty() )
+ aFD = myBlocFcntl;
+ else
+ aFD = fopen( theLF.toLatin1().constData(), "w" );
+
+ struct flock fLock;
+ fLock.l_type = F_WRLCK;
+ fLock.l_whence = SEEK_SET;
+ fLock.l_len = 0;
+ fLock.l_start = 0;
+ return fcntl( fileno( aFD ), F_SETLK, &fLock );
+#endif
+
+}
+
+
/*!
Remove files. First item in <theFiles> is a directory with slash at the end.
Other items are names of files. If <IsDirDeleted> is true,
QString blocName = Qtx::addSlash(tmpDir) + "used_by_salome";
myBloc = fopen( blocName.toLatin1().constData(), "w" );
+#ifndef WIN32
+ blocName += ".fcntl";
+ if ( myBlocFcntl )
+ fclose( myBlocFcntl );
+ myBlocFcntl = fopen( blocName.toLatin1().constData(), "w" );
+#endif
+ lockFcntl( QString() );
+
+
+
return aTmpDir.ToCString();
}
#pragma warning( disable:4251 )
#endif
+class QString;
+
/*!Description : Driver can save to file and read from file list of files for light modules*/
class LIGHTAPP_EXPORT LightApp_Driver
void SetIsTemporary( bool theFlag ) { myIsTemp = theFlag; }
bool IsTemporary() const { return myIsTemp; }
+
+ int lockFcntl( QString theLF );
protected:
typedef std::map<std::string, ListOfFiles> MapOfListOfFiles;
MapOfListOfFiles myMap;
std::string myTmpDir;
FILE* myBloc;
+#ifndef WIN32
+ FILE* myBlocFcntl;
+#endif
private:
bool myIsTemp;
#include <windows.h>
#else
#include <dlfcn.h>
+
+#include <cstdio>
+#include <unistd.h>
+#include <fcntl.h>
+#include <cerrno>
#endif
#include "SUIT_Study.h"
myExitStatus( NORMAL ),
myExitFlags ( 0 ),
myBTimer( 0 ),
- myBFile( 0 )
+ myBFile( 0 ),
+ myBFileFcntl( 0 )
{
SUIT_ASSERT( !mySession )
{
QString used = Qtx::addSlash( myBFolder ) + "used_by_salome";
myBFile = fopen( used.toLatin1().constData(), "w" );
+
+#ifndef WIN32
+ used += ".fcntl";
+ myBFileFcntl = fopen( used.toLatin1().constData(), "w" );
+#endif
+ lockFcntl( QString() );
}
}
+/*
+ * Lock theLF or myBFileFcntl if empty
+ * returns 0 on success
+ */
+int SUIT_Session::lockFcntl( QString theLF )
+{
+#ifdef WIN32
+ return 0;
+#else
+ if ( theLF.isEmpty() && !myBFileFcntl )
+ return -2;
+
+ FILE* aFD;
+ if ( theLF.isEmpty() )
+ aFD = myBFileFcntl;
+ else
+ aFD = fopen( theLF.toLatin1().constData(), "w" );
+
+ struct flock fLock;
+ fLock.l_type = F_WRLCK;
+ fLock.l_whence = SEEK_SET;
+ fLock.l_len = 0;
+ fLock.l_start = 0;
+ return fcntl( fileno( aFD ), F_SETLK, &fLock );
+#endif
+
+}
+
/*!
Slot, called when backup interval is out, iterates through all opened
applications, creates 'folderName' directories for them and calls app->backup( folderName );
// checks whether folder is not currently used
QString testFile = Qtx::addSlash( stdRoot ) + "used_by_salome";
QFileInfo fi( testFile );
- if ( fi.exists() && !QFile( testFile ).remove() )
- continue;
-
+ if ( fi.exists() )
+ {
+#ifdef WIN32
+ if ( !QFile( testFile ).remove() )
+ continue;
+#else
+ testFile += ".fcntl";
+ if ( lockFcntl( testFile ) )
+ continue;
+#endif
+ }
+
toRemove.append( stdRoot );
QDir sessDir( stdRoot );
// iterate through tmp folders
const QString& currF = Qtx::addSlash( QDir::tempPath() ) + *it;
QString blocName = Qtx::addSlash( currF ) + "used_by_salome";
- if ( QFileInfo( blocName ).exists() && QFile::remove( blocName ) )
+
+
+ bool locked;
+#ifdef WIN32
+ locked = !QFile( blocName ).remove();
+#else
+ QString testFile = blocName + ".fcntl";
+ locked = lockFcntl( testFile );
+#endif
+
+ if ( QFileInfo( blocName ).exists() && !locked )
{
// unused non-removed folder
Qtx::rmDir( currF );