• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "overlap_binary_file_packer.h"
17 
18 namespace OHOS {
19 namespace Global {
20 namespace Restool {
21 using namespace std;
22 
OverlapBinaryFilePacker(const PackageParser & packageParser,const std::string & moduleName)23 OverlapBinaryFilePacker::OverlapBinaryFilePacker(const PackageParser &packageParser, const std::string &moduleName)
24     : BinaryFilePacker(packageParser, moduleName)
25 {
26 }
27 
CopyBinaryFile(const vector<string> & inputs)28 uint32_t OverlapBinaryFilePacker::CopyBinaryFile(const vector<string> &inputs)
29 {
30     string hapPath = inputs[0];
31     BinaryFilePacker::CopyBinaryFile(hapPath);
32     if (CheckCopyResults() != RESTOOL_SUCCESS) {
33         return RESTOOL_ERROR;
34     }
35 
36     vector<string> resource(inputs.begin() + 1, inputs.end());
37     BinaryFilePacker rawFilePacker(packageParser_, moduleName_);
38     std::future<uint32_t> copyFuture = rawFilePacker.CopyBinaryFileAsync(resource);
39     if (copyFuture.get() != RESTOOL_SUCCESS) {
40         return RESTOOL_ERROR;
41     }
42     return RESTOOL_SUCCESS;
43 }
44 
IsDuplicated(const unique_ptr<FileEntry> & entry,string subPath)45 bool OverlapBinaryFilePacker::IsDuplicated(const unique_ptr<FileEntry> &entry, string subPath)
46 {
47     lock_guard<mutex> lock(mutex_);
48     if (!g_hapResourceSet.emplace(subPath).second || !g_resourceSet.emplace(subPath).second) {
49         cout << "Warning: '" << entry->GetFilePath().GetPath() << "' is defined repeatedly in hap." << endl;
50         return true;
51     }
52     return false;
53 }
54 }
55 }
56 }