fix: SplitFile thread-safe guard (#1688)

* fix: SplitFile thread-safe guard
* add friendly log message

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
xiaoyifang 2024-07-16 16:00:17 +08:00 committed by GitHub
parent fac8dfb28b
commit 99ce0a7bbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 24 additions and 5 deletions

View file

@ -1565,7 +1565,7 @@ void DslResourceRequest::run()
string n = dict.getContainingFolder().toStdString() + Utils::Fs::separator() + resourceName;
GD_DPRINTF( "n is %s\n", n.c_str() );
GD_DPRINTF( "dsl resource name is %s\n", n.c_str() );
try {
try {

View file

@ -1069,7 +1069,7 @@ void GlsResourceRequest::run()
try {
string n = dict.getContainingFolder().toStdString() + Utils::Fs::separator() + resourceName;
GD_DPRINTF( "n is %s\n", n.c_str() );
GD_DPRINTF( "gls resource name is %s\n", n.c_str() );
try {
QMutexLocker _( &dataMutex );

View file

@ -1517,7 +1517,7 @@ void StardictResourceRequest::run()
string n =
dict.getContainingFolder().toStdString() + Utils::Fs::separator() + "res" + Utils::Fs::separator() + resourceName;
GD_DPRINTF( "n is %s\n", n.c_str() );
GD_DPRINTF( "startdict resource name is %s\n", n.c_str() );
try {
QMutexLocker _( &dataMutex );

View file

@ -942,7 +942,7 @@ void XdxfResourceRequest::run()
string n = dict.getContainingFolder().toStdString() + Utils::Fs::separator() + resourceName;
GD_DPRINTF( "n is %s\n", n.c_str() );
GD_DPRINTF( "xdxf resource name is %s\n", n.c_str() );
try {
try {

View file

@ -13,6 +13,7 @@
#else
#include <QTextCodec>
#endif
#include <QMutexLocker>
using namespace BtreeIndexing;
using std::vector;
@ -54,15 +55,23 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data )
if ( !zipIsOpen )
return false;
QMutexLocker _( &mutex );
// Now seek into the zip file and read its header
if ( !zip.seek( offset ) )
return false;
ZipFile::LocalFileHeader header;
if ( !ZipFile::readLocalHeader( zip, header ) ) {
vector< string > zipFileNames;
zip.getFilenames( zipFileNames );
GD_DPRINTF( "Failed to load header" );
string filename;
if ( zip.getCurrentFile() < zipFileNames.size() ) {
filename = zipFileNames.at( zip.getCurrentFile() );
}
qDebug() << "Current failed zip file:" << QString::fromStdString( filename );
return false;
}
@ -123,6 +132,8 @@ bool IndexedZip::indexFile( BtreeIndexing::IndexedWords & zipFileNames, quint32
{
if ( !zipIsOpen )
return false;
QMutexLocker _( &mutex );
if ( !ZipFile::positionAtCentralDir( zip ) )
return false;

View file

@ -7,6 +7,7 @@
#include "btreeidx.hh"
#include <QFile>
#include "zipfile.hh"
#include <QMutex>
/// Allows using a btree index to read zip files. Basically built on top of
/// the base dictionary infrastructure adapted for zips.
@ -14,6 +15,7 @@ class IndexedZip: public BtreeIndexing::BtreeIndex
{
ZipFile::SplitZipFile zip;
bool zipIsOpen;
QMutex mutex;
public:

View file

@ -44,6 +44,11 @@ void SplitFile::getFilenames( vector< string > & names ) const
names.push_back( ( *i )->fileName().toStdString() );
}
int SplitFile::getCurrentFile() const
{
return currentFile;
}
bool SplitFile::open( QFile::OpenMode mode )
{
for ( QVector< QFile * >::iterator i = files.begin(); i != files.end(); ++i )

View file

@ -32,6 +32,7 @@ public:
virtual void setFileName( const QString & name ) = 0;
void getFilenames( vector< string > & names ) const;
int getCurrentFile() const;
bool open( QFile::OpenMode mode );
void close();
bool seek( quint64 pos );