Bug 123838 - kfind doesn't find large file with minimum file size
Summary: kfind doesn't find large file with minimum file size
Status: RESOLVED FIXED
Alias: None
Product: kfind
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Thorsten Roeder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-18 12:22 UTC by usa
Modified: 2006-05-27 23:44 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description usa 2006-03-18 12:22:21 UTC
Version:           Unbekannt (using KDE 3.4.2 Level "b" , SUSE 10.0)
Compiler:          Target: i586-suse-linux
OS:                Linux (i686) release 2.6.13-15.8-default

A file with 4.2 GB isn't found when entering a search criteria with a minimum file size of (example) 1000 Mb.
Maybe it's because file size is larger than 2147483647 bytes (max_int).

Besides it's impossible to enter a larger number than 2147483647 in the size..at least..field.
Comment 1 Thorsten Roeder 2006-05-10 21:22:45 UTC
SVN commit 539481 by troeder:

- Allow kfind to search for files greater 
than 2GB (INT_MAX), if a size range is specified.
- Allow size ranges greater than 2GB to be entered
into the search form.

Okay to backport this to 3.5.3 ?
(without breaking the message freeze)

CCBUG: 123838


 M  +25 -24    kftabdlg.cpp  
 M  +24 -8     kquery.cpp  
 M  +4 -3      kquery.h  


--- trunk/KDE/kdebase/kfind/kftabdlg.cpp #539480:539481
@@ -208,6 +208,7 @@
     sizeUnitBox ->addItem( i18n("Bytes") );
     sizeUnitBox ->addItem( i18n("KB") );
     sizeUnitBox ->addItem( i18n("MB") );
+    sizeUnitBox ->addItem( i18n("GB") );
     sizeUnitBox ->setCurrentIndex(1);
 
     int tmp = sizeEdit->fontMetrics().width(" 000000000 ");
@@ -603,7 +604,8 @@
 
 void KfindTabWidget::setQuery(KQuery *query)
 {
-	int size;
+  KIO::filesize_t size;
+  KIO::filesize_t sizeunit;
   bool itemAlreadyContained(false);
   // only start if we have valid dates
   if (!isDateValid()) return;
@@ -632,43 +634,42 @@
   switch (sizeUnitBox->currentIndex())
   {
      case 0:
-         size = 1; //one byte
+         sizeunit = 1; //one byte
 			break;
      case 2:
-         size = 1048576; //1M
+         sizeunit = 1048576; //1M
 			break;
-		case 1:
-		default:
-			size=1024; //1k
+     case 3:
+         sizeunit = 1073741824; //1G
 			break;
+     case 1: // fall to default case
+     default:
+         sizeunit=1024; //1k
+            break;
   }
-  size = sizeEdit->value() * size;
+  size = sizeEdit->value() * sizeunit;
+
+// TODO: troeder: do we need this check since it is very unlikely 
+// to exceed ULLONG_MAX with INT_MAX * 1024^3. 
+// Or is there an arch where this can happen?
+#if 0 
   if (size < 0)  // overflow
-     if (KMessageBox::warningYesNo(this, i18n("Size is too big. Set maximum size value?"), i18n("Error"),i18n("Set"),i18n("Do Not Set"))
+  {
+	if (KMessageBox::warningYesNo(this, i18n("Size is too big. Set maximum size value?"), i18n("Error"),i18n("Set"),i18n("Do Not Set"))
            == KMessageBox::Yes)
 		{
          sizeEdit->setValue(INT_MAX);
-	   	sizeUnitBox->setCurrentIndex(0);
-		   size = INT_MAX;
+		 sizeUnitBox->setCurrentIndex(0);
+		 size = INT_MAX;
 		}
      else
         return;
-
-  switch (sizeBox->currentIndex())
-  {
-    case 1:
-      query->setSizeRange(size, -1);
-      break;
-    case 2:
-      query->setSizeRange(-1, size);
-      break;
-    case 3:
-      query->setSizeRange(size,size);
-      break;
-    default:
-      query->setSizeRange(-1, -1);
   }
+#endif
 
+  // set range mode and size value
+  query->setSizeRange(sizeBox->currentIndex(),size,0);
+
   // dates
   QDateTime epoch;
   epoch.setTime_t(0);
--- trunk/KDE/kdebase/kfind/kquery.cpp #539480:539481
@@ -16,7 +16,7 @@
 
 KQuery::KQuery(QObject *parent, const char * name)
   : QObject(parent),
-    m_minsize(-1), m_maxsize(-1),
+    m_sizemode(0), m_sizeboundary1(0), m_sizeboundary2(0),
     m_timeFrom(0), m_timeTo(0),
     job(0), m_insideCheckEntries(false), m_result(0)
 {
@@ -194,9 +194,25 @@
       return;
 
     // make sure the files are in the correct range
-    if (  ( m_minsize >= 0 && (int)file->size() < m_minsize ) ||
-          ( m_maxsize >= 0 && (int)file->size() > m_maxsize ) )
-      return;
+    switch( m_sizemode )
+	{
+		case 1: // "at least"
+				if ( file->size() < m_sizeboundary1 ) return;
+				break;
+		case 2: // "at most"
+				if ( file->size() > m_sizeboundary1 ) return;
+				break;
+		case 3: // "equal"
+				if ( file->size() != m_sizeboundary1 ) return;
+				break;
+		case 4: // "between"
+				if ( (file->size() < m_sizeboundary1) || 
+		 				(file->size() > m_sizeboundary2) ) return;
+				break;
+		case 0: // "none" -> Fall to default
+        default:
+				break;
+	}
 
     // make sure it's in the correct date range
     // what about 0 times?
@@ -424,10 +440,11 @@
   m_filetype = filetype;
 }
 
-void KQuery::setSizeRange(int min, int max)
+void KQuery::setSizeRange(int mode, KIO::filesize_t value1, KIO::filesize_t value2)
 {
-  m_minsize = min;
-  m_maxsize = max;
+  m_sizemode = mode;
+  m_sizeboundary1 = value1;
+  m_sizeboundary2 = value2;
 }
 
 void KQuery::setTimeRange(time_t from, time_t to)
@@ -446,7 +463,6 @@
    m_groupname = groupname;
 }
 
-
 void KQuery::setRegExp(const QString &regexp, bool caseSensitive)
 {
   QRegExp *regExp;
--- trunk/KDE/kdebase/kfind/kquery.h #539480:539481
@@ -24,7 +24,7 @@
   KQuery(QObject *parent = 0, const char * name = 0);
   ~KQuery();
 
-  void setSizeRange( int min, int max );
+  void setSizeRange( int mode, KIO::filesize_t value1, KIO::filesize_t value2);
   void setTimeRange( time_t from, time_t to );
   void setRegExp( const QString &regexp, bool caseSensitive );
   void setRecursive( bool recursive );
@@ -66,8 +66,9 @@
   void checkEntries();
 
   int m_filetype;
-  int m_minsize;
-  int m_maxsize;
+  int m_sizemode;
+  KIO::filesize_t m_sizeboundary1;
+  KIO::filesize_t m_sizeboundary2;
   KUrl m_url;
   time_t m_timeFrom;
   time_t m_timeTo;
Comment 2 Thorsten Roeder 2006-05-27 23:44:05 UTC
SVN commit 545621 by troeder:

backport SVN commit 539481 from trunk for 3.5.4:

- Allow kfind to search for files greater 
than 2GB (INT_MAX), if a size range is specified.
- Allow size ranges greater than 2GB to be entered
into the search form.

BUG: 123838


 M  +23 -24    kftabdlg.cpp  
 M  +23 -8     kquery.cpp  
 M  +4 -3      kquery.h  


--- branches/KDE/3.5/kdebase/kfind/kftabdlg.cpp #545620:545621
@@ -183,6 +183,7 @@
     sizeUnitBox ->insertItem( i18n("Bytes") );
     sizeUnitBox ->insertItem( i18n("KB") );
     sizeUnitBox ->insertItem( i18n("MB") );
+    sizeUnitBox ->insertItem( i18n("GB") );
     sizeUnitBox ->setCurrentItem(1);
 
     int tmp = sizeEdit->fontMetrics().width(" 000000000 ");
@@ -574,7 +575,8 @@
 
 void KfindTabWidget::setQuery(KQuery *query)
 {
-	int size;
+  KIO::filesize_t size;
+  KIO::filesize_t sizeunit;
   bool itemAlreadyContained(false);
   // only start if we have valid dates
   if (!isDateValid()) return;
@@ -603,17 +605,25 @@
   switch (sizeUnitBox->currentItem())
   {
      case 0:
-         size = 1; //one byte
-			break;
+         sizeunit = 1; //one byte
+         break;
      case 2:
-         size = 1048576; //1M
-			break;
-		case 1:
-		default:
-			size=1024; //1k
-			break;
+         sizeunit = 1048576; //1M
+         break;
+     case 3:
+         sizeunit = 1073741824; //1GB
+         break;
+     case 1: //fall to default case
+     default:
+         sizeunit = 1024; //1k
+         break;
   }
-  size = sizeEdit->value() * size;
+  size = sizeEdit->value() * sizeunit;
+
+// TODO: troeder: do we need this check since it is very unlikely-
+// to exceed ULLONG_MAX with INT_MAX * 1024^3.-
+// Or is there an arch where this can happen?
+#if 0
   if (size < 0)  // overflow
      if (KMessageBox::warningYesNo(this, i18n("Size is too big. Set maximum size value?"), i18n("Error"),i18n("Set"),i18n("Do Not Set"))
            == KMessageBox::Yes)
@@ -624,21 +634,10 @@
 		}
      else
         return;
+#endif
 
-  switch (sizeBox->currentItem())
-  {
-    case 1:
-      query->setSizeRange(size, -1);
-      break;
-    case 2:
-      query->setSizeRange(-1, size);
-      break;
-    case 3:
-      query->setSizeRange(size,size);
-      break;
-    default:
-      query->setSizeRange(-1, -1);
-  }
+  // set range mode and size value
+  query->setSizeRange(sizeBox->currentItem(),size,0);
 
   // dates
   QDateTime epoch;
--- branches/KDE/3.5/kdebase/kfind/kquery.cpp #545620:545621
@@ -14,7 +14,7 @@
 
 KQuery::KQuery(QObject *parent, const char * name)
   : QObject(parent, name),
-    m_minsize(-1), m_maxsize(-1),
+    m_sizemode(0), m_sizeboundary1(0), m_sizeboundary2(0),
     m_timeFrom(0), m_timeTo(0),
     job(0), m_insideCheckEntries(false), m_result(0)
 {
@@ -178,10 +178,24 @@
     if (!matched)
       return;
 
-    // make sure the files are in the correct range
-    if (  ( m_minsize >= 0 && (int)file->size() < m_minsize ) ||
-          ( m_maxsize >= 0 && (int)file->size() > m_maxsize ) )
-      return;
+    switch( m_sizemode )
+    {
+        case 1: // "at least"
+            if ( file->size() < m_sizeboundary1 ) return;
+            break;
+        case 2: // "at most"
+            if ( file->size() > m_sizeboundary1 ) return;
+            break;
+        case 3: // "equal"
+            if ( file->size() != m_sizeboundary1 ) return;
+            break;
+        case 4: // "between"
+            if ( (file->size() < m_sizeboundary1) || (file->size() > m_sizeboundary2) ) return;
+            break;
+        case 0: // "none" -> fall to default
+        default:
+            break;
+    }
 
     // make sure it's in the correct date range
     // what about 0 times?
@@ -403,10 +417,11 @@
   m_filetype = filetype;
 }
 
-void KQuery::setSizeRange(int min, int max)
+void KQuery::setSizeRange(int mode, KIO::filesize_t value1, KIO::filesize_t value2)
 {
-  m_minsize = min;
-  m_maxsize = max;
+  m_sizemode = mode;
+  m_sizeboundary1 = value1;
+  m_sizeboundary2 = value2;
 }
 
 void KQuery::setTimeRange(time_t from, time_t to)
--- branches/KDE/3.5/kdebase/kfind/kquery.h #545620:545621
@@ -23,7 +23,7 @@
   KQuery(QObject *parent = 0, const char * name = 0);
   ~KQuery();
 
-  void setSizeRange( int min, int max );
+  void setSizeRange( int mode, KIO::filesize_t value1, KIO::filesize_t value2 );
   void setTimeRange( time_t from, time_t to );
   void setRegExp( const QString &regexp, bool caseSensitive );
   void setRecursive( bool recursive );
@@ -65,8 +65,9 @@
   void checkEntries();
 
   int m_filetype;
-  int m_minsize;
-  int m_maxsize;
+  int m_sizemode;
+  KIO::filesize_t m_sizeboundary1;
+  KIO::filesize_t m_sizeboundary2;
   KURL m_url;
   time_t m_timeFrom;
   time_t m_timeTo;