1 /*
2 * Copyright (c) 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 "app_packager.h"
17
18 #include "constants.h"
19 #include "json/hap_verify_info.h"
20 #include "json/module_json_utils.h"
21 #include "json/hap_verify_utils.h"
22 #include "log.h"
23 #include "utils.h"
24
25 namespace OHOS {
26 namespace AppPackingTool {
AppPackager(const std::map<std::string,std::string> & parameterMap,std::string & resultReceiver)27 AppPackager::AppPackager(const std::map<std::string, std::string> ¶meterMap, std::string &resultReceiver)
28 : Packager(parameterMap, resultReceiver)
29 {}
30
InitAllowedParam()31 int32_t AppPackager::InitAllowedParam()
32 {
33 allowedParameters_ = {
34 {}
35 };
36 return ERR_OK;
37 }
38
PreProcess()39 int32_t AppPackager::PreProcess()
40 {
41 if (!CheckForceFlag()) {
42 return ERR_INVALID_VALUE;
43 }
44 bool ret = IsVerifyValidInAppMode();
45 if (!ret) {
46 return ERR_INVALID_VALUE;
47 }
48 if (!Packager::ParseAtomicServiceSizeLimit()) {
49 return ERR_INVALID_VALUE;
50 }
51 return ERR_OK;
52 }
53
Process()54 int32_t AppPackager::Process()
55 {
56 bool ret = CompressAppMode();
57 if (!ret) {
58 std::string outPath;
59 if (parameterMap_.find(Constants::PARAM_OUT_PATH) != parameterMap_.end()) {
60 outPath = parameterMap_.at(Constants::PARAM_OUT_PATH);
61 }
62 if (fs::exists(outPath)) {
63 fs::remove_all(outPath);
64 }
65 LOGE("App Process failed.");
66 return ERR_INVALID_VALUE;
67 }
68 return ERR_OK;
69 }
70
PostProcess()71 int32_t AppPackager::PostProcess()
72 {
73 return ERR_OK;
74 }
75
CheckBundleTypeConsistency(const std::string & hapPath,const std::string & hspPath)76 bool AppPackager::CheckBundleTypeConsistency(const std::string &hapPath, const std::string &hspPath)
77 {
78 std::string bundleType;
79 std::list<std::string> tmpHapPathList;
80 std::list<std::string> tmpHspPathList;
81 Packager::CompatibleProcess(hapPath, tmpHapPathList, Constants::HAP_SUFFIX);
82 Packager::CompatibleProcess(hspPath, tmpHspPathList, Constants::HSP_SUFFIX);
83 if (!tmpHapPathList.empty()) {
84 HapVerifyInfo hapVerifyInfo;
85 if (!ModuleJsonUtils::GetStageHapVerifyInfo(tmpHapPathList.front(), hapVerifyInfo)) {
86 LOGW("GetStageHapVerifyInfo failed, this hap maybe fa module");
87 return true;
88 }
89 bundleType = hapVerifyInfo.GetBundleType();
90 } else {
91 HapVerifyInfo hapVerifyInfo;
92 if (!ModuleJsonUtils::GetStageHapVerifyInfo(tmpHspPathList.front(), hapVerifyInfo)) {
93 LOGW("GetStageHapVerifyInfo failed, this hap maybe fa module");
94 return true;
95 }
96 bundleType = hapVerifyInfo.GetBundleType();
97 }
98 for (const auto& hapPath : tmpHapPathList) {
99 HapVerifyInfo hapVerifyInfo;
100 if (!ModuleJsonUtils::GetStageHapVerifyInfo(hapPath, hapVerifyInfo)) {
101 LOGW("GetStageHapVerifyInfo failed");
102 return false;
103 }
104 if (bundleType != hapVerifyInfo.GetBundleType()) {
105 LOGE("bundleType is not same");
106 return false;
107 }
108 }
109 for (const auto& hspPath : tmpHspPathList) {
110 HapVerifyInfo hapVerifyInfo;
111 if (!ModuleJsonUtils::GetStageHapVerifyInfo(hspPath, hapVerifyInfo)) {
112 LOGW("GetStageHapVerifyInfo failed");
113 return false;
114 }
115 if (bundleType != hapVerifyInfo.GetBundleType()) {
116 LOGE("bundleType is not same");
117 return false;
118 }
119 }
120 return true;
121 }
122
VerifyIsSharedApp(const std::list<std::string> & hspPath)123 bool AppPackager::VerifyIsSharedApp(const std::list<std::string>& hspPath)
124 {
125 HapVerifyInfo hapVerifyInfo;
126 if (!ModuleJsonUtils::GetStageHapVerifyInfo(hspPath.front(), hapVerifyInfo)) {
127 return false;
128 }
129 if (hapVerifyInfo.GetBundleType() != Constants::TYPE_SHARED) {
130 return false;
131 }
132 return true;
133 }
134
IsSharedApp(const std::string & hapPath,const std::string & hspPath)135 bool AppPackager::IsSharedApp(const std::string &hapPath, const std::string &hspPath)
136 {
137 if (!hapPath.empty()) {
138 return false;
139 }
140 if (hspPath.empty()) {
141 return false;
142 }
143 std::list<std::string> tmpHspPathList;
144 if (CompatibleProcess(hspPath, tmpHspPathList, Constants::HSP_SUFFIX)
145 && VerifyIsSharedApp(tmpHspPathList)) {
146 isSharedApp_ = true;
147 return true;
148 }
149 return false;
150 }
151
VerifyIsAppService(const std::list<std::string> & modulePathList)152 bool AppPackager::VerifyIsAppService(const std::list<std::string>& modulePathList)
153 {
154 if (modulePathList.empty()) {
155 LOGE("Module path list is empty");
156 return false;
157 }
158
159 for (const std::string& modulePath : modulePathList) {
160 HapVerifyInfo hapVerifyInfo;
161 if (!ModuleJsonUtils::GetStageHapVerifyInfo(modulePath, hapVerifyInfo)) {
162 return false;
163 }
164 if (hapVerifyInfo.GetBundleType() != Constants::BUNDLE_TYPE_APP_SERVICE) {
165 return false;
166 }
167 }
168 return true;
169 }
170
IsAppService(const std::string & hapPath,const std::string & hspPath)171 bool AppPackager::IsAppService(const std::string &hapPath, const std::string &hspPath)
172 {
173 if (!hapPath.empty()) {
174 std::list<std::string> tmpHapPathList;
175 if (CompatibleProcess(hapPath, tmpHapPathList, Constants::HAP_SUFFIX)
176 && VerifyIsAppService(tmpHapPathList)) {
177 isAppService_ = true;
178 return true;
179 }
180 }
181 if (hspPath.empty()) {
182 return false;
183 }
184 std::list<std::string> tmpHspPathList;
185 if (CompatibleProcess(hspPath, tmpHspPathList, Constants::HSP_SUFFIX)
186 && VerifyIsAppService(tmpHspPathList)) {
187 isAppService_ = true;
188 return true;
189 }
190 return false;
191 }
192
CheckInputModulePath(const std::string & hapPath,const std::string & hspPath)193 bool AppPackager::CheckInputModulePath(const std::string &hapPath, const std::string &hspPath)
194 {
195 bool isSharedApp = IsSharedApp(hapPath, hspPath);
196 bool isAppService = IsAppService(hapPath, hspPath);
197 if (hapPath.empty() && !isSharedApp && !isAppService) {
198 LOGW("CheckInputModulePath hap-path is empty.");
199 return false;
200 }
201 if (hspPath.empty() && isAppService) {
202 LOGW("CheckInputModulePath hsp-path is empty.");
203 return false;
204 }
205 return true;
206 }
207
GetAndCheckOutPath(std::string & outPath)208 bool AppPackager::GetAndCheckOutPath(std::string &outPath)
209 {
210 if (parameterMap_.find(Constants::PARAM_OUT_PATH) == parameterMap_.end()) {
211 LOGE("input out-path are null.");
212 return false;
213 }
214 outPath = parameterMap_.at(Constants::PARAM_OUT_PATH);
215 if (outPath.empty()) {
216 LOGE("input out-path are empty.");
217 return false;
218 }
219 if (outPath.find('.') == std::string::npos ||
220 outPath.substr(outPath.size() - Constants::APP_SUFFIX_LENGTH) != Constants::APP_SUFFIX) {
221 LOGE("out-path must end with .app.");
222 return false;
223 }
224 return true;
225 }
226
GetAndCheckHapPathAndHspPath(std::string & hapPath,std::string & hspPath)227 bool AppPackager::GetAndCheckHapPathAndHspPath(std::string &hapPath, std::string &hspPath)
228 {
229 if (parameterMap_.find(Constants::PARAM_HAP_PATH) == parameterMap_.end() &&
230 parameterMap_.find(Constants::PARAM_HSP_PATH) == parameterMap_.end()) {
231 LOGE("input hap-path or hsp-path are all null.");
232 return false;
233 }
234 if (parameterMap_.find(Constants::PARAM_HAP_PATH) != parameterMap_.end()) {
235 hapPath = parameterMap_.at(Constants::PARAM_HAP_PATH);
236 }
237 if (parameterMap_.find(Constants::PARAM_HSP_PATH) != parameterMap_.end()) {
238 hspPath = parameterMap_.at(Constants::PARAM_HSP_PATH);
239 }
240 if (hapPath.empty() && hspPath.empty()) {
241 LOGE("input hap-path or hsp-path are all empty.");
242 return false;
243 }
244 if (!CheckBundleTypeConsistency(hapPath, hspPath)) {
245 LOGE("bundleType is inconsistent.");
246 return false;
247 }
248 if (!CheckInputModulePath(hapPath, hspPath)) {
249 LOGE("input hap-path or hsp-path is invalid.");
250 }
251 if (!hapPath.empty() && !CompatibleProcess(hapPath, formattedHapPathList_, Constants::HAP_SUFFIX)) {
252 LOGE("hap-path is invalid.");
253 return false;
254 }
255 if (!hspPath.empty() && !CompatibleProcess(hspPath, formattedHspPathList_, Constants::HSP_SUFFIX)) {
256 LOGE("hsp-path is invalid.");
257 return false;
258 }
259 return true;
260 }
261
GetAndCheckPackInfoPath(std::string & packInfoPath)262 bool AppPackager::GetAndCheckPackInfoPath(std::string &packInfoPath)
263 {
264 if (parameterMap_.find(Constants::PARAM_PACK_INFO_PATH) == parameterMap_.end()) {
265 LOGE("input pack-info-path is null.");
266 return false;
267 }
268 packInfoPath = parameterMap_.at(Constants::PARAM_PACK_INFO_PATH);
269 if (packInfoPath.empty()) {
270 LOGE("input pack-info-path is empty.");
271 return false;
272 }
273 if (!fs::is_regular_file(packInfoPath) || fs::path(packInfoPath).filename() != Constants::PACK_INFO) {
274 LOGE("pack-info-path is invalid.");
275 return false;
276 }
277 return true;
278 }
279
CheckSignaturePath()280 bool AppPackager::CheckSignaturePath()
281 {
282 auto it = parameterMap_.find(Constants::PARAM_SIGNATURE_PATH);
283 if (it != parameterMap_.end() && !it->second.empty()) {
284 if (!fs::is_regular_file(it->second)) {
285 LOGE("signature-path is invalid.");
286 return false;
287 }
288 }
289 return true;
290 }
291
CheckCertificatePath()292 bool AppPackager::CheckCertificatePath()
293 {
294 auto it = parameterMap_.find(Constants::PARAM_CERTIFICATE_PATH);
295 if (it != parameterMap_.end() && !it->second.empty()) {
296 if (!fs::is_regular_file(it->second)) {
297 LOGE("certificate-path is invalid.");
298 return false;
299 }
300 }
301 return true;
302 }
303
CheckEntrycardPath()304 bool AppPackager::CheckEntrycardPath()
305 {
306 auto it = parameterMap_.find(Constants::PARAM_ENTRYCARD_PATH);
307 if (it != parameterMap_.end() && !it->second.empty()) {
308 if (!CompatibleProcess(it->second, formattedEntryCardPathList_, Constants::PNG_SUFFIX)) {
309 LOGE("entrycard-path is invalid.");
310 return false;
311 }
312 }
313 return true;
314 }
315
CheckPackResPath()316 bool AppPackager::CheckPackResPath()
317 {
318 auto it = parameterMap_.find(Constants::PARAM_PACK_RES_PATH);
319 if (it != parameterMap_.end() && !it->second.empty()) {
320 if (!IsPathValid(it->second, true, Constants::FILE_PACK_RES)) {
321 LOGE("pack-res-path is invalid.");
322 return false;
323 }
324 }
325 return true;
326 }
327
CheckPacJsonPath()328 bool AppPackager::CheckPacJsonPath()
329 {
330 auto it = parameterMap_.find(Constants::PARAM_PAC_JSON_PATH);
331 if (it != parameterMap_.end() && !it->second.empty()) {
332 if (!IsFileMatch(it->second, Constants::PAC_JSON)) {
333 LOGE("pac-json-path is invalid.");
334 return false;
335 }
336 }
337 return true;
338 }
339
IsVerifyValidInAppMode()340 bool AppPackager::IsVerifyValidInAppMode()
341 {
342 std::string hapPath;
343 std::string hspPath;
344 if (!GetAndCheckHapPathAndHspPath(hapPath, hspPath)) {
345 LOGE("GetAndCheckHapPathAndHspPath failed!");
346 return false;
347 }
348
349 std::string packInfoPath;
350 if (!GetAndCheckPackInfoPath(packInfoPath)) {
351 LOGE("GetAndCheckPackInfoPath failed!");
352 return false;
353 }
354
355 if (!CheckSignaturePath() || !CheckCertificatePath() || !CheckEntrycardPath() || !CheckPackResPath()) {
356 LOGE("CheckSignaturePath or CheckCertificatePath or CheckEntrycardPath or CheckPackResPath failed!");
357 return false;
358 }
359
360 if (!CheckPacJsonPath()) {
361 LOGE("CheckPacJsonPath failed!");
362 return false;
363 }
364
365 std::string outPath;
366 if (!GetAndCheckOutPath(outPath)) {
367 LOGE("GetAndCheckOutPath failed!");
368 return false;
369 }
370 std::string force;
371 if (parameterMap_.find(Constants::PARAM_FORCE) != parameterMap_.end()) {
372 force = parameterMap_.at(Constants::PARAM_FORCE);
373 }
374 return IsOutPathValid(outPath, force, Constants::APP_SUFFIX);
375 }
376
PrepareDirectoriesAndFiles(const std::string outPath)377 bool AppPackager::PrepareDirectoriesAndFiles(const std::string outPath)
378 {
379 fs::path tempPath;
380 fs::path hspTempDirPath;
381 if (fs::exists(fs::path(outPath).parent_path().parent_path()) &&
382 fs::path(outPath).parent_path().parent_path() != fs::path("/")) {
383 tempPath = fs::path(outPath).parent_path().parent_path() / ((Constants::COMPRESSOR_APP_TEMP_DIR) +
384 Utils::GenerateUUID());
385 hspTempDirPath = fs::path(outPath).parent_path().parent_path() / ((Constants::COMPRESSOR_APP_TEMP_DIR) +
386 Utils::GenerateUUID());
387 } else {
388 tempPath = fs::path(outPath).parent_path() / ((Constants::COMPRESSOR_APP_TEMP_DIR) +
389 Utils::GenerateUUID());
390 hspTempDirPath = fs::path(outPath).parent_path() / ((Constants::COMPRESSOR_APP_TEMP_DIR) +
391 Utils::GenerateUUID());
392 }
393 if (!fs::exists(tempPath)) {
394 fs::create_directories(tempPath);
395 }
396 if (!fs::exists(hspTempDirPath)) {
397 fs::create_directories(hspTempDirPath);
398 }
399 if (!CompressHapAndHspFiles(tempPath, hspTempDirPath)) {
400 if (fs::exists(tempPath)) {
401 fs::remove_all(tempPath);
402 }
403 if (fs::exists(hspTempDirPath)) {
404 fs::remove_all(hspTempDirPath);
405 }
406 LOGE("AppPackager::CompressHapAndHspFiles failed.");
407 return false;
408 }
409 return true;
410 }
411
CompressHapAndHspFiles(const fs::path & tempPath,const fs::path & hspTempDirPath)412 bool AppPackager::CompressHapAndHspFiles(const fs::path &tempPath, const fs::path &hspTempDirPath)
413 {
414 std::map<std::string, std::string>::const_iterator it = parameterMap_.find(Constants::PARAM_HAP_PATH);
415 std::list<std::string> fileList;
416 if (it != parameterMap_.end()) {
417 for (const auto& hapPathItem : formattedHapPathList_) {
418 fs::path hapFile = hapPathItem;
419 fs::path hapTempPath = tempPath / hapFile.filename();
420 fs::path hapUnzipTempPath = tempPath / ((Constants::COMPRESSOR_APP_TEMP_DIR) +
421 Utils::GenerateUUID());
422 fileList.push_back(hapTempPath.string());
423 it = parameterMap_.find(Constants::PARAM_PACK_INFO_PATH);
424 if (it != parameterMap_.end()) {
425 CompressPackinfoIntoHap(hapPathItem, hapUnzipTempPath, hapTempPath.string(), it->second);
426 }
427 }
428 }
429 it = parameterMap_.find(Constants::PARAM_HSP_PATH);
430 if (it != parameterMap_.end()) {
431 for (const auto& hspPathItem : formattedHspPathList_) {
432 fs::path hspFile = hspPathItem;
433 fs::path hspTempPath = hspTempDirPath / hspFile.filename();
434 fs::path hspUnzipTempPath = tempPath / ((Constants::COMPRESSOR_APP_TEMP_DIR) +
435 Utils::GenerateUUID());
436 fileList.push_back(hspTempPath.string());
437 it = parameterMap_.find(Constants::PARAM_PACK_INFO_PATH);
438 if (it != parameterMap_.end()) {
439 CompressPackinfoIntoHap(hspPathItem, hspUnzipTempPath, hspTempPath.string(), it->second);
440 }
441 }
442 }
443 if (!ModuleJsonUtils::CheckHapsIsValid(fileList, isSharedApp_)) {
444 LOGE("AppPackager::CheckHapsIsValid verify failed.");
445 return false;
446 }
447 if (!ModuleJsonUtils::GetHapVerifyInfosMapfromFileList(fileList, hapVerifyInfoMap_)) {
448 LOGE("AppPackager::GetHapVerifyInfosMapfromFileList failed.");
449 return false;
450 }
451 if (!AddHapListToApp(fileList)) {
452 zipWrapper_.SetZipLevel(ZipLevel::ZIP_LEVEL_DEFAULT);
453 LOGE("AppPackager::AddHapListToApp failed.");
454 return false;
455 }
456 if (fs::exists(tempPath)) {
457 fs::remove_all(tempPath);
458 }
459 if (fs::exists(hspTempDirPath)) {
460 fs::remove_all(hspTempDirPath);
461 }
462 return true;
463 }
464
AddHapListToApp(const std::list<std::string> & fileList)465 bool AppPackager::AddHapListToApp(const std::list<std::string> &fileList)
466 {
467 for (const auto& hapPath : fileList) {
468 HapVerifyInfo hapVerifyInfo;
469 if (ModuleJsonUtils::IsModuleHap(hapPath)) {
470 if (!ModuleJsonUtils::GetStageHapVerifyInfo(hapPath, hapVerifyInfo)) {
471 LOGW("GetStageHapVerifyInfo failed! hapPath:%s", hapPath.c_str());
472 }
473 } else {
474 if (!ModuleJsonUtils::GetFaHapVerifyInfo(hapPath, hapVerifyInfo)) {
475 LOGW("GetFaHapVerifyInfo failed! hapPath:%s", hapPath.c_str());
476 }
477 }
478 if (hapVerifyInfo.IsDebug()) {
479 zipWrapper_.SetZipLevel(ZipLevel::ZIP_LEVEL_0);
480 }
481 zipWrapper_.SetZipMethod(ZipMethod::ZIP_METHOD_DEFLATED);
482 if (zipWrapper_.AddFileOrDirectoryToZip(hapPath, fs::path(hapPath).filename().string()) !=
483 ZipErrCode::ZIP_ERR_SUCCESS) {
484 zipWrapper_.SetZipLevel(ZipLevel::ZIP_LEVEL_DEFAULT);
485 zipWrapper_.SetZipMethod(ZipMethod::ZIP_METHOD_STORED);
486 LOGE("AppPackager::Process: zipWrapper AddFileOrDirectoryToZip failed!");
487 return false;
488 }
489 zipWrapper_.SetZipLevel(ZipLevel::ZIP_LEVEL_DEFAULT);
490 zipWrapper_.SetZipMethod(ZipMethod::ZIP_METHOD_STORED);
491 }
492 return true;
493 }
494
CompressOtherFiles()495 bool AppPackager::CompressOtherFiles()
496 {
497 std::string moduleName;
498 std::map<std::string, std::string>::const_iterator it = parameterMap_.find(Constants::PARAM_ENTRYCARD_PATH);
499 if (it != parameterMap_.end() && !it->second.empty()) {
500 std::string entryCardPath = Constants::ENTRYCARD_NAME + Constants::LINUX_FILE_SEPARATOR +
501 moduleName + Constants::LINUX_FILE_SEPARATOR +
502 Constants::ENTRYCARD_BASE_NAME + Constants::LINUX_FILE_SEPARATOR +
503 Constants::ENTRYCARD_SNAPSHOT_NAME + Constants::LINUX_FILE_SEPARATOR;
504 for (auto itemFormattedEntryCardPath : formattedEntryCardPathList_) {
505 if (zipWrapper_.AddFileOrDirectoryToZip(itemFormattedEntryCardPath, entryCardPath +
506 fs::path(itemFormattedEntryCardPath).filename().string()) !=
507 ZipErrCode::ZIP_ERR_SUCCESS) {
508 return false;
509 }
510 }
511 }
512 it = parameterMap_.find(Constants::PARAM_PACK_INFO_PATH);
513 if (it != parameterMap_.end()) {
514 if (zipWrapper_.AddFileOrDirectoryToZip(it->second, Constants::PACK_INFO) != ZipErrCode::ZIP_ERR_SUCCESS) {
515 return false;
516 }
517 }
518 it = parameterMap_.find(Constants::PARAM_SIGNATURE_PATH);
519 if (it != parameterMap_.end()) {
520 std::string zipPath = Constants::NULL_DIR_NAME;
521 zipPath = fs::path(it->second).filename().string();
522 if (zipWrapper_.AddFileOrDirectoryToZip(it->second, zipPath) != ZipErrCode::ZIP_ERR_SUCCESS) {
523 return false;
524 }
525 }
526 it = parameterMap_.find(Constants::PARAM_CERTIFICATE_PATH);
527 if (it != parameterMap_.end()) {
528 std::string zipPath = Constants::NULL_DIR_NAME;
529 zipPath = fs::path(it->second).filename().string();
530 if (zipWrapper_.AddFileOrDirectoryToZip(it->second, zipPath) != ZipErrCode::ZIP_ERR_SUCCESS) {
531 return false;
532 }
533 }
534 it = parameterMap_.find(Constants::PARAM_PAC_JSON_PATH);
535 if (it != parameterMap_.end()) {
536 if (zipWrapper_.AddFileOrDirectoryToZip(it->second, Constants::PAC_JSON) != ZipErrCode::ZIP_ERR_SUCCESS) {
537 LOGE("AppPackager::CompressOtherFiles: zipWrapper pac.json failed!");
538 return false;
539 }
540 }
541 return true;
542 }
543
CompressAppMode()544 bool AppPackager::CompressAppMode()
545 {
546 std::string outPath;
547 if (parameterMap_.find(Constants::PARAM_OUT_PATH) != parameterMap_.end()) {
548 outPath = parameterMap_.at(Constants::PARAM_OUT_PATH);
549 }
550 zipWrapper_.Open(outPath);
551 if (!zipWrapper_.IsOpen()) {
552 LOGE("AppPackager::CompressAppMode: zipWrapper Open failed!");
553 return ERR_INVALID_VALUE;
554 }
555 if (!PrepareDirectoriesAndFiles(outPath)) {
556 return false;
557 }
558 if (!CompressOtherFiles()) {
559 return false;
560 }
561 std::map<std::string, std::string>::const_iterator it = parameterMap_.find(Constants::PARAM_PACK_RES_PATH);
562 if (it != parameterMap_.end()) {
563 std::string zipPath = Constants::NULL_DIR_NAME;
564 zipPath = fs::path(it->second).filename().string();
565 if (zipWrapper_.AddFileOrDirectoryToZip(it->second, zipPath) != ZipErrCode::ZIP_ERR_SUCCESS) {
566 return false;
567 }
568 }
569 zipWrapper_.Close();
570 if (!ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid(parameterMap_, hapVerifyInfoMap_)) {
571 LOGE("AppPackager::CompressAppMode: CheckAppAtomicServiceCompressedSizeValid() failed!");
572 return false;
573 }
574 return true;
575 }
576 } // namespace AppPackingTool
577 } // namespace OHOS