mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 13:24: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;
|
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 {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1069,7 +1069,7 @@ void GlsResourceRequest::run()
|
||||||
try {
|
try {
|
||||||
string n = dict.getContainingFolder().toStdString() + Utils::Fs::separator() + resourceName;
|
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 {
|
try {
|
||||||
QMutexLocker _( &dataMutex );
|
QMutexLocker _( &dataMutex );
|
||||||
|
|
|
@ -1517,7 +1517,7 @@ void StardictResourceRequest::run()
|
||||||
string n =
|
string n =
|
||||||
dict.getContainingFolder().toStdString() + Utils::Fs::separator() + "res" + Utils::Fs::separator() + resourceName;
|
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 {
|
try {
|
||||||
QMutexLocker _( &dataMutex );
|
QMutexLocker _( &dataMutex );
|
||||||
|
|
|
@ -942,7 +942,7 @@ void XdxfResourceRequest::run()
|
||||||
|
|
||||||
string n = dict.getContainingFolder().toStdString() + Utils::Fs::separator() + resourceName;
|
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 {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#else
|
#else
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#endif
|
#endif
|
||||||
|
#include <QMutexLocker>
|
||||||
|
|
||||||
using namespace BtreeIndexing;
|
using namespace BtreeIndexing;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
@ -54,15 +55,23 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data )
|
||||||
if ( !zipIsOpen )
|
if ( !zipIsOpen )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
QMutexLocker _( &mutex );
|
||||||
// Now seek into the zip file and read its header
|
// Now seek into the zip file and read its header
|
||||||
|
|
||||||
if ( !zip.seek( offset ) )
|
if ( !zip.seek( offset ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ZipFile::LocalFileHeader header;
|
ZipFile::LocalFileHeader header;
|
||||||
|
|
||||||
if ( !ZipFile::readLocalHeader( zip, header ) ) {
|
if ( !ZipFile::readLocalHeader( zip, header ) ) {
|
||||||
|
vector< string > zipFileNames;
|
||||||
|
zip.getFilenames( zipFileNames );
|
||||||
GD_DPRINTF( "Failed to load header" );
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +132,8 @@ bool IndexedZip::indexFile( BtreeIndexing::IndexedWords & zipFileNames, quint32
|
||||||
{
|
{
|
||||||
if ( !zipIsOpen )
|
if ( !zipIsOpen )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
QMutexLocker _( &mutex );
|
||||||
if ( !ZipFile::positionAtCentralDir( zip ) )
|
if ( !ZipFile::positionAtCentralDir( zip ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "btreeidx.hh"
|
#include "btreeidx.hh"
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include "zipfile.hh"
|
#include "zipfile.hh"
|
||||||
|
#include <QMutex>
|
||||||
|
|
||||||
/// Allows using a btree index to read zip files. Basically built on top of
|
/// Allows using a btree index to read zip files. Basically built on top of
|
||||||
/// the base dictionary infrastructure adapted for zips.
|
/// the base dictionary infrastructure adapted for zips.
|
||||||
|
@ -14,6 +15,7 @@ class IndexedZip: public BtreeIndexing::BtreeIndex
|
||||||
{
|
{
|
||||||
ZipFile::SplitZipFile zip;
|
ZipFile::SplitZipFile zip;
|
||||||
bool zipIsOpen;
|
bool zipIsOpen;
|
||||||
|
QMutex mutex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,11 @@ void SplitFile::getFilenames( vector< string > & names ) const
|
||||||
names.push_back( ( *i )->fileName().toStdString() );
|
names.push_back( ( *i )->fileName().toStdString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SplitFile::getCurrentFile() const
|
||||||
|
{
|
||||||
|
return currentFile;
|
||||||
|
}
|
||||||
|
|
||||||
bool SplitFile::open( QFile::OpenMode mode )
|
bool SplitFile::open( QFile::OpenMode mode )
|
||||||
{
|
{
|
||||||
for ( QVector< QFile * >::iterator i = files.begin(); i != files.end(); ++i )
|
for ( QVector< QFile * >::iterator i = files.begin(); i != files.end(); ++i )
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
|
|
||||||
virtual void setFileName( const QString & name ) = 0;
|
virtual void setFileName( const QString & name ) = 0;
|
||||||
void getFilenames( vector< string > & names ) const;
|
void getFilenames( vector< string > & names ) const;
|
||||||
|
int getCurrentFile() const;
|
||||||
bool open( QFile::OpenMode mode );
|
bool open( QFile::OpenMode mode );
|
||||||
void close();
|
void close();
|
||||||
bool seek( quint64 pos );
|
bool seek( quint64 pos );
|
||||||
|
|
Loading…
Reference in a new issue