summaryrefslogtreecommitdiffstats
path: root/tdeioslave/trash/trashimpl.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2016-11-20 23:58:22 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2016-11-20 23:58:22 +0900
commitb6887381d7062e2150c5511d50ac03421bcc211d (patch)
tree7235f10c87eda8b99e976f6eebf8a35ae1fbe75a /tdeioslave/trash/trashimpl.cpp
parent6110a523f9acb34a704fda02b2aa9d5e555358f5 (diff)
downloadtdebase-b6887381d7062e2150c5511d50ac03421bcc211d.tar.gz
tdebase-b6887381d7062e2150c5511d50ac03421bcc211d.zip
Trash limit: add "fixed size" configuration option and code
improvements. This relates to bug 1923. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdeioslave/trash/trashimpl.cpp')
-rw-r--r--tdeioslave/trash/trashimpl.cpp51
1 files changed, 25 insertions, 26 deletions
diff --git a/tdeioslave/trash/trashimpl.cpp b/tdeioslave/trash/trashimpl.cpp
index e6b219a13..6de7edd2a 100644
--- a/tdeioslave/trash/trashimpl.cpp
+++ b/tdeioslave/trash/trashimpl.cpp
@@ -22,7 +22,6 @@
#include <tdelocale.h>
#include <klargefile.h>
-#include <tdeio/global.h>
#include <tdeio/renamedlg.h>
#include <tdeio/job.h>
#include <kdebug.h>
@@ -35,8 +34,6 @@
#include <tdefileitem.h>
#include <tdeio/chmodjob.h>
-#include <dcopref.h>
-
#include <tqapplication.h>
#include <tqeventloop.h>
#include <tqfile.h>
@@ -51,6 +48,8 @@
#include <stdlib.h>
#include <errno.h>
+#include "trash_constant.h"
+
TrashImpl::TrashImpl() :
TQObject(),
m_lastErrorCode( 0 ),
@@ -976,7 +975,10 @@ bool TrashImpl::adaptTrashSize( const TQString& origPath, int trashId )
bool useTimeLimit = config.readBoolEntry( "UseTimeLimit", false );
bool useSizeLimit = config.readBoolEntry( "UseSizeLimit", true );
+ int sizeLimitType = config.readNumEntry( "SizeLimitType", TrashConstant::SIZE_LIMIT_PERCENT );
double percent = config.readDoubleNumEntry( "Percent", 10 );
+ double fixedSize = config.readDoubleNumEntry( "FixedSize", 500 );
+ int fixedSizeUnit = config.readNumEntry( "FixedSizeUnit", TrashConstant::SIZE_ID_MB );
int actionType = config.readNumEntry( "LimitReachedAction", 0 );
if ( useTimeLimit ) { // delete all files in trash older than X days
@@ -998,33 +1000,32 @@ bool TrashImpl::adaptTrashSize( const TQString& origPath, int trashId )
}
if ( useSizeLimit ) { // check if size limit exceeded
-
// calculate size of the files to be put into the trash
unsigned long additionalSize = DiscSpaceUtil::sizeOfPath( origPath );
-
- DiscSpaceUtil util( trashPath + "/files/" );
- if ( util.usage( additionalSize ) >= percent ) {
+ TQString trashPathName = trashPath + "/files/";
+ DiscSpaceUtil util( trashPathName );
+ unsigned long requiredTrashSpace = util.sizeOfPath(trashPathName) + additionalSize;
+ unsigned long trashLimit = 0;
+ if ( sizeLimitType == TrashConstant::SIZE_LIMIT_PERCENT)
+ {
+ trashLimit = (unsigned long)(1024 * percent * util.size() / 100.0);
+ }
+ else if ( sizeLimitType == TrashConstant::SIZE_LIMIT_FIXED)
+ {
+ double trashLimitTemp = fixedSize;
+ while (fixedSizeUnit > TrashConstant::SIZE_ID_B)
+ {
+ trashLimitTemp *= 1024;
+ --fixedSizeUnit;
+ }
+ trashLimit = (unsigned long)trashLimitTemp;
+ }
+ if ( requiredTrashSpace > trashLimit ) {
if ( actionType == 0 ) { // warn the user only
m_lastErrorCode = TDEIO::ERR_SLAVE_DEFINED;
m_lastErrorMessage = i18n( "The trash has reached its maximum size!\nClean the trash manually." );
return false;
} else {
- // before we start to remove any files from the trash,
- // check whether the new file will fit into the trash
- // at all...
-
- unsigned long partitionSize = util.size(); // in kB
- unsigned long fileSize = additionalSize/1024; // convert to kB
-
- if ( ((double)fileSize*100/(double)partitionSize) >= percent ) {
- m_lastErrorCode = TDEIO::ERR_SLAVE_DEFINED;
- m_lastErrorMessage = i18n( "The file is too big to be trashed because it exceeds the maximum size set for the trash bin." );
- return false;
- }
-
- // the size of the to be trashed file is ok, so lets start removing
- // some other files from the trash
-
TQDir dir( trashPath + "/files" );
const TQFileInfoList *infos = 0;
if ( actionType == 1 ) // delete oldest files first
@@ -1038,11 +1039,9 @@ bool TrashImpl::adaptTrashSize( const TQString& origPath, int trashId )
TQFileInfo *info;
bool deleteFurther = true;
while ( ((info = it.current()) != 0) && deleteFurther ) {
-
if ( info->fileName() != "." && info->fileName() != ".." ) {
del( trashId, info->fileName() ); // delete trashed file
-
- if ( util.usage( additionalSize ) < percent ) // check whether we have enough space now
+ if ( (util.sizeOfPath(trashPathName) + additionalSize) < trashLimit ) // check whether we have enough space now
deleteFurther = false;
}
++it;