LCOV - code coverage report
Current view: top level - basic_component/package_manager/src - package_worker_utils.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.7 % 30 29
Test Date: 2026-07-28 10:52:48 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : #include "package_worker_utils.h"
      11              : 
      12              : #include <sys/stat.h>
      13              : #include <fstream>
      14              : #include <sstream>
      15              : #include "mmpa/mmpa_api.h"
      16              : #include "tsd_log.h"
      17              : #include "tsd_util_func.h"
      18              : #include "package_verify.h"
      19              : #include "tsd_path_mgr.h"
      20              : 
      21              : namespace tsd {
      22            1 : TSD_StatusT PackageWorkerUtils::VerifyPackage(const std::string& pkgPath)
      23              : {
      24            1 :     const PackageVerify pkgVerify(pkgPath);
      25            1 :     const TSD_StatusT ret = pkgVerify.VerifyPackage();
      26            1 :     if (ret != TSD_OK) {
      27            1 :         TSD_ERROR("Verify package failed, ret=%u, path=%s", ret, pkgPath.c_str());
      28            1 :         return TSD_VERIFY_OPP_FAIL;
      29              :     }
      30              : 
      31            0 :     return TSD_OK;
      32            1 : }
      33              : 
      34           14 : TSD_StatusT PackageWorkerUtils::MakeDirectory(const std::string& dirPath)
      35              : {
      36           14 :     if (dirPath.empty()) {
      37            1 :         TSD_ERROR("Dir path is empty");
      38            1 :         return TSD_INTERNAL_ERROR;
      39              :     }
      40              : 
      41           13 :     int32_t ret = access(dirPath.c_str(), F_OK);
      42           13 :     if (ret == 0) {
      43            4 :         ret = mmIsDir(dirPath.c_str());
      44            4 :         if (ret != EN_OK) {
      45            1 :             TSD_ERROR(
      46              :                 "File exist but not is a dir, ret=%d, path=%s, reason=%s", ret, dirPath.c_str(),
      47              :                 SafeStrerror().c_str());
      48            1 :             return TSD_INTERNAL_ERROR;
      49              :         }
      50            3 :         return TSD_OK;
      51              :     }
      52              : 
      53            9 :     ret = mkdir(dirPath.c_str(), (S_IRWXU | S_IRGRP | S_IXGRP));
      54            9 :     if (ret != 0) {
      55            1 :         TSD_ERROR("Create dir failed, ret=%d, path=%s, reason=%s", ret, dirPath.c_str(), SafeStrerror().c_str());
      56            1 :         return TSD_INTERNAL_ERROR;
      57              :     }
      58              : 
      59              :     // chmod is necessary, because mkdir cannot really change mode in rc
      60            8 :     ret = chmod(dirPath.c_str(), (S_IRWXU | S_IRGRP | S_IXGRP));
      61            8 :     if (ret != 0) {
      62            1 :         TSD_ERROR("Change dir mode failed, ret=%d, path=%s, reason=%s", ret, dirPath.c_str(), SafeStrerror().c_str());
      63            1 :         return TSD_INTERNAL_ERROR;
      64              :     }
      65              : 
      66            7 :     return TSD_OK;
      67              : }
      68              : 
      69           10 : void PackageWorkerUtils::RemoveFile(const std::string& filePath) { RemoveOneFile(filePath); }
      70              : 
      71           30 : uint64_t PackageWorkerUtils::GetFileSize(const std::string& filePath) { return CalFileSize(filePath.c_str()); }
      72              : 
      73              : } // namespace tsd
        

Generated by: LCOV version 2.0-1