mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
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:
parent
fac8dfb28b
commit
99ce0a7bbb
|
@ -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 {
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue