search/index: fixed a number of bad conversions to properly deal with text documents bigger than 2GB

This commit is contained in:
"Jean-Francois Dockes ext:(%22)
2011-07-12 08:28:09 -07:00
parent 5e59354535
commit 88685d2e64
11 changed files with 42 additions and 23 deletions
+1 -1
View File
@@ -368,7 +368,7 @@ string& MD5HexScan(const string& xdigest, string& digest)
class FileScanMd5 : public FileScanDo {
public:
FileScanMd5(string& d) : digest(d) {}
virtual bool init(unsigned int size, string *)
virtual bool init(size_t size, string *)
{
MD5Init(&ctx);
return true;
+4 -4
View File
@@ -78,7 +78,7 @@ class FileToString : public FileScanDo {
public:
FileToString(string& data) : m_data(data) {}
string& m_data;
bool init(unsigned int size, string *reason) {
bool init(size_t size, string *reason) {
if (size > 0)
m_data.reserve(size);
return true;
@@ -135,10 +135,10 @@ bool file_scan(const string &fn, FileScanDo* doer, off_t startoffs,
noclosing = false;
}
if (st.st_size > 0) {
doer->init(st.st_size+1, reason);
} else if (cnttoread) {
if (cnttoread != (size_t)-1 && cnttoread) {
doer->init(cnttoread+1, reason);
} else if (st.st_size > 0) {
doer->init(st.st_size+1, reason);
} else {
doer->init(0, reason);
}
+1 -1
View File
@@ -29,7 +29,7 @@ using std::string;
class FileScanDo {
public:
virtual ~FileScanDo() {}
virtual bool init(unsigned int size, string *reason) = 0;
virtual bool init(size_t size, string *reason) = 0;
virtual bool data(const char *buf, int cnt, string* reason) = 0;
};
bool file_scan(const string &filename, FileScanDo* doer, string *reason = 0);
+6 -2
View File
@@ -14,7 +14,11 @@
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef TEST_SMALLUT
#ifdef HAVE_CONFIG_H
#include "autoconfig.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@@ -556,7 +560,7 @@ bool pcSubst(const string& in, string& out, map<string, string>& subs)
}
// Convert byte count into unit (KB/MB...) appropriate for display
string displayableBytes(long size)
string displayableBytes(off_t size)
{
char sizebuf[30];
const char * unit = " B ";
@@ -568,7 +572,7 @@ string displayableBytes(long size)
unit = " MB ";
size /= (1024*1024);
}
sprintf(sizebuf, "%ld%s", size, unit);
sprintf(sizebuf, OFFTPC "%s", size, unit);
return string(sizebuf);
}
+2 -1
View File
@@ -16,6 +16,7 @@
*/
#ifndef _SMALLUT_H_INCLUDED_
#define _SMALLUT_H_INCLUDED_
#include <stdlib.h>
#include <string>
@@ -125,7 +126,7 @@ extern string truncate_to_word(const string &input, string::size_type maxlen);
extern void utf8truncate(string &s, int maxlen);
/** Convert byte count into unit (KB/MB...) appropriate for display */
string displayableBytes(long size);
string displayableBytes(off_t size);
/** Break big string into lines */
string breakIntoLines(const string& in, unsigned int ll = 100,