kioslave: create absolute lock file for the trash kioslave

otherwise it is affected by the current directory of the slave process

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-09-08 03:22:15 +03:00
parent ec442d8ad1
commit 119bf184de

View file

@ -26,9 +26,16 @@
#include <kconfig.h>
#include <kconfiggroup.h>
#include <klockfile.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <QtCore/QDir>
static QString kTrashLock()
{
return KGlobal::dirs()->saveLocation("tmp") + QLatin1String( "trash" );
}
TrashSizeCache::TrashSizeCache( const QString &path )
: mTrashSizeCachePath( path + QDir::separator() + QString::fromLatin1( "metadata" ) ),
mTrashPath( path ),
@ -45,7 +52,7 @@ void TrashSizeCache::initialize()
void TrashSizeCache::add( qulonglong value )
{
KLockFile lock( QLatin1String( "trash" ) );
KLockFile lock( kTrashLock() );
lock.lock();
KConfig config( mTrashSizeCachePath );
@ -56,13 +63,11 @@ void TrashSizeCache::add( qulonglong value )
group.writeEntry( mTrashSizeKey, size );
config.sync();
lock.unlock();
}
void TrashSizeCache::remove( qulonglong value )
{
KLockFile lock( QLatin1String( "trash" ) );
KLockFile lock( kTrashLock() );
lock.lock();
KConfig config( mTrashSizeCachePath );
@ -73,13 +78,11 @@ void TrashSizeCache::remove( qulonglong value )
group.writeEntry( mTrashSizeKey, size );
config.sync();
lock.unlock();
}
void TrashSizeCache::clear()
{
KLockFile lock( QLatin1String( "trash" ) );
KLockFile lock( kTrashLock() );
lock.lock();
KConfig config( mTrashSizeCachePath );
@ -87,8 +90,6 @@ void TrashSizeCache::clear()
group.writeEntry( mTrashSizeKey, (qulonglong)0 );
config.sync();
lock.unlock();
}
qulonglong TrashSizeCache::size() const
@ -98,7 +99,7 @@ qulonglong TrashSizeCache::size() const
qulonglong TrashSizeCache::currentSize( bool doLocking ) const
{
KLockFile lock( QLatin1String( "trash" ) );
KLockFile lock( kTrashLock() );
if ( doLocking ) {
lock.lock();