mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-18 09:14:48 -04:00
stop copy binary file when resources compile process failed
Signed-off-by: liule <liule21@huawei.com>
This commit is contained in:
@@ -28,6 +28,7 @@ public:
|
||||
explicit BinaryFilePacker(const PackageParser &packageParser, const std::string &moduleName);
|
||||
~BinaryFilePacker();
|
||||
std::future<uint32_t> CopyBinaryFileAsync(const std::vector<std::string> &inputs);
|
||||
void StopCopy();
|
||||
|
||||
private:
|
||||
uint32_t CopyBinaryFile(const std::vector<std::string> &inputs);
|
||||
@@ -38,6 +39,7 @@ private:
|
||||
std::string moduleName_;
|
||||
ThreadPool threadPool_;
|
||||
std::vector<std::future<uint32_t>> copyResults_;
|
||||
std::atomic<bool> stopCopy_{false};
|
||||
};
|
||||
} // namespace Restool
|
||||
} // namespace Global
|
||||
|
||||
@@ -18,10 +18,11 @@
|
||||
|
||||
#include "cmd_parser.h"
|
||||
#include "config_parser.h"
|
||||
#include "resource_util.h"
|
||||
#include "resource_item.h"
|
||||
#include "resource_data.h"
|
||||
#include "resource_append.h"
|
||||
#include "resource_data.h"
|
||||
#include "resource_item.h"
|
||||
#include "resource_merge.h"
|
||||
#include "resource_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
@@ -49,6 +50,7 @@ private:
|
||||
uint32_t PackPreview();
|
||||
uint32_t PackAppend();
|
||||
uint32_t PackCombine();
|
||||
uint32_t PackQualifierResources(const ResourceMerge &resourceMerge);
|
||||
uint32_t HandleFeature();
|
||||
uint32_t FindResourceItems(const std::map<int64_t, std::vector<ResourceItem>> &resInfoLocal,
|
||||
std::vector<ResourceItem> &items, int64_t id) const;
|
||||
|
||||
@@ -74,11 +74,6 @@ std::future<typename std::result_of<F(Args...)>::type> ThreadPool::Enqueue(F &&f
|
||||
auto task = std::make_shared<p_task>(std::bind(std::forward<F>(f), std::forward<Args>(args)...));
|
||||
|
||||
std::future<return_type> res = task->get_future();
|
||||
if (!running_ || workerThreads_.empty()) {
|
||||
// If the pool is not running or there are no worker threads, execute the task immediately
|
||||
(*task)();
|
||||
return res;
|
||||
}
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(queueMutex_);
|
||||
tasks_.emplace([task]() { (*task)(); });
|
||||
|
||||
@@ -34,6 +34,11 @@ BinaryFilePacker::~BinaryFilePacker()
|
||||
threadPool_.Stop();
|
||||
}
|
||||
|
||||
void BinaryFilePacker::StopCopy()
|
||||
{
|
||||
stopCopy_.store(true);
|
||||
}
|
||||
|
||||
std::future<uint32_t> BinaryFilePacker::CopyBinaryFileAsync(const std::vector<std::string> &inputs)
|
||||
{
|
||||
auto func = [this](const std::vector<std::string> &inputs) { return this->CopyBinaryFile(inputs); };
|
||||
@@ -56,6 +61,10 @@ uint32_t BinaryFilePacker::CopyBinaryFile(const vector<string> &inputs)
|
||||
}
|
||||
}
|
||||
for (auto &res : copyResults_) {
|
||||
if (stopCopy_.load()) {
|
||||
cout << "Info: CopyBinaryFile: stop copy binary file." << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
uint32_t ret = res.get();
|
||||
if (ret != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
@@ -111,6 +120,10 @@ uint32_t BinaryFilePacker::CopyBinaryFileImpl(const string &src, const string &d
|
||||
cerr << "Warning: '" << entry->GetFilePath().GetPath() << "' is defined repeatedly." << endl;
|
||||
continue;
|
||||
}
|
||||
if (stopCopy_.load()) {
|
||||
cout << "Info: CopyBinaryFileImpl: stop copy binary file." << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
string path = entry->GetFilePath().GetPath();
|
||||
auto copyFunc = [this](const string path, string subPath) { return this->CopySingleFile(path, subPath); };
|
||||
std::future<uint32_t> res = threadPool_.Enqueue(copyFunc, path, subPath);
|
||||
|
||||
+10
-2
@@ -295,7 +295,16 @@ uint32_t ResourcePack::PackNormal()
|
||||
|
||||
BinaryFilePacker rawFilePacker(packageParser_, moduleName_);
|
||||
std::future<uint32_t> copyFuture = rawFilePacker.CopyBinaryFileAsync(resourceMerge.GetInputs());
|
||||
uint32_t packQualifierRet = PackQualifierResources(resourceMerge);
|
||||
if (packQualifierRet != RESTOOL_SUCCESS) {
|
||||
rawFilePacker.StopCopy();
|
||||
}
|
||||
uint32_t copyRet = copyFuture.get();
|
||||
return packQualifierRet == RESTOOL_SUCCESS && copyRet == RESTOOL_SUCCESS ? RESTOOL_SUCCESS : RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::PackQualifierResources(const ResourceMerge &resourceMerge)
|
||||
{
|
||||
if (ScanResources(resourceMerge.GetInputs(), packageParser_.GetOutput()) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
@@ -329,8 +338,7 @@ uint32_t ResourcePack::PackNormal()
|
||||
if (resourceTable.CreateResourceTable() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
uint32_t copyRet = copyFuture.get();
|
||||
return copyRet == RESTOOL_SUCCESS ? RESTOOL_SUCCESS : RESTOOL_ERROR;
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::HandleFeature()
|
||||
|
||||
+5
-1
@@ -49,7 +49,11 @@ void ThreadPool::Stop()
|
||||
running_ = false;
|
||||
}
|
||||
condition_.notify_all();
|
||||
for (std::thread &worker : workerThreads_) { worker.join(); }
|
||||
for (std::thread &worker : workerThreads_) {
|
||||
if (worker.joinable()) {
|
||||
worker.join();
|
||||
}
|
||||
}
|
||||
cout << "Info: thread pool is stopped" << endl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user