@ -45,7 +45,7 @@
// TODO: http://www.spinnaker.de/linux/nfs-locking.html
// TODO: Make regression test
class KLockFile: : K LockFilePrivate {
class TDELockFile: : TDE LockFilePrivate {
public :
TQString file ;
int staleTime ;
@ -62,9 +62,9 @@ public:
// 30 seconds
KLockFile: : K LockFile( const TQString & file )
TDELockFile: : TDE LockFile( const TQString & file )
{
d = new K LockFilePrivate( ) ;
d = new TDE LockFilePrivate( ) ;
d - > file = file ;
d - > staleTime = 30 ;
d - > isLocked = false ;
@ -72,21 +72,21 @@ KLockFile::KLockFile(const TQString &file)
d - > linkCountSupport = true ;
}
KLockFile: : ~ K LockFile( )
TDELockFile: : ~ TDE LockFile( )
{
unlock ( ) ;
delete d ;
}
int
K LockFile: : staleTime ( ) const
TDE LockFile: : staleTime ( ) const
{
return d - > staleTime ;
}
void
K LockFile: : setStaleTime ( int _staleTime )
TDE LockFile: : setStaleTime ( int _staleTime )
{
d - > staleTime = _staleTime ;
}
@ -109,17 +109,17 @@ static bool testLinkCountSupport(const TQCString &fileName)
return ( ( result = = 0 ) & & ( st_buf . st_nlink = = 2 ) ) ;
}
static K LockFile: : LockResult lockFile ( const TQString & lockFile , KDE_struct_stat & st_buf , bool & linkCountSupport )
static TDE LockFile: : LockResult lockFile ( const TQString & lockFile , KDE_struct_stat & st_buf , bool & linkCountSupport )
{
TQCString lockFileName = TQFile : : encodeName ( lockFile ) ;
int result = KDE_lstat ( lockFileName , & st_buf ) ;
if ( result = = 0 )
return K LockFile: : LockFail ;
return TDE LockFile: : LockFail ;
KTempFile uniqueFile ( lockFile , TQString : : null , 0644 ) ;
uniqueFile . setAutoDelete ( true ) ;
if ( uniqueFile . status ( ) ! = 0 )
return K LockFile: : LockError ;
return TDE LockFile: : LockError ;
char hostname [ 256 ] ;
hostname [ 0 ] = 0 ;
@ -138,23 +138,23 @@ static KLockFile::LockResult lockFile(const TQString &lockFile, KDE_struct_stat
// Create lock file
result = : : link ( uniqueName , lockFileName ) ;
if ( result ! = 0 )
return K LockFile: : LockError ;
return TDE LockFile: : LockError ;
if ( ! linkCountSupport )
return K LockFile: : LockOK ;
return TDE LockFile: : LockOK ;
# else
//TODO for win32
return K LockFile: : LockOK ;
return TDE LockFile: : LockOK ;
# endif
KDE_struct_stat st_buf2 ;
result = KDE_lstat ( uniqueName , & st_buf2 ) ;
if ( result ! = 0 )
return K LockFile: : LockError ;
return TDE LockFile: : LockError ;
result = KDE_lstat ( lockFileName , & st_buf ) ;
if ( result ! = 0 )
return K LockFile: : LockError ;
return TDE LockFile: : LockError ;
if ( ! statResultIsEqual ( st_buf , st_buf2 ) | | S_ISLNK ( st_buf . st_mode ) | | S_ISLNK ( st_buf2 . st_mode ) )
{
@ -163,15 +163,15 @@ static KLockFile::LockResult lockFile(const TQString &lockFile, KDE_struct_stat
{
linkCountSupport = testLinkCountSupport ( uniqueName ) ;
if ( ! linkCountSupport )
return K LockFile: : LockOK ; // Link count support is missing... assume everything is OK.
return TDE LockFile: : LockOK ; // Link count support is missing... assume everything is OK.
}
return K LockFile: : LockFail ;
return TDE LockFile: : LockFail ;
}
return K LockFile: : LockOK ;
return TDE LockFile: : LockOK ;
}
static K LockFile: : LockResult deleteStaleLock ( const TQString & lockFile , KDE_struct_stat & st_buf , bool & linkCountSupport )
static TDE LockFile: : LockResult deleteStaleLock ( const TQString & lockFile , KDE_struct_stat & st_buf , bool & linkCountSupport )
{
// This is dangerous, we could be deleting a new lock instead of
// the old stale one, let's be very careful
@ -179,7 +179,7 @@ static KLockFile::LockResult deleteStaleLock(const TQString &lockFile, KDE_struc
// Create temp file
KTempFile ktmpFile ( lockFile ) ;
if ( ktmpFile . status ( ) ! = 0 )
return K LockFile: : LockError ;
return TDE LockFile: : LockError ;
TQCString lckFile = TQFile : : encodeName ( lockFile ) ;
TQCString tmpFile = TQFile : : encodeName ( ktmpFile . name ( ) ) ;
@ -189,10 +189,10 @@ static KLockFile::LockResult deleteStaleLock(const TQString &lockFile, KDE_struc
# ifdef Q_OS_UNIX
// link to lock file
if ( : : link ( lckFile , tmpFile ) ! = 0 )
return K LockFile: : LockFail ; // Try again later
return TDE LockFile: : LockFail ; // Try again later
# else
//TODO for win32
return K LockFile: : LockOK ;
return TDE LockFile: : LockOK ;
# endif
// check if link count increased with exactly one
@ -209,7 +209,7 @@ static KLockFile::LockResult deleteStaleLock(const TQString &lockFile, KDE_struc
tqWarning ( " WARNING: deleting stale lockfile %s " , lckFile . data ( ) ) ;
: : unlink ( lckFile ) ;
: : unlink ( tmpFile ) ;
return K LockFile: : LockOK ;
return TDE LockFile: : LockOK ;
}
}
@ -227,34 +227,34 @@ static KLockFile::LockResult deleteStaleLock(const TQString &lockFile, KDE_struc
tqWarning ( " WARNING: deleting stale lockfile %s " , lckFile . data ( ) ) ;
: : unlink ( lckFile ) ;
: : unlink ( tmpFile ) ;
return K LockFile: : LockOK ;
return TDE LockFile: : LockOK ;
}
// Failed to delete stale lock file
tqWarning ( " WARNING: Problem deleting stale lockfile %s " , lckFile . data ( ) ) ;
: : unlink ( tmpFile ) ;
return K LockFile: : LockFail ;
return TDE LockFile: : LockFail ;
}
KLockFile: : LockResult K LockFile: : lock ( int options )
TDELockFile: : LockResult TDE LockFile: : lock ( int options )
{
if ( d - > isLocked )
return K LockFile: : LockOK ;
return TDE LockFile: : LockOK ;
K LockFile: : LockResult result ;
TDE LockFile: : LockResult result ;
int hardErrors = 5 ;
int n = 5 ;
while ( true )
{
KDE_struct_stat st_buf ;
result = lockFile ( d - > file , st_buf , d - > linkCountSupport ) ;
if ( result = = K LockFile: : LockOK )
if ( result = = TDE LockFile: : LockOK )
{
d - > staleTimer = TQTime ( ) ;
break ;
}
else if ( result = = K LockFile: : LockError )
else if ( result = = TDE LockFile: : LockError )
{
d - > staleTimer = TQTime ( ) ;
if ( - - hardErrors = = 0 )
@ -262,7 +262,7 @@ KLockFile::LockResult KLockFile::lock(int options)
break ;
}
}
else // K LockFile::Fail
else // TDE LockFile::Fail
{
if ( ! d - > staleTimer . isNull ( ) & & ! statResultIsEqual ( d - > statBuf , st_buf ) )
d - > staleTimer = TQTime ( ) ;
@ -292,17 +292,17 @@ KLockFile::LockResult KLockFile::lock(int options)
if ( isStale )
{
if ( ( options & LockForce ) = = 0 )
return K LockFile: : LockStale ;
return TDE LockFile: : LockStale ;
result = deleteStaleLock ( d - > file , d - > statBuf , d - > linkCountSupport ) ;
if ( result = = K LockFile: : LockOK )
if ( result = = TDE LockFile: : LockOK )
{
// Lock deletion successful
d - > staleTimer = TQTime ( ) ;
continue ; // Now try to get the new lock
}
else if ( result ! = K LockFile: : LockFail )
else if ( result ! = TDE LockFile: : LockFail )
{
return result ;
}
@ -351,12 +351,12 @@ KLockFile::LockResult KLockFile::lock(int options)
return result ;
}
bool K LockFile: : isLocked ( ) const
bool TDE LockFile: : isLocked ( ) const
{
return d - > isLocked ;
}
void K LockFile: : unlock ( )
void TDE LockFile: : unlock ( )
{
if ( d - > isLocked )
{
@ -365,7 +365,7 @@ void KLockFile::unlock()
}
}
bool K LockFile: : getLockInfo ( int & pid , TQString & hostname , TQString & appname )
bool TDE LockFile: : getLockInfo ( int & pid , TQString & hostname , TQString & appname )
{
if ( d - > pid = = - 1 )
return false ;