Skip to content

Commit

Permalink
Fix #181
Browse files Browse the repository at this point in the history
This moves the allocation of the LogDataOperation slightly down, since
we now only enqueue the operation conditionally.
  • Loading branch information
gin-ahirsch committed Jun 14, 2018
1 parent c95b334 commit 7d0eac4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/data/logdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,33 +202,35 @@ void LogData::fileChangedOnDisk()
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 open the file in case it was absent
attached_file_->close();

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

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

Expand Down

0 comments on commit 7d0eac4

Please sign in to comment.