logic: fixed crash when renaming the temp storage while it is still used
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include "Application.h"
|
||||
|
||||
TaskCleanStorage::TaskCleanStorage(
|
||||
PersistentStorage* storage, const std::vector<FilePath>& filePaths, bool clearAllErrors
|
||||
std::weak_ptr<PersistentStorage> storage, const std::vector<FilePath>& filePaths, bool clearAllErrors
|
||||
)
|
||||
: m_storage(storage)
|
||||
, m_filePaths(filePaths)
|
||||
@@ -25,23 +25,29 @@ void TaskCleanStorage::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
|
||||
if (!m_filePaths.empty() || m_clearAllErrors)
|
||||
{
|
||||
m_storage->setMode(SqliteIndexStorage::STORAGE_MODE_CLEAR);
|
||||
if (std::shared_ptr<PersistentStorage> storage = m_storage.lock())
|
||||
{
|
||||
storage->setMode(SqliteIndexStorage::STORAGE_MODE_CLEAR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Task::TaskState TaskCleanStorage::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
if (m_clearAllErrors)
|
||||
if (std::shared_ptr<PersistentStorage> storage = m_storage.lock())
|
||||
{
|
||||
m_storage->clearAllErrors();
|
||||
}
|
||||
|
||||
m_storage->clearFileElements(m_filePaths, [=](int progress)
|
||||
if (m_clearAllErrors)
|
||||
{
|
||||
Application::getInstance()->getDialogView(DialogView::UseCase::INDEXING)->showProgressDialog(
|
||||
L"Clearing", std::to_wstring(m_filePaths.size()) + L" Files", progress);
|
||||
storage->clearAllErrors();
|
||||
}
|
||||
);
|
||||
|
||||
storage->clearFileElements(m_filePaths, [=](int progress)
|
||||
{
|
||||
Application::getInstance()->getDialogView(DialogView::UseCase::INDEXING)->showProgressDialog(
|
||||
L"Clearing", std::to_wstring(m_filePaths.size()) + L" Files", progress);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
m_filePaths.clear();
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class TaskCleanStorage
|
||||
{
|
||||
public:
|
||||
TaskCleanStorage(
|
||||
PersistentStorage* storage,
|
||||
std::weak_ptr<PersistentStorage> storage,
|
||||
const std::vector<FilePath>& filePaths,
|
||||
bool clearAllErrors
|
||||
);
|
||||
@@ -26,7 +26,7 @@ private:
|
||||
void doExit(std::shared_ptr<Blackboard> blackboard) override;
|
||||
void doReset(std::shared_ptr<Blackboard> blackboard) override;
|
||||
|
||||
PersistentStorage* m_storage;
|
||||
std::weak_ptr<PersistentStorage> m_storage;
|
||||
std::vector<FilePath> m_filePaths;
|
||||
bool m_clearAllErrors;
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr<Blackboard> blackboa
|
||||
|
||||
void TaskFinishParsing::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
m_storage.reset();
|
||||
}
|
||||
|
||||
void TaskFinishParsing::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
TaskInjectStorage::TaskInjectStorage(
|
||||
std::shared_ptr<StorageProvider> storageProvider,
|
||||
std::shared_ptr<Storage> target
|
||||
std::weak_ptr<Storage> target
|
||||
)
|
||||
: m_storageProvider(storageProvider)
|
||||
, m_target(target)
|
||||
@@ -26,8 +26,11 @@ Task::TaskState TaskInjectStorage::doUpdate(std::shared_ptr<Blackboard> blackboa
|
||||
std::shared_ptr<IntermediateStorage> source = m_storageProvider->consumeLargestStorage();
|
||||
if (source)
|
||||
{
|
||||
m_target->inject(source.get());
|
||||
return STATE_SUCCESS;
|
||||
if (std::shared_ptr<Storage> target = m_target.lock())
|
||||
{
|
||||
target->inject(source.get());
|
||||
return STATE_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -14,7 +14,7 @@ class TaskInjectStorage
|
||||
public:
|
||||
TaskInjectStorage(
|
||||
std::shared_ptr<StorageProvider> storageProvider,
|
||||
std::shared_ptr<Storage> target
|
||||
std::weak_ptr<Storage> target
|
||||
);
|
||||
|
||||
private:
|
||||
@@ -24,7 +24,7 @@ private:
|
||||
void doReset(std::shared_ptr<Blackboard> blackboard) override;
|
||||
|
||||
std::shared_ptr<StorageProvider> m_storageProvider;
|
||||
std::shared_ptr<Storage> m_target;
|
||||
std::weak_ptr<Storage> m_target;
|
||||
};
|
||||
|
||||
#endif // TASK_INJECT_STORAGE_H
|
||||
|
||||
@@ -6,15 +6,11 @@
|
||||
#include "utility/utility.h"
|
||||
#include "Application.h"
|
||||
|
||||
TaskParseWrapper::TaskParseWrapper(PersistentStorage* storage)
|
||||
TaskParseWrapper::TaskParseWrapper(std::weak_ptr<PersistentStorage> storage)
|
||||
: m_storage(storage)
|
||||
{
|
||||
}
|
||||
|
||||
TaskParseWrapper::~TaskParseWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
void TaskParseWrapper::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
int sourceFileCount = 0;
|
||||
@@ -30,7 +26,10 @@ void TaskParseWrapper::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
|
||||
if (sourceFileCount > 0)
|
||||
{
|
||||
m_storage->setMode(SqliteIndexStorage::STORAGE_MODE_WRITE);
|
||||
if (std::shared_ptr<PersistentStorage> storage = m_storage.lock())
|
||||
{
|
||||
storage->setMode(SqliteIndexStorage::STORAGE_MODE_WRITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ class TaskParseWrapper
|
||||
: public TaskDecorator
|
||||
{
|
||||
public:
|
||||
TaskParseWrapper(PersistentStorage* storage);
|
||||
virtual ~TaskParseWrapper();
|
||||
TaskParseWrapper(std::weak_ptr<PersistentStorage> storage);
|
||||
|
||||
private:
|
||||
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||
@@ -25,7 +24,7 @@ private:
|
||||
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||
|
||||
PersistentStorage* m_storage;
|
||||
std::weak_ptr<PersistentStorage> m_storage;
|
||||
|
||||
TimeStamp m_start;
|
||||
};
|
||||
|
||||
@@ -422,7 +422,7 @@ void Project::buildIndex(const RefreshInfo& info, DialogView* dialogView)
|
||||
if (info.mode != REFRESH_ALL_FILES && (info.filesToClear.size() || info.nonIndexedFilesToClear.size()))
|
||||
{
|
||||
taskSequential->addTask(std::make_shared<TaskCleanStorage>(
|
||||
tempStorage.get(),
|
||||
tempStorage,
|
||||
utility::toVector(utility::concat(info.filesToClear, info.nonIndexedFilesToClear)),
|
||||
info.mode == REFRESH_UPDATED_AND_INCOMPLETE_FILES
|
||||
));
|
||||
@@ -467,7 +467,7 @@ void Project::buildIndex(const RefreshInfo& info, DialogView* dialogView)
|
||||
taskSequential->addTask(std::make_shared<TaskSetValue<int>>("indexed_source_file_count", 0));
|
||||
taskSequential->addTask(std::make_shared<TaskSetValue<int>>("indexer_count", 0));
|
||||
|
||||
std::shared_ptr<TaskParseWrapper> taskParserWrapper = std::make_shared<TaskParseWrapper>(tempStorage.get());
|
||||
std::shared_ptr<TaskParseWrapper> taskParserWrapper = std::make_shared<TaskParseWrapper>(tempStorage);
|
||||
|
||||
taskSequential->addTask(taskParserWrapper);
|
||||
std::shared_ptr<TaskGroupParallel> taskParallelIndexing = std::make_shared<TaskGroupParallel>();
|
||||
@@ -537,7 +537,6 @@ void Project::buildIndex(const RefreshInfo& info, DialogView* dialogView)
|
||||
|
||||
taskSequential->addTask(std::make_shared<TaskFinishParsing>(tempStorage));
|
||||
|
||||
|
||||
taskSequential->addTask(std::make_shared<TaskGroupSelector>()->addChildTasks(
|
||||
std::make_shared<TaskGroupSequence>()->addChildTasks(
|
||||
std::make_shared<TaskFindValue>("keep_database"),
|
||||
|
||||
@@ -12,10 +12,7 @@ class Message
|
||||
: public MessageBase
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Message()
|
||||
{
|
||||
}
|
||||
virtual ~Message() = default;
|
||||
|
||||
virtual std::string getType() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user