Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #181 #222

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/data/logdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ void LogData::attachFile( const QString& fileName )
{
LOG(logDEBUG) << "LogData::attachFile " << fileName.toStdString();

fileMutex_.lock();

if ( attached_file_ ) {
// We cannot reattach
throw CantReattachErr();
Expand All @@ -117,6 +119,8 @@ void LogData::attachFile( const QString& fileName )
attached_file_.reset( new QFile( fileName ) );
attached_file_->open( QIODevice::ReadOnly );

fileMutex_.unlock();

std::shared_ptr<const LogDataOperation> operation( new AttachOperation( fileName ) );
enqueueOperation( std::move( operation ) );
}
Expand Down Expand Up @@ -199,37 +203,44 @@ void LogData::fileChangedOnDisk()
{
LOG(logDEBUG) << "signalFileChanged";

fileMutex_.lock();

const QString name = attached_file_->fileName();
QFileInfo info( name );

// Need to open the file in case it was absent
attached_file_->open( QIODevice::ReadOnly );

std::shared_ptr<LogDataOperation> newOperation;
std::function<std::shared_ptr<LogDataOperation>()> newOperation;

qint64 file_size = indexing_data_.getSize();
LOG(logDEBUG) << "current fileSize=" << file_size;
LOG(logDEBUG) << "info file_->size()=" << info.size();
if ( info.size() < file_size ) {
fileChangedOnDisk_ = Truncated;
LOG(logINFO) << "File truncated";
newOperation = std::make_shared<FullIndexOperation>();
newOperation = std::make_shared<FullIndexOperation>;
}
else if ( info.size() == file_size ) {
LOG(logINFO) << "No change in file";
}
else if ( fileChangedOnDisk_ != DataAdded ) {
fileChangedOnDisk_ = DataAdded;
LOG(logINFO) << "New data on disk";
newOperation = std::make_shared<PartialIndexOperation>();
newOperation = std::make_shared<PartialIndexOperation>;
}

if ( newOperation ) {
enqueueOperation( newOperation );
lastModifiedDate_ = info.lastModified();
// Need to reopen the file in case it was absent
auto reopened = std::make_unique<QFile>( name );

if ( reopened->open( QIODevice::ReadOnly ) ) {
attached_file_ = std::move( reopened );
enqueueOperation( newOperation() );
lastModifiedDate_ = info.lastModified();

emit fileChanged( fileChangedOnDisk_ );
emit fileChanged( fileChangedOnDisk_ );
}
}

fileMutex_.unlock();
}

void LogData::indexingFinished( LoadingStatus status )
Expand Down