mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-23 07:00:17 +00:00
!1021 native包支持opt参数输入,打包新增json配置文件
Merge pull request !1021 from 王达/native_opt_update
This commit is contained in:
commit
d5c6ff9a69
@ -25,6 +25,11 @@ typedef enum {
|
||||
TRUE
|
||||
} Bool;
|
||||
|
||||
typedef enum {
|
||||
OPTION_INDEX_FORCE = 0, /* installed forcely */
|
||||
OPTION_INDEX_BUTT
|
||||
} HnpInstallOptionIndex;
|
||||
|
||||
#define HNP_API_ERRNO_BASE 0x2000
|
||||
|
||||
// 0x2001 参数非法
|
||||
@ -40,12 +45,15 @@ typedef enum {
|
||||
* Install native software package.
|
||||
*
|
||||
* @param userId Indicates id of user.
|
||||
* @param hnpPath Indicates the directory path of hnp file.
|
||||
* @param isForce Indicates whether to force install.
|
||||
* @param packages Indicates the path of hnp file.
|
||||
* @param count Indicates num of hnp file.
|
||||
* @param installPath Indicates the path for private hnp file.
|
||||
* @param installOptions Indicates install options.
|
||||
*
|
||||
* @return 0:success;other means failure.
|
||||
*/
|
||||
int NativeInstallHnp(const char *userId, const char *hnpPath, const char *packageName, Bool isForce);
|
||||
int NativeInstallHnp(const char *userId, const char *packages[], int count, const char *installPath,
|
||||
int installOptions);
|
||||
|
||||
/**
|
||||
* Uninstall native software package.
|
||||
@ -53,10 +61,11 @@ int NativeInstallHnp(const char *userId, const char *hnpPath, const char *packag
|
||||
* @param userId Indicates id of user.
|
||||
* @param hnpName Indicates the name of native software.
|
||||
* @param hnpVersion Indicates the version of native software.
|
||||
* @param installPath Indicates the path for private hnp file.
|
||||
*
|
||||
* @return 0:success;other means failure.
|
||||
*/
|
||||
int NativeUnInstallHnp(const char *userId, const char *hnpName, const char *hnpVersion, const char *packageName);
|
||||
int NativeUnInstallHnp(const char *userId, const char *hnpName, const char *hnpVersion, const char *installPath);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ extern "C" {
|
||||
HILOG_INFO(LOG_CORE, "[%{public}s:%{public}d]" fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
|
||||
#define MAX_ARGV_NUM 256
|
||||
#define MAX_ENV_NUM (128 + 2)
|
||||
#define IS_OPTION_SET(x, option) ((x) & (1 << (option)))
|
||||
|
||||
/* 数字索引 */
|
||||
enum {
|
||||
@ -56,7 +57,7 @@ static int StartHnpProcess(char *const argv[], char *const apcEnv[])
|
||||
return HNP_API_ERRNO_FORK_FAILED;
|
||||
} else if (pid == 0) {
|
||||
HNPAPI_LOG("\r\n [HNP API] this is fork children!\r\n");
|
||||
ret = execve("./hnp", argv, apcEnv);
|
||||
ret = execve("/system/bin/hnp", argv, apcEnv);
|
||||
if (ret < 0) {
|
||||
HNPAPI_LOG("\r\n [HNP API] execve unsuccess!\r\n");
|
||||
_exit(-1);
|
||||
@ -81,40 +82,46 @@ static int StartHnpProcess(char *const argv[], char *const apcEnv[])
|
||||
return exitVal;
|
||||
}
|
||||
|
||||
int NativeInstallHnp(const char *userId, const char *hnpPath, const char *packageName, Bool isForce)
|
||||
int NativeInstallHnp(const char *userId, const char *packages[], int count, const char *installPath, int installOptions)
|
||||
{
|
||||
char *argv[MAX_ARGV_NUM] = {0};
|
||||
char *apcEnv[MAX_ENV_NUM] = {0};
|
||||
int index = 0;
|
||||
|
||||
if ((userId == NULL) || (hnpPath == NULL))) {
|
||||
if ((userId == NULL) || (packages == NULL) || (count == 0)) {
|
||||
return HNP_API_ERRNO_PARAM_INVALID;
|
||||
}
|
||||
|
||||
HNPAPI_LOG("\r\n [HNP API] native package install! userId=%s, hnpPath=%s, IsForce=%d\r\n",
|
||||
userId, hnpPath, isForce);
|
||||
HNPAPI_LOG("\r\n [HNP API] native package install! userId=%s, hnpPath count=%d, install path=%s "
|
||||
"install options=%d\r\n", userId, count, installPath, installOptions);
|
||||
|
||||
argv[HNP_INDEX_0] = "hnp";
|
||||
argv[HNP_INDEX_1] = "install";
|
||||
argv[HNP_INDEX_2] = (char*)userId;
|
||||
argv[HNP_INDEX_3] = (char*)hnpPath;
|
||||
argv[index++] = "hnp";
|
||||
argv[index++] = "install";
|
||||
argv[index++] = "-u";
|
||||
argv[index++] = (char*)userId;
|
||||
|
||||
if (packageName == NULL) {
|
||||
argv[HNP_INDEX_4] = "null";
|
||||
} else {
|
||||
argv[HNP_INDEX_4] = (char*)packageName;
|
||||
for (int i = 0; i < count; i++) {
|
||||
argv[index++] = "-p";
|
||||
argv[index++] = (char*)packages[i];
|
||||
}
|
||||
|
||||
if (isForce == TRUE) {
|
||||
argv[HNP_INDEX_5] = "-f";
|
||||
if (installPath != NULL) {
|
||||
argv[index++] = "-i";
|
||||
argv[index++] = (char*)installPath;
|
||||
}
|
||||
|
||||
if (IS_OPTION_SET(installOptions, OPTION_INDEX_FORCE)) {
|
||||
argv[index++] = "-f";
|
||||
}
|
||||
|
||||
return StartHnpProcess(argv, apcEnv);
|
||||
}
|
||||
|
||||
int NativeUnInstallHnp(const char *userId, const char *hnpName, const char *hnpVersion, const char *packageName)
|
||||
int NativeUnInstallHnp(const char *userId, const char *hnpName, const char *hnpVersion, const char *installPath)
|
||||
{
|
||||
char *argv[MAX_ARGV_NUM] = {0};
|
||||
char *apcEnv[MAX_ENV_NUM] = {0};
|
||||
int index = 0;
|
||||
|
||||
if ((userId == NULL) || (hnpName == NULL) || (hnpVersion == NULL)) {
|
||||
return HNP_API_ERRNO_PARAM_INVALID;
|
||||
@ -123,16 +130,18 @@ int NativeUnInstallHnp(const char *userId, const char *hnpName, const char *hnpV
|
||||
HNPAPI_LOG("\r\n [HNP API] native package uninstall! userId=%s, hnpName=%s, hnpVersion=%s\r\n",
|
||||
userId, hnpName, hnpVersion);
|
||||
|
||||
argv[HNP_INDEX_0] = "hnp";
|
||||
argv[HNP_INDEX_1] = "uninstall";
|
||||
argv[HNP_INDEX_2] = (char*)userId;
|
||||
argv[HNP_INDEX_3] = (char*)hnpName;
|
||||
argv[HNP_INDEX_4] = (char*)hnpVersion;
|
||||
argv[index++] = "hnp";
|
||||
argv[index++] = "uninstall";
|
||||
argv[index++] = "-u";
|
||||
argv[index++] = (char*)userId;
|
||||
argv[index++] = "-n";
|
||||
argv[index++] = (char*)hnpName;
|
||||
argv[index++] = "-v";
|
||||
argv[index++] = (char*)hnpVersion;
|
||||
|
||||
if (packageName == NULL) {
|
||||
argv[HNP_INDEX_5] = "null";
|
||||
} else {
|
||||
argv[HNP_INDEX_5] = (char*)packageName;
|
||||
if (installPath != NULL) {
|
||||
argv[index++] = "-i";
|
||||
argv[index++] = (char*)installPath;
|
||||
}
|
||||
|
||||
return StartHnpProcess(argv, apcEnv);
|
||||
|
@ -21,6 +21,7 @@ if (!defined(ohos_lite)) {
|
||||
]
|
||||
sources = [
|
||||
"${appspawn_path}/service/hnp/base/hnp_file.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_json.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_log.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_sal.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_zip.c",
|
||||
@ -47,6 +48,7 @@ if (!defined(ohos_lite)) {
|
||||
]
|
||||
sources = [
|
||||
"${appspawn_path}/service/hnp/base/hnp_file.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_json.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_log.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_zip.c",
|
||||
"${appspawn_path}/service/hnp/hnpcli_main.c",
|
||||
|
@ -29,12 +29,13 @@ extern "C" {
|
||||
|
||||
#define MAX_FILE_PATH_LEN PATH_MAX
|
||||
|
||||
#define HNP_HEAD_MAGIC 0x12345678
|
||||
#define HNP_HEAD_VERSION 1
|
||||
#define HNP_VERSION_LEN 32
|
||||
#define BUFFER_SIZE 1024
|
||||
#define HNP_COMMAND_LEN 128
|
||||
#define MAX_PROCESSES 32
|
||||
#define MAX_SOFTWARE_NUM 32
|
||||
|
||||
#define HNP_CFG_FILE_NAME "hnp.json"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define DIR_SPLIT_SYMBOL '\\'
|
||||
@ -48,16 +49,13 @@ typedef struct NativeBinLinkStru {
|
||||
char target[MAX_FILE_PATH_LEN];
|
||||
} NativeBinLink;
|
||||
|
||||
/* hnp文件头结构 */
|
||||
typedef struct NativeHnpHeadStru {
|
||||
unsigned int magic; // 魔术字校验
|
||||
unsigned int version; // 版本号
|
||||
unsigned int headLen; // hnp结构头大小
|
||||
unsigned int reserve; // 预留字段
|
||||
char hnpVersion[HNP_VERSION_LEN]; // Native软件包版本号
|
||||
/* hnp配置文件信息 */
|
||||
typedef struct HnpCfgInfoStru {
|
||||
char name[MAX_FILE_PATH_LEN];
|
||||
char version[HNP_VERSION_LEN]; // Native软件包版本号
|
||||
unsigned int linkNum; // 软链接配置个数
|
||||
NativeBinLink links[0];
|
||||
} NativeHnpHead;
|
||||
NativeBinLink *links;
|
||||
} HnpCfgInfo;
|
||||
|
||||
/* 日志级别 */
|
||||
typedef enum {
|
||||
@ -100,6 +98,9 @@ enum {
|
||||
// 0x801001 操作类型非法
|
||||
#define HNP_ERRNO_OPERATOR_TYPE_INVALID HNP_ERRNO_COMMON(HNP_MID_MAIN, 0x1)
|
||||
|
||||
// 0x801002 缺少必要的操作参数
|
||||
#define HNP_ERRNO_OPERATOR_ARGV_MISS HNP_ERRNO_COMMON(HNP_MID_MAIN, 0x2)
|
||||
|
||||
/* hnp_base模块*/
|
||||
// 0x801101 打开文件失败
|
||||
#define HNP_ERRNO_BASE_FILE_OPEN_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x1)
|
||||
@ -140,47 +141,50 @@ enum {
|
||||
// 0x80110d 获取文件属性失败
|
||||
#define HNP_ERRNO_GET_FILE_ATTR_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0xd)
|
||||
|
||||
// 0x80110e 魔术字校验失败
|
||||
#define HNP_ERRNO_BASE_MAGIC_CHECK_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0xe)
|
||||
// 0x80110e 解压缩打开文件失败
|
||||
#define HNP_ERRNO_BASE_UNZIP_OPEN_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0xe)
|
||||
|
||||
// 0x80110f 解压缩打开文件失败
|
||||
#define HNP_ERRNO_BASE_UNZIP_OPEN_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0xf)
|
||||
// 0x80110f 解压缩获取文件信息失败
|
||||
#define HNP_ERRNO_BASE_UNZIP_GET_INFO_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0xf)
|
||||
|
||||
// 0x801110 解压缩获取文件信息失败
|
||||
#define HNP_ERRNO_BASE_UNZIP_GET_INFO_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x10)
|
||||
#define HNP_ERRNO_BASE_UNZIP_READ_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x10)
|
||||
|
||||
// 0x801111 解压缩获取文件信息失败
|
||||
#define HNP_ERRNO_BASE_UNZIP_READ_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x11)
|
||||
// 0x801111 生成软链接失败
|
||||
#define HNP_ERRNO_GENERATE_SOFT_LINK_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x11)
|
||||
|
||||
// 0x801112 生成软链接失败
|
||||
#define HNP_ERRNO_GENERATE_SOFT_LINK_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x12)
|
||||
// 0x801112 进程正在运行
|
||||
#define HNP_ERRNO_PROCESS_RUNNING HNP_ERRNO_COMMON(HNP_MID_BASE, 0x12)
|
||||
|
||||
// 0x801113 进程正在运行
|
||||
#define HNP_ERRNO_PROGRAM_RUNNING HNP_ERRNO_COMMON(HNP_MID_BASE, 0x13)
|
||||
// 0x801113 入参失败
|
||||
#define HNP_ERRNO_BASE_PARAMS_INVALID HNP_ERRNO_COMMON(HNP_MID_BASE, 0x13)
|
||||
|
||||
// 0x801114 打开管道失败
|
||||
#define HNP_ERRNO_BASE_POPEN_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x14)
|
||||
// 0x801114 strdup失败
|
||||
#define HNP_ERRNO_BASE_STRDUP_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x14)
|
||||
|
||||
// 0x801115 入参失败
|
||||
#define HNP_ERRNO_BASE_PARAMS_INVALID HNP_ERRNO_COMMON(HNP_MID_BASE, 0x15)
|
||||
// 0x801115 设置权限失败
|
||||
#define HNP_ERRNO_BASE_CHMOD_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x15)
|
||||
|
||||
// 0x801116 strdup失败
|
||||
#define HNP_ERRNO_BASE_STRDUP_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x16)
|
||||
// 0x801116 删除目录失败
|
||||
#define HNP_ERRNO_BASE_UNLINK_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x16)
|
||||
|
||||
// 0x801117 设置权限失败
|
||||
#define HNP_ERRNO_BASE_CHMOD_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x17)
|
||||
// 0x801117 对应进程不存在
|
||||
#define HNP_ERRNO_BASE_PROCESS_NOT_FOUND HNP_ERRNO_COMMON(HNP_MID_BASE, 0x17)
|
||||
|
||||
// 0x801118 删除目录失败
|
||||
#define HNP_ERRNO_BASE_UNLINK_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x18)
|
||||
// 0x801118 创建路径失败
|
||||
#define HNP_ERRNO_BASE_MKDIR_PATH_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x18)
|
||||
|
||||
// 0x801119 对应进程不存在
|
||||
#define HNP_ERRNO_BASE_PROGRAM_NOT_FOUND HNP_ERRNO_COMMON(HNP_MID_BASE, 0x19)
|
||||
// 0x801119 读取配置文件流失败
|
||||
#define HNP_ERRNO_BASE_READ_FILE_STREAM_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x19)
|
||||
|
||||
// 0x80111a 进程超过最大值
|
||||
#define HNP_ERRNO_BASE_PROGRAM_NUM_OVERSIZE HNP_ERRNO_COMMON(HNP_MID_BASE, 0x1a)
|
||||
// 0x80111a 解析json信息失败
|
||||
#define HNP_ERRNO_BASE_PARSE_JSON_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x1a)
|
||||
|
||||
// 0x80111b 创建路径失败
|
||||
#define HNP_ERRNO_BASE_MKDIR_PATH_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x1b)
|
||||
// 0x80111b 未找到json项
|
||||
#define HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND HNP_ERRNO_COMMON(HNP_MID_BASE, 0x1b)
|
||||
|
||||
// 0x80111c 解析json数组失败
|
||||
#define HNP_ERRNO_BASE_GET_ARRAY_ITRM_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x1c)
|
||||
|
||||
int GetFileSizeByHandle(FILE *file, int *size);
|
||||
|
||||
@ -194,15 +198,15 @@ int HnpZip(const char *inputDir, const char *outputFile);
|
||||
|
||||
int HnpUnZip(const char *inputFile, const char *outputDir);
|
||||
|
||||
int HnpWriteToZipHead(const char *zipFile, char *buff, int len);
|
||||
int HnpAddFileToZip(char *zipfile, char *filename, char *buff, int size);
|
||||
|
||||
void HnpLogPrintf(int logLevel, char *module, const char *format, ...);
|
||||
|
||||
int HnpReadFromZipHead(const char *zipFile, NativeHnpHead **hnpHead);
|
||||
int HnpCfgGetFromZip(const char *inputFile, HnpCfgInfo *hnpCfg);
|
||||
|
||||
int HnpSymlink(const char *srcFile, const char *dstFile);
|
||||
|
||||
int HnpProgramRunCheck(const char *binName, const char *runPath);
|
||||
int HnpProcessRunCheck(const char *runPath);
|
||||
|
||||
int HnpDeleteFolder(const char *path);
|
||||
|
||||
@ -210,6 +214,12 @@ int HnpCreateFolder(const char* path);
|
||||
|
||||
int HnpWriteInfoToFile(const char* filePath, char *buff, int len);
|
||||
|
||||
int ParseHnpCfgFile(const char *hnpCfgPath, HnpCfgInfo *hnpCfg);
|
||||
|
||||
int GetHnpJsonBuff(HnpCfgInfo *hnpCfg, char **buff);
|
||||
|
||||
int HnpCfgGetFromSteam(char *cfgStream, HnpCfgInfo *hnpCfg);
|
||||
|
||||
#define HNP_LOGI(args...) \
|
||||
HnpLogPrintf(HNP_LOG_INFO, "HNP", ##args)
|
||||
|
||||
|
@ -75,6 +75,7 @@ int ReadFileToStream(const char *filePath, char **stream, int *streamLen)
|
||||
}
|
||||
if (size == 0) {
|
||||
HNP_LOGE("get file[%s] size is null.", filePath);
|
||||
(void)fclose(file);
|
||||
return HNP_ERRNO_BASE_GET_FILE_LEN_NULL;
|
||||
}
|
||||
streamTmp = (char*)malloc(size);
|
||||
|
184
service/hnp/base/hnp_json.c
Normal file
184
service/hnp/base/hnp_json.c
Normal file
@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "securec.h"
|
||||
|
||||
#include "hnp_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static int ParseLinksJsonToCfgInfo(cJSON *linksItem, HnpCfgInfo *hnpCfg)
|
||||
{
|
||||
NativeBinLink *linkArray = NULL;
|
||||
|
||||
int linkArrayNum = cJSON_GetArraySize(linksItem);
|
||||
if (linkArrayNum > 0) {
|
||||
hnpCfg->linkNum = linkArrayNum;
|
||||
linkArray = (NativeBinLink*)malloc(sizeof(NativeBinLink) * linkArrayNum);
|
||||
if (linkArray == NULL) {
|
||||
HNP_LOGE("malloc unsuccess.");
|
||||
return HNP_ERRNO_NOMEM;
|
||||
}
|
||||
for (int i = 0; i < linkArrayNum; i++) {
|
||||
cJSON *link = cJSON_GetArrayItem(linksItem, i);
|
||||
if (link == NULL) {
|
||||
free(linkArray);
|
||||
return HNP_ERRNO_BASE_GET_ARRAY_ITRM_FAILED;
|
||||
}
|
||||
cJSON *sourceItem = cJSON_GetObjectItem(link, "source");
|
||||
if ((sourceItem == NULL) || (sourceItem->valuestring == NULL)) {
|
||||
HNP_LOGE("get source info in cfg unsuccess.");
|
||||
free(linkArray);
|
||||
return HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
if (strcpy_s(linkArray[i].source, MAX_FILE_PATH_LEN, sourceItem->valuestring) != EOK) {
|
||||
HNP_LOGE("strcpy unsuccess.");
|
||||
free(linkArray);
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
linkArray[i].target[0] = '\0'; //允许target不填,软链接默认使用原二进制名称
|
||||
cJSON *targetItem = cJSON_GetObjectItem(link, "target");
|
||||
if ((targetItem != NULL) && (targetItem->valuestring != NULL) &&
|
||||
(strcpy_s(linkArray[i].target, MAX_FILE_PATH_LEN, targetItem->valuestring) != EOK)) {
|
||||
HNP_LOGE("strcpy unsuccess.");
|
||||
free(linkArray);
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
}
|
||||
hnpCfg->links = linkArray;
|
||||
} else {
|
||||
hnpCfg->linkNum = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ParseJsonStreamToHnpCfgInfo(cJSON *json, HnpCfgInfo *hnpCfg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
cJSON *typeItem = cJSON_GetObjectItem(json, "type");
|
||||
if ((typeItem == NULL) || (typeItem->valuestring == NULL)) {
|
||||
HNP_LOGE("get type info in cfg unsuccess.");
|
||||
return HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
if (strcmp(typeItem->valuestring, "hnp-config") != 0) {
|
||||
HNP_LOGE("type info not match.type=%s", typeItem->valuestring);
|
||||
return HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
cJSON *nameItem = cJSON_GetObjectItem(json, "name");
|
||||
if ((nameItem == NULL) || (nameItem->valuestring == NULL)) {
|
||||
HNP_LOGE("get name info in cfg unsuccess.");
|
||||
return HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
ret = strcpy_s(hnpCfg->name, MAX_FILE_PATH_LEN, nameItem->valuestring);
|
||||
if (ret != EOK) {
|
||||
HNP_LOGE("strcpy unsuccess.");
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
cJSON *versionItem = cJSON_GetObjectItem(json, "version");
|
||||
if ((versionItem == NULL) || (versionItem->valuestring == NULL)) {
|
||||
HNP_LOGE("get version info in cfg unsuccess.");
|
||||
return HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
ret = strcpy_s(hnpCfg->version, HNP_VERSION_LEN, versionItem->valuestring);
|
||||
if (ret != EOK) {
|
||||
HNP_LOGE("strcpy unsuccess.");
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
cJSON *installItem = cJSON_GetObjectItem(json, "install");
|
||||
if (installItem == NULL) {
|
||||
HNP_LOGE("get install info in cfg unsuccess.");
|
||||
return HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
cJSON *linksItem = cJSON_GetObjectItem(installItem, "links");
|
||||
if (linksItem != NULL) {
|
||||
ret = ParseLinksJsonToCfgInfo(linksItem, hnpCfg);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
hnpCfg->linkNum = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ParseHnpCfgFile(const char *hnpCfgPath, HnpCfgInfo *hnpCfg)
|
||||
{
|
||||
int ret;
|
||||
char *cfgStream = NULL;
|
||||
cJSON *json;
|
||||
int size;
|
||||
|
||||
ret = ReadFileToStream(hnpCfgPath, &cfgStream, &size);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("read cfg file[%s] unsuccess.", hnpCfgPath);
|
||||
return HNP_ERRNO_BASE_READ_FILE_STREAM_FAILED;
|
||||
}
|
||||
json = cJSON_Parse(cfgStream);
|
||||
free(cfgStream);
|
||||
if (json == NULL) {
|
||||
HNP_LOGE("parse json file[%s] unsuccess.", hnpCfgPath);
|
||||
return HNP_ERRNO_BASE_PARSE_JSON_FAILED;
|
||||
}
|
||||
ret = ParseJsonStreamToHnpCfgInfo(json, hnpCfg);
|
||||
cJSON_Delete(json);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int HnpCfgGetFromSteam(char *cfgStream, HnpCfgInfo *hnpCfg)
|
||||
{
|
||||
cJSON *json;
|
||||
int ret;
|
||||
|
||||
if (cfgStream == NULL) {
|
||||
HNP_LOGE("hnp cfg file not found.");
|
||||
return HNP_ERRNO_BASE_READ_FILE_STREAM_FAILED;
|
||||
}
|
||||
|
||||
json = cJSON_Parse(cfgStream);
|
||||
if (json == NULL) {
|
||||
HNP_LOGE("parse json file unsuccess.");
|
||||
return HNP_ERRNO_BASE_PARSE_JSON_FAILED;
|
||||
}
|
||||
ret = ParseJsonStreamToHnpCfgInfo(json, hnpCfg);
|
||||
cJSON_Delete(json);
|
||||
|
||||
return ret;
|
||||
}
|
||||
int GetHnpJsonBuff(HnpCfgInfo *hnpCfg, char **buff)
|
||||
{
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(root, "type", "hnp-config");
|
||||
cJSON_AddStringToObject(root, "name", hnpCfg->name);
|
||||
cJSON_AddStringToObject(root, "version", hnpCfg->version);
|
||||
cJSON_AddObjectToObject(root, "install");
|
||||
char *str = cJSON_Print(root);
|
||||
cJSON_Delete(root);
|
||||
|
||||
*buff = str;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -17,7 +17,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "hnp_base.h"
|
||||
|
||||
@ -25,80 +27,29 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static int HnpPidGetByBinName(const char *programName, int *pids, int *count)
|
||||
int HnpProcessRunCheck(const char *runPath)
|
||||
{
|
||||
FILE *cmdOutput;
|
||||
char cmdBuffer[BUFFER_SIZE];
|
||||
char command[HNP_COMMAND_LEN];
|
||||
int pidNum = 0;
|
||||
FILE *cmdOutput;
|
||||
|
||||
/* programName为卸载命令输入的进程名拼接命令command */
|
||||
if (sprintf_s(command, HNP_COMMAND_LEN, "pgrep -x %s", programName) < 0) {
|
||||
HNP_LOGE("hnp uninstall program[%s] run command sprintf unsuccess", programName);
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
HNP_LOGI("runPath[%s] running check", runPath);
|
||||
|
||||
cmdOutput = popen(command, "rb");
|
||||
/* 判断进程是否运行 */
|
||||
cmdOutput = popen("lsof", "rb");
|
||||
if (cmdOutput == NULL) {
|
||||
HNP_LOGE("hnp uninstall program[%s] not found", programName);
|
||||
return HNP_ERRNO_BASE_PROGRAM_NOT_FOUND;
|
||||
HNP_LOGE("hnp uninstall lsof command unsuccess");
|
||||
return HNP_ERRNO_BASE_FILE_OPEN_FAILED;
|
||||
}
|
||||
|
||||
while (fgets(cmdBuffer, sizeof(cmdBuffer), cmdOutput) != NULL) {
|
||||
pids[pidNum++] = atoi(cmdBuffer);
|
||||
if (pidNum >= MAX_PROCESSES) {
|
||||
HNP_LOGI("hnp uninstall program[%s] num over size", programName);
|
||||
break;
|
||||
if (strstr(cmdBuffer, runPath) != NULL) {
|
||||
HNP_LOGE("hnp install path is running now, path[%s]", cmdBuffer);
|
||||
pclose(cmdOutput);
|
||||
return HNP_ERRNO_PROCESS_RUNNING;
|
||||
}
|
||||
}
|
||||
|
||||
pclose(cmdOutput);
|
||||
*count = pidNum;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HnpProgramRunCheck(const char *binName, const char *runPath)
|
||||
{
|
||||
int ret;
|
||||
int pids[MAX_PROCESSES];
|
||||
int count = 0;
|
||||
char command[HNP_COMMAND_LEN];
|
||||
char cmdBuffer[BUFFER_SIZE];
|
||||
|
||||
HNP_LOGI("process[%s] running check", binName);
|
||||
|
||||
/* 对programName进行空格过滤,防止外部命令注入 */
|
||||
if (strchr(binName, ' ') != NULL) {
|
||||
HNP_LOGE("hnp uninstall program name[%s] inval", binName);
|
||||
return HNP_ERRNO_BASE_PARAMS_INVALID;
|
||||
}
|
||||
|
||||
ret = HnpPidGetByBinName(binName, pids, &count);
|
||||
if ((ret != 0) || (count == 0)) { // 返回非0代表未找到进程对应的pid
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 判断进程是否运行 */
|
||||
for (int index = 0; index < count; index++) {
|
||||
if (sprintf_s(command, HNP_COMMAND_LEN, "lsof -p %d", pids[index]) < 0) {
|
||||
HNP_LOGE("hnp uninstall pid[%d] run check command sprintf unsuccess", pids[index]);
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
FILE *cmdOutput = popen(command, "rb");
|
||||
if (cmdOutput == NULL) {
|
||||
HNP_LOGE("hnp uninstall pid[%d] not found", pids[index]);
|
||||
continue;
|
||||
}
|
||||
while (fgets(cmdBuffer, sizeof(cmdBuffer), cmdOutput) != NULL) {
|
||||
if (strstr(cmdBuffer, runPath) != NULL) {
|
||||
pclose(cmdOutput);
|
||||
HNP_LOGE("hnp install process[%s] is running now", binName);
|
||||
return HNP_ERRNO_PROGRAM_RUNNING;
|
||||
}
|
||||
}
|
||||
pclose(cmdOutput);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -195,6 +195,32 @@ int HnpZip(const char *inputDir, const char *outputFile)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int HnpAddFileToZip(char *zipfile, char *filename, char *buff, int size)
|
||||
{
|
||||
zipFile zf;
|
||||
int ret;
|
||||
|
||||
zf = zipOpen(zipfile, APPEND_STATUS_ADDINZIP);
|
||||
if (zf == NULL) {
|
||||
HNP_LOGE("open zip=%s unsuccess ", zipfile);
|
||||
return HNP_ERRNO_BASE_CREATE_ZIP_FAILED;
|
||||
}
|
||||
|
||||
// 将外层文件夹信息保存到zip文件中
|
||||
ret = zipOpenNewFileInZip3(zf, filename, NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_BEST_COMPRESSION,
|
||||
0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, NULL, 0);
|
||||
if (ret != ZIP_OK) {
|
||||
HNP_LOGE("open new file[%s] in zip unsuccess ", filename);
|
||||
zipClose(zf, NULL);
|
||||
return HNP_ERRNO_BASE_CREATE_ZIP_FAILED;
|
||||
}
|
||||
zipWriteInFileInZip(zf, buff, size);
|
||||
zipCloseFileInZip(zf);
|
||||
zipClose(zf, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HnpUnZipForFile(const char *fileName, const char *outputDir, unzFile zipFile)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@ -206,7 +232,7 @@ static int HnpUnZipForFile(const char *fileName, const char *outputDir, unzFile
|
||||
char buffer[BUFFER_SIZE];
|
||||
int readSize = 0;
|
||||
|
||||
ret = sprintf_s(filePath, MAX_FILE_PATH_LEN, "%s%s", outputDir, fileName);
|
||||
ret = sprintf_s(filePath, MAX_FILE_PATH_LEN, "%s/%s", outputDir, fileName);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
@ -253,7 +279,7 @@ int HnpUnZip(const char *inputFile, const char *outputDir)
|
||||
|
||||
zipFile = unzOpen(inputFile);
|
||||
if (zipFile == NULL) {
|
||||
HNP_LOGE("unzip open zip:%s unsuccess!", inputFile);
|
||||
HNP_LOGE("unzip open hnp:%s unsuccess!", inputFile);
|
||||
return HNP_ERRNO_BASE_UNZIP_OPEN_FAILED;
|
||||
}
|
||||
|
||||
@ -285,87 +311,58 @@ int HnpUnZip(const char *inputFile, const char *outputDir)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HnpWriteToZipHead(const char *zipFile, char *buff, int len)
|
||||
int HnpCfgGetFromZip(const char *inputFile, HnpCfgInfo *hnpCfg)
|
||||
{
|
||||
int size;
|
||||
char *buffTmp;
|
||||
char fileName[MAX_FILE_PATH_LEN];
|
||||
char *fileNameTmp;
|
||||
unz_file_info fileInfo;
|
||||
char *cfgStream = NULL;
|
||||
|
||||
int ret = ReadFileToStream(zipFile, &buffTmp, &size);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("read file:%s to stream unsuccess!", zipFile);
|
||||
return ret;
|
||||
unzFile zipFile = unzOpen(inputFile);
|
||||
if (zipFile == NULL) {
|
||||
HNP_LOGE("unzip open hnp:%s unsuccess!", inputFile);
|
||||
return HNP_ERRNO_BASE_UNZIP_OPEN_FAILED;
|
||||
}
|
||||
|
||||
FILE *fp = fopen(zipFile, "wb");
|
||||
if (fp == NULL) {
|
||||
free(buffTmp);
|
||||
HNP_LOGE("open file:%s unsuccess!", zipFile);
|
||||
return HNP_ERRNO_BASE_FILE_OPEN_FAILED;
|
||||
}
|
||||
int writeLen = fwrite(buff, sizeof(char), len, fp);
|
||||
if (writeLen != len) {
|
||||
HNP_LOGE("write file:%s unsuccess! len=%d, write=%d", zipFile, len, writeLen);
|
||||
(void)fclose(fp);
|
||||
free(buffTmp);
|
||||
return HNP_ERRNO_BASE_FILE_WRITE_FAILED;
|
||||
}
|
||||
writeLen = fwrite(buffTmp, sizeof(char), size, fp);
|
||||
(void)fclose(fp);
|
||||
free(buffTmp);
|
||||
if (writeLen != size) {
|
||||
HNP_LOGE("write file:%s unsuccess! size=%d, write=%d", zipFile, size, writeLen);
|
||||
return HNP_ERRNO_BASE_FILE_WRITE_FAILED;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int ret = unzGoToFirstFile(zipFile);
|
||||
while (ret == UNZ_OK) {
|
||||
ret = unzGetCurrentFileInfo(zipFile, &fileInfo, fileName, sizeof(fileName), NULL, 0, NULL, 0);
|
||||
if (ret != UNZ_OK) {
|
||||
HNP_LOGE("unzip get zip:%s info unsuccess!", inputFile);
|
||||
unzClose(zipFile);
|
||||
return HNP_ERRNO_BASE_UNZIP_GET_INFO_FAILED;
|
||||
}
|
||||
fileNameTmp = strrchr(fileName, DIR_SPLIT_SYMBOL);
|
||||
if (fileNameTmp == NULL) {
|
||||
fileNameTmp = fileName;
|
||||
} else {
|
||||
fileNameTmp++;
|
||||
}
|
||||
if (strcmp(fileNameTmp, HNP_CFG_FILE_NAME) != 0) {
|
||||
ret = unzGoToNextFile(zipFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
int HnpReadFromZipHead(const char *zipFile, NativeHnpHead **hnpHead)
|
||||
{
|
||||
char *buffTmp;
|
||||
int headLen;
|
||||
NativeHnpHead *hnpHeadTmp;
|
||||
|
||||
int ret = ReadFileToStreamBySize(zipFile, &buffTmp, sizeof(NativeHnpHead));
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("read file:%s to stream unsuccess!", zipFile);
|
||||
return ret;
|
||||
unzOpenCurrentFile(zipFile);
|
||||
cfgStream = malloc(fileInfo.uncompressed_size);
|
||||
if (cfgStream == NULL) {
|
||||
HNP_LOGE("malloc unsuccess. size=%d, errno=%d", fileInfo.uncompressed_size, errno);
|
||||
unzClose(zipFile);
|
||||
return HNP_ERRNO_NOMEM;
|
||||
}
|
||||
uLong readSize = unzReadCurrentFile(zipFile, cfgStream, fileInfo.uncompressed_size);
|
||||
if (readSize != fileInfo.uncompressed_size) {
|
||||
free(cfgStream);
|
||||
unzClose(zipFile);
|
||||
HNP_LOGE("unzip read zip:%s info size[%lu]=>[%lu] error!", inputFile, fileInfo.uncompressed_size, readSize);
|
||||
return HNP_ERRNO_BASE_FILE_READ_FAILED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* 读取native头的大小 */
|
||||
hnpHeadTmp = (NativeHnpHead *)buffTmp;
|
||||
if (hnpHeadTmp->magic != HNP_HEAD_MAGIC) {
|
||||
free(buffTmp);
|
||||
HNP_LOGE("read file unsuccess,%s is invalid hnp file", zipFile);
|
||||
return HNP_ERRNO_BASE_MAGIC_CHECK_FAILED;
|
||||
}
|
||||
headLen = hnpHeadTmp->headLen;
|
||||
free(buffTmp);
|
||||
buffTmp = NULL;
|
||||
|
||||
FILE *fp = fopen(zipFile, "rb");
|
||||
if (fp == NULL) {
|
||||
HNP_LOGE("open file[%s] unsuccess. errno=%d", zipFile, errno);
|
||||
return HNP_ERRNO_BASE_FILE_OPEN_FAILED;
|
||||
}
|
||||
|
||||
buffTmp = (char*)malloc(headLen);
|
||||
if (buffTmp == NULL) {
|
||||
HNP_LOGE("malloc unsuccess. size=%d, errno=%d", headLen, errno);
|
||||
(void)fclose(fp);
|
||||
return HNP_ERRNO_NOMEM;
|
||||
}
|
||||
|
||||
ret = fread(buffTmp, sizeof(char), headLen, fp);
|
||||
if (ret != headLen) {
|
||||
HNP_LOGE("fread unsuccess. ret=%d, size=%d, errno=%d", ret, headLen, errno);
|
||||
(void)fclose(fp);
|
||||
free(buffTmp);
|
||||
return HNP_ERRNO_BASE_FILE_READ_FAILED;
|
||||
}
|
||||
|
||||
*hnpHead = (NativeHnpHead *)buffTmp;
|
||||
(void)fclose(fp);
|
||||
return 0;
|
||||
unzClose(zipFile);
|
||||
ret = HnpCfgGetFromSteam(cfgStream, hnpCfg);
|
||||
free(cfgStream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "hnp_base.h"
|
||||
#include "hnp_installer.h"
|
||||
@ -33,6 +34,7 @@ typedef struct NativeManagerCmdInfoStru {
|
||||
|
||||
NativeManagerCmdInfo g_nativeManagerCmd[] = {
|
||||
{"help", HnpShowHelp},
|
||||
{"-h", HnpShowHelp},
|
||||
{"install", HnpCmdInstall},
|
||||
{"uninstall", HnpCmdUnInstall}
|
||||
};
|
||||
@ -42,17 +44,28 @@ int HnpShowHelp(int argc, char *argv[])
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
HNP_LOGI("\r\nusage:hnp <command> <args>\r\n"
|
||||
HNP_LOGI("\r\nusage:hnp <command> <args> [-u <user id>][-p <software package path>]"
|
||||
"[-i <private path>][-f]\r\n"
|
||||
"\r\nThese are common hnp commands used in various situations:\r\n"
|
||||
"\r\nIf the [package name] is null, it represents a public install/nuninstall,\r\n"
|
||||
" or it represents a private install/nuninstall\r\n"
|
||||
"\r\ninstall: install native software"
|
||||
"\r\n hnp install [user id] [hnp package dir] [package name] <-f>\r\n"
|
||||
"\r\nuninstall: uninstall native software"
|
||||
"\r\n hnp uninstall [user id] [software name] [software version] [package name]\r\n"
|
||||
"\r\ninstall: install one or more native hnp packages"
|
||||
"\r\n hnp install <-u [user id]> <-p [hnp package path]> <-i [hnp install path]> <-f>"
|
||||
"\r\n -u : [required] user id"
|
||||
"\r\n -p : [required] path of hnp package to be installed, multiple packages are supported"
|
||||
"\r\n -i : [optional] hnp install path; if not provided, it will be installed to"
|
||||
" public hnp path"
|
||||
"\r\n -f : [optional] if provided, the hnp package will be installed forcely, ignoring old"
|
||||
" versions of the hnp package\r\n"
|
||||
"\r\nuninstall: uninstall one hnp package"
|
||||
"\r\n hnp uninstall <-u [user id]> <-n [hnp package name]> <-v [hnp package version]>"
|
||||
" <-i [hnp package uninstall path]>"
|
||||
"\r\n -u : [required] user id"
|
||||
"\r\n -n : [required] hnp package name"
|
||||
"\r\n -v : [required] hnp package version"
|
||||
"\r\n -i : [optional] the path for uninstalling the hnp package; if not provided, it will"
|
||||
" install from the default public hnp path\r\n"
|
||||
"\r\nfor example:\r\n"
|
||||
"\r\n hnp install 1000 /usr1/hnp wechat -f\r\n"
|
||||
" hnp uninstall 1000 native_sample 1.1 wechat\r\n");
|
||||
"\r\n hnp install -u 1000 -p /usr1/hnp/sample.hnp -p /usr1/hnp/sample2.hnp -i /data/app/el1/bundle/ -f"
|
||||
"\r\n hnp uninstall -u 1000 -n native_sample -v 1.1 -i /data/app/el1/bundle/\r\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -85,14 +98,17 @@ int main(int argc, char *argv[])
|
||||
/* 检验用户命令,获取对应的处理函数 */
|
||||
cmdInfo = HnpCmdCheck(argv[HNP_INDEX_1]);
|
||||
if (cmdInfo == NULL) {
|
||||
HNP_LOGE("invalid cmd!. cmd:%s", argv[HNP_INDEX_1]);
|
||||
HNP_LOGE("invalid cmd!. cmd:%s\r\n", argv[HNP_INDEX_1]);
|
||||
return HNP_ERRNO_OPERATOR_TYPE_INVALID;
|
||||
}
|
||||
|
||||
/* 执行命令 */
|
||||
ret = cmdInfo->process(argc, argv);
|
||||
if (ret == HNP_ERRNO_OPERATOR_ARGV_MISS) {
|
||||
HnpShowHelp(argc, argv);
|
||||
}
|
||||
|
||||
HNP_LOGI("native manager process exit. ret=%d ", ret);
|
||||
HNP_LOGI("native manager process exit. ret=%d \r\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "hnp_base.h"
|
||||
#include "hnp_pack.h"
|
||||
@ -33,6 +34,7 @@ typedef struct NativeManagerCmdInfoStru {
|
||||
|
||||
NativeManagerCmdInfo g_nativeManagerCmd[] = {
|
||||
{"help", HnpCliShowHelp},
|
||||
{"-h", HnpCliShowHelp},
|
||||
{"pack", HnpCmdPack}
|
||||
};
|
||||
|
||||
@ -41,16 +43,18 @@ int HnpCliShowHelp(int argc, char *argv[])
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
HNP_LOGI("\r\nusage:hnpcli <command> <args> [-cfg <link cfg file>][-name <native package name>]"
|
||||
"[-v <native package version>]\r\n"
|
||||
"\r\nThese are common hnp commands used in various situations:\r\n"
|
||||
HNP_LOGI("\r\nusage:hnpcli <command> <args> [-i <software package dir>][-o <hnp output path>]"
|
||||
"[-n <native package name>][-v <native package version>]\r\n"
|
||||
"\r\nThese are common hnpcli commands used in various situations:\r\n"
|
||||
"\r\npack: packet native software package to .hnp file"
|
||||
"\r\n hnpcli pack [source path] [dst path] -name [software name] -v [software version]"
|
||||
"\r\n hnpcli pack [source path] [dst path] -cfg [link config file]\r\n"
|
||||
"\r\n hnpcli pack <-i [source path]> <-o [dst path]> <-n [software name]> <-v [software version]>"
|
||||
"\r\n -i : [required] input path of software package dir"
|
||||
"\r\n -o : [optional] output path of hnp file. if not set then ouput to current directory"
|
||||
"\r\n -n : [optional] software name. if not hnp.json in input dir then must set"
|
||||
"\r\n -v : [optional] software version. if not hnp.json in input dir then must set\r\n"
|
||||
"\r\nfor example:\r\n"
|
||||
"\r\n hnpcli pack /usr1/native_sample /usr1/output -name native_sample -v 1.1\r\n"
|
||||
" hnpcli pack /usr1/native_sample /usr1/output -cfg /usr1/native_sample.cfg\r\n");
|
||||
|
||||
"\r\n hnpcli pack -i /usr1/native_sample -o /usr1/output -n native_sample -v 1.1\r\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -74,7 +78,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (argc < HNP_INDEX_2) {
|
||||
HnpCliShowHelp(argc, argv);
|
||||
return HNP_ERRNO_PARAM_INVALID;
|
||||
return HNP_ERRNO_OPERATOR_ARGV_MISS;
|
||||
}
|
||||
|
||||
HNP_LOGI("native manager process start.");
|
||||
@ -88,6 +92,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* 执行命令 */
|
||||
ret = cmdInfo->process(argc, argv);
|
||||
if (ret == HNP_ERRNO_OPERATOR_ARGV_MISS) {
|
||||
HnpCliShowHelp(argc, argv);
|
||||
}
|
||||
|
||||
HNP_LOGI("native manager process exit. ret=%d ", ret);
|
||||
return ret;
|
||||
|
@ -23,42 +23,37 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct NativeHnpPathStru {
|
||||
char hnpProgramName[MAX_FILE_PATH_LEN];
|
||||
char hnpSoftwareName[MAX_FILE_PATH_LEN];
|
||||
char hnpBasePath[MAX_FILE_PATH_LEN];
|
||||
char hnpProgramPath[MAX_FILE_PATH_LEN];
|
||||
char hnpSoftwarePath[MAX_FILE_PATH_LEN];
|
||||
char hnpVersionPath[MAX_FILE_PATH_LEN];
|
||||
} NativeHnpPath;
|
||||
|
||||
// 0x801301 安装命令参数错误
|
||||
#define HNP_ERRNO_INSTALLER_ARGV_NUM_INVALID HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x1)
|
||||
// 0x801301 组装安装路径失败
|
||||
#define HNP_ERRNO_INSTALLER_GET_HNP_PATH_FAILED HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x1)
|
||||
|
||||
// 0x801302 组装安装路径失败
|
||||
#define HNP_ERRNO_INSTALLER_GET_HNP_PATH_FAILED HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x2)
|
||||
// 0x801302 获取安装绝对路径失败
|
||||
#define HNP_ERRNO_INSTALLER_GET_REALPATH_FAILED HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x2)
|
||||
|
||||
// 0x801303 获取安装绝对路径失败
|
||||
#define HNP_ERRNO_INSTALLER_GET_REALPATH_FAILED HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x3)
|
||||
// 0x801303 获取Hnp安装包名称失败
|
||||
#define HNP_ERRNO_INSTALLER_GET_HNP_NAME_FAILED HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x3)
|
||||
|
||||
// 0x801304 获取Hnp安装包名称失败
|
||||
#define HNP_ERRNO_INSTALLER_GET_HNP_NAME_FAILED HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x4)
|
||||
// 0x801304 安装的包已存在
|
||||
#define HNP_ERRNO_INSTALLER_PATH_IS_EXIST HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x4)
|
||||
|
||||
// 0x801305 安装的包已存在
|
||||
#define HNP_ERRNO_INSTALLER_PATH_IS_EXIST HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x5)
|
||||
// 0x801305 获取卸载路径失败
|
||||
#define HNP_ERRNO_UNINSTALLER_HNP_PATH_NOT_EXIST HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x5)
|
||||
|
||||
// 0x801306 卸载命令参数错误
|
||||
#define HNP_ERRNO_UNINSTALLER_ARGV_NUM_INVALID HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x6)
|
||||
// 0x801306 安装命令参数uid错误
|
||||
#define HNP_ERRNO_INSTALLER_ARGV_UID_INVALID HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x6)
|
||||
|
||||
// 0x801307 获取卸载路径失败
|
||||
#define HNP_ERRNO_UNINSTALLER_HNP_PATH_NOT_EXIST HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x7)
|
||||
// 0x801307 获取版本目录失败
|
||||
#define HNP_ERRNO_INSTALLER_VERSION_FILE_GET_FAILED HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x7)
|
||||
|
||||
// 0x801308 安装命令参数uid错误
|
||||
#define HNP_ERRNO_INSTALLER_ARGV_UID_INVALID HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x8)
|
||||
// 0x801308 安装包超过最大值
|
||||
#define HNP_ERRNO_INSTALLER_SOFTWARE_NUM_OVERSIZE HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x8)
|
||||
|
||||
// 0x801309 获取版本目录失败
|
||||
#define HNP_ERRNO_INSTALLER_VERSION_FILE_GET_FAILED HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x9)
|
||||
|
||||
#define HNP_DEFAULT_INSTALL_ROOT_PATH "/data/app/el1/bundle/"
|
||||
|
||||
#define HNP_UNSTALL_INFO_FILE "hnp_uninstall.txt"
|
||||
#define HNP_DEFAULT_INSTALL_ROOT_PATH "/data/app/el1/bundle"
|
||||
|
||||
int HnpCmdInstall(int argc, char *argv[]);
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "hnp_installer.h"
|
||||
|
||||
@ -28,10 +29,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static int HnpInstallerUidGet(const char *uidIn, unsigned long *uidOut)
|
||||
static int HnpInstallerUidGet(const char *uidIn, int *uidOut)
|
||||
{
|
||||
int index;
|
||||
char *endptr;
|
||||
|
||||
for (index = 0; uidIn[index] != '\0'; index++) {
|
||||
if (!isdigit(uidIn[index])) {
|
||||
@ -39,16 +39,15 @@ static int HnpInstallerUidGet(const char *uidIn, unsigned long *uidOut)
|
||||
}
|
||||
}
|
||||
|
||||
*uidOut = strtoul(uidIn, &endptr, 10); // 转化为10进制
|
||||
*uidOut = atoi(uidIn); // 转化为10进制
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HnpGenerateSoftLinkAllByJson(const char *installPath, const char *dstPath, NativeHnpHead *hnpHead)
|
||||
static int HnpGenerateSoftLinkAllByJson(const char *installPath, const char *dstPath, HnpCfgInfo *hnpCfg)
|
||||
{
|
||||
char srcFile[MAX_FILE_PATH_LEN];
|
||||
char dstFile[MAX_FILE_PATH_LEN];
|
||||
char uninstallFile[MAX_FILE_PATH_LEN];
|
||||
NativeBinLink *currentLink = hnpHead->links;
|
||||
NativeBinLink *currentLink = hnpCfg->links;
|
||||
char *fileName;
|
||||
char *fileNameTmp;
|
||||
|
||||
@ -60,8 +59,8 @@ static int HnpGenerateSoftLinkAllByJson(const char *installPath, const char *dst
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < hnpHead->linkNum; i++) {
|
||||
int ret = sprintf_s(srcFile, MAX_FILE_PATH_LEN, "%s%s", installPath, currentLink->source);
|
||||
for (unsigned int i = 0; i < hnpCfg->linkNum; i++) {
|
||||
int ret = sprintf_s(srcFile, MAX_FILE_PATH_LEN, "%s/%s", installPath, currentLink->source);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf install bin src file unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
@ -72,13 +71,13 @@ static int HnpGenerateSoftLinkAllByJson(const char *installPath, const char *dst
|
||||
} else {
|
||||
fileNameTmp = currentLink->target;
|
||||
}
|
||||
fileName = strrchr(fileNameTmp, '/');
|
||||
fileName = strrchr(fileNameTmp, DIR_SPLIT_SYMBOL);
|
||||
if (fileName == NULL) {
|
||||
fileName = fileNameTmp;
|
||||
} else {
|
||||
fileName++;
|
||||
}
|
||||
ret = sprintf_s(dstFile, MAX_FILE_PATH_LEN, "%s%s", dstPath, fileName);
|
||||
ret = sprintf_s(dstFile, MAX_FILE_PATH_LEN, "%s/%s", dstPath, fileName);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf install bin dst file unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
@ -92,15 +91,7 @@ static int HnpGenerateSoftLinkAllByJson(const char *installPath, const char *dst
|
||||
currentLink++;
|
||||
}
|
||||
|
||||
int ret = sprintf_s(uninstallFile, MAX_FILE_PATH_LEN, "%s"HNP_UNSTALL_INFO_FILE, installPath);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf install info file unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
/* 向生成的hnp_unstall.txt文件头写入配置信息便于卸载 */
|
||||
ret = HnpWriteInfoToFile(uninstallFile, (char*)hnpHead, hnpHead->headLen);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HnpGenerateSoftLinkAll(const char *installPath, const char *dstPath)
|
||||
@ -112,7 +103,7 @@ static int HnpGenerateSoftLinkAll(const char *installPath, const char *dstPath)
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
ret = sprintf_s(srcPath, MAX_FILE_PATH_LEN, "%sbin/", installPath);
|
||||
ret = sprintf_s(srcPath, MAX_FILE_PATH_LEN, "%s/bin/", installPath);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf install bin path unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
@ -136,14 +127,14 @@ static int HnpGenerateSoftLinkAll(const char *installPath, const char *dstPath)
|
||||
if (entry->d_type != DT_REG) {
|
||||
continue;
|
||||
}
|
||||
ret = sprintf_s(srcFile, MAX_FILE_PATH_LEN, "%s%s", srcPath, entry->d_name);
|
||||
ret = sprintf_s(srcFile, MAX_FILE_PATH_LEN, "%s/%s", srcPath, entry->d_name);
|
||||
if (ret < 0) {
|
||||
closedir(dir);
|
||||
HNP_LOGE("sprintf install bin src file unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
|
||||
ret = sprintf_s(dstFile, MAX_FILE_PATH_LEN, "%s%s", dstPath, entry->d_name);
|
||||
ret = sprintf_s(dstFile, MAX_FILE_PATH_LEN, "%s/%s", dstPath, entry->d_name);
|
||||
if (ret < 0) {
|
||||
closedir(dir);
|
||||
HNP_LOGE("sprintf install bin dst file unsuccess.");
|
||||
@ -161,27 +152,27 @@ static int HnpGenerateSoftLinkAll(const char *installPath, const char *dstPath)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HnpGenerateSoftLink(const char *installPath, const char *hnpBasePath, NativeHnpHead *hnpHead)
|
||||
static int HnpGenerateSoftLink(const char *installPath, const char *hnpBasePath, HnpCfgInfo *hnpCfg)
|
||||
{
|
||||
int ret = 0;
|
||||
char binPath[MAX_FILE_PATH_LEN];
|
||||
|
||||
ret = sprintf_s(binPath, MAX_FILE_PATH_LEN, "%sbin/", hnpBasePath);
|
||||
ret = sprintf_s(binPath, MAX_FILE_PATH_LEN, "%s/bin/", hnpBasePath);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf install bin path unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
|
||||
if (hnpHead->linkNum == 0) {
|
||||
if (hnpCfg->linkNum == 0) {
|
||||
ret = HnpGenerateSoftLinkAll(installPath, binPath);
|
||||
} else {
|
||||
ret = HnpGenerateSoftLinkAllByJson(installPath, binPath, hnpHead);
|
||||
ret = HnpGenerateSoftLinkAllByJson(installPath, binPath, hnpCfg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int HnpInstall(const char *hnpFile, NativeHnpPath *hnpDstPath, NativeHnpHead *hnpHead)
|
||||
static int HnpInstall(const char *hnpFile, NativeHnpPath *hnpDstPath, HnpCfgInfo *hnpCfg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -192,138 +183,57 @@ static int HnpInstall(const char *hnpFile, NativeHnpPath *hnpDstPath, NativeHnpH
|
||||
}
|
||||
|
||||
/* 生成软链 */
|
||||
return HnpGenerateSoftLink(hnpDstPath->hnpVersionPath, hnpDstPath->hnpBasePath, hnpHead);
|
||||
return HnpGenerateSoftLink(hnpDstPath->hnpVersionPath, hnpDstPath->hnpBasePath, hnpCfg);
|
||||
}
|
||||
|
||||
static int HnpProgramRunCheckWithFile(const char *file, NativeHnpPath *hnpDstPath, const char *versionPath)
|
||||
static int HnpUnInstall(NativeHnpPath *hnpDstPath, const char *uninstallPath, bool runCheck)
|
||||
{
|
||||
int ret;
|
||||
NativeHnpHead *hnpHead;
|
||||
NativeBinLink *currentLink;
|
||||
char *fileName;
|
||||
|
||||
ret = HnpReadFromZipHead(file, &hnpHead);
|
||||
if (ret != 0) {
|
||||
return ret; /* 内部已打印日志 */
|
||||
}
|
||||
|
||||
currentLink = hnpHead->links;
|
||||
for (unsigned int i = 0; i < hnpHead->linkNum; i++) {
|
||||
/* 如果target为空则使用源二进制名称 */
|
||||
if (strcmp(currentLink->target, "") == 0) {
|
||||
fileName = strrchr(currentLink->source, '/');
|
||||
if (fileName == NULL) {
|
||||
fileName = currentLink->source;
|
||||
} else {
|
||||
fileName++;
|
||||
}
|
||||
ret = HnpProgramRunCheck(fileName, versionPath);
|
||||
} else {
|
||||
ret = HnpProgramRunCheck(currentLink->target, versionPath);
|
||||
}
|
||||
if (ret != 0) {
|
||||
free(hnpHead);
|
||||
return ret;
|
||||
}
|
||||
currentLink++;
|
||||
}
|
||||
|
||||
free(hnpHead);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HnpProgramRunCheckWithPath(const char *path, NativeHnpPath *hnpDstPath, const char *versionPath)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
int ret;
|
||||
|
||||
if ((dir = opendir(path)) == NULL) {
|
||||
HNP_LOGE("uninstall run check opendir:%s unsuccess", path);
|
||||
return 0; /* 无bin文件继续删除目录 */
|
||||
}
|
||||
while (((entry = readdir(dir)) != NULL)) {
|
||||
/* 非二进制文件跳过 */
|
||||
if (entry->d_type != DT_REG) {
|
||||
continue;
|
||||
}
|
||||
/* 查询软件是否正在运行 */
|
||||
ret = HnpProgramRunCheck(entry->d_name, versionPath);
|
||||
if (ret != 0) {
|
||||
closedir(dir);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HnpUnInstall(NativeHnpPath *hnpDstPath, const char *versionPath, bool runCheck)
|
||||
{
|
||||
int ret;
|
||||
char uninstallFile[MAX_FILE_PATH_LEN];
|
||||
char binPath[MAX_FILE_PATH_LEN];
|
||||
|
||||
HNP_LOGI("hnp uninstall start now! path=%s program name[%s], run check=%d", hnpDstPath->hnpProgramPath,
|
||||
hnpDstPath->hnpProgramName, runCheck);
|
||||
HNP_LOGI("hnp uninstall start now! path=%s soft name[%s], run check=%d", hnpDstPath->hnpSoftwarePath,
|
||||
hnpDstPath->hnpSoftwareName, runCheck);
|
||||
|
||||
if (runCheck == false) {
|
||||
ret = HnpDeleteFolder(hnpDstPath->hnpProgramPath);
|
||||
ret = HnpDeleteFolder(hnpDstPath->hnpSoftwarePath);
|
||||
HNP_LOGI("hnp uninstall end! ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = sprintf_s(uninstallFile, MAX_FILE_PATH_LEN, "%s/"HNP_UNSTALL_INFO_FILE, versionPath);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf uninstall info file unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
if (access(uninstallFile, F_OK) == 0) {
|
||||
ret = HnpProgramRunCheckWithFile(uninstallFile, hnpDstPath, versionPath);
|
||||
} else {
|
||||
ret = sprintf_s(binPath, MAX_FILE_PATH_LEN, "%s/bin", versionPath);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf uninstall info file unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
ret = HnpProgramRunCheckWithPath(binPath, hnpDstPath, versionPath);
|
||||
}
|
||||
|
||||
ret = HnpProcessRunCheck(uninstallPath);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = HnpDeleteFolder(hnpDstPath->hnpProgramPath);
|
||||
ret = HnpDeleteFolder(hnpDstPath->hnpSoftwarePath);
|
||||
HNP_LOGI("hnp uninstall end! ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int HnpGetVersionPathInProgramPath(const char *programPath, char *versionPath)
|
||||
static int HnpGetUninstallPath(const char *softwarePath, char *uninstallPath)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
int ret;
|
||||
|
||||
if ((dir = opendir(programPath)) == NULL) {
|
||||
HNP_LOGE("get version file opendir:%s unsuccess", programPath);
|
||||
if ((dir = opendir(softwarePath)) == NULL) {
|
||||
HNP_LOGE("get version file opendir:%s unsuccess", softwarePath);
|
||||
return HNP_ERRNO_BASE_FILE_OPEN_FAILED;
|
||||
}
|
||||
while (((entry = readdir(dir)) != NULL)) {
|
||||
if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) {
|
||||
continue;
|
||||
}
|
||||
ret = sprintf_s(versionPath, MAX_FILE_PATH_LEN, "%s/%s", programPath, entry->d_name);
|
||||
ret = sprintf_s(uninstallPath, MAX_FILE_PATH_LEN, "%s/%s", softwarePath, entry->d_name);
|
||||
if (ret < 0) {
|
||||
closedir(dir);
|
||||
HNP_LOGE("get version file sprintf_s unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
HNP_LOGI("get version file:%s success", versionPath);
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
HNP_LOGE("get uninstall path in[%s] unsuccess", softwarePath);
|
||||
closedir(dir);
|
||||
return HNP_ERRNO_INSTALLER_VERSION_FILE_GET_FAILED;
|
||||
}
|
||||
@ -332,48 +242,48 @@ static int HnpInstallPathGet(const char *fileName, bool isForce, char* hnpVersio
|
||||
{
|
||||
int ret;
|
||||
char *hnpNameTmp;
|
||||
char versionOldPath[MAX_FILE_PATH_LEN];
|
||||
char uninstallPath[MAX_FILE_PATH_LEN];
|
||||
|
||||
/* 裁剪获取文件名使用 */
|
||||
ret = strcpy_s(hnpDstPath->hnpProgramName, MAX_FILE_PATH_LEN, fileName);
|
||||
ret = strcpy_s(hnpDstPath->hnpSoftwareName, MAX_FILE_PATH_LEN, fileName);
|
||||
if (ret != EOK) {
|
||||
HNP_LOGE("hnp install program path strcpy unsuccess.");
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
hnpNameTmp = strrchr(hnpDstPath->hnpProgramName, '.');
|
||||
if (hnpNameTmp && !strcmp(hnpNameTmp, ".hnp")) {
|
||||
hnpNameTmp = strrchr(hnpDstPath->hnpSoftwareName, '.');
|
||||
if (hnpNameTmp) {
|
||||
*hnpNameTmp = '\0';
|
||||
} else {
|
||||
return HNP_ERRNO_INSTALLER_GET_HNP_NAME_FAILED;
|
||||
}
|
||||
|
||||
/* 拼接安装路径 */
|
||||
ret = sprintf_s(hnpDstPath->hnpProgramPath, MAX_FILE_PATH_LEN, "%s%s.org/", hnpDstPath->hnpBasePath,
|
||||
hnpDstPath->hnpProgramName);
|
||||
ret = sprintf_s(hnpDstPath->hnpSoftwarePath, MAX_FILE_PATH_LEN, "%s/%s.org", hnpDstPath->hnpBasePath,
|
||||
hnpDstPath->hnpSoftwareName);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("hnp install sprintf hnp base path unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
|
||||
/* 拼接安装路径 */
|
||||
ret = sprintf_s(hnpDstPath->hnpVersionPath, MAX_FILE_PATH_LEN, "%s%s_%s/", hnpDstPath->hnpProgramPath,
|
||||
hnpDstPath->hnpProgramName, hnpVersion);
|
||||
ret = sprintf_s(hnpDstPath->hnpVersionPath, MAX_FILE_PATH_LEN, "%s/%s_%s", hnpDstPath->hnpSoftwarePath,
|
||||
hnpDstPath->hnpSoftwareName, hnpVersion);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("hnp install sprintf install path unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
|
||||
/* 判断安装目录是否存在,存在判断是否是强制安装,如果是则走卸载流程,否则返回错误 */
|
||||
if (access(hnpDstPath->hnpProgramPath, F_OK) == 0) {
|
||||
if (access(hnpDstPath->hnpSoftwarePath, F_OK) == 0) {
|
||||
if (isForce == false) {
|
||||
HNP_LOGE("hnp install path[%s] exist, but force is false", hnpDstPath->hnpProgramPath);
|
||||
HNP_LOGE("hnp install path[%s] exist, but force is false", hnpDstPath->hnpSoftwarePath);
|
||||
return HNP_ERRNO_INSTALLER_PATH_IS_EXIST;
|
||||
} else {
|
||||
ret = HnpGetVersionPathInProgramPath(hnpDstPath->hnpProgramPath, versionOldPath);
|
||||
ret = HnpGetUninstallPath(hnpDstPath->hnpSoftwarePath, uninstallPath);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
ret = HnpUnInstall(hnpDstPath, versionOldPath, true);
|
||||
ret = HnpUnInstall(hnpDstPath, uninstallPath, true);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
@ -387,153 +297,187 @@ static int HnpInstallPathGet(const char *fileName, bool isForce, char* hnpVersio
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int HnpDirReadAndInstall(const char *srcPath, NativeHnpPath *hnpDstPath, bool isForce)
|
||||
static int HnpReadAndInstall(char *srcFile, NativeHnpPath *hnpDstPath, bool isForce)
|
||||
{
|
||||
struct dirent *entry;
|
||||
char hnpFile[MAX_FILE_PATH_LEN];
|
||||
NativeHnpHead *hnpHead;
|
||||
int count = 0;
|
||||
int ret;
|
||||
char *fileName;
|
||||
HnpCfgInfo hnpCfg = {0};
|
||||
|
||||
DIR *dir = opendir(srcPath);
|
||||
if (dir == NULL) {
|
||||
HNP_LOGE("hnp install opendir:%s unsuccess, errno=%d", srcPath, errno);
|
||||
return HNP_ERRNO_BASE_DIR_OPEN_FAILED;
|
||||
/* 从hnp zip获取cfg信息 */
|
||||
ret = HnpCfgGetFromZip(srcFile, &hnpCfg);
|
||||
if (ret != 0) {
|
||||
return ret; /* 内部已打印日志 */
|
||||
}
|
||||
|
||||
/* 遍历hnp目录 */
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
||||
continue;
|
||||
/* 获取文件名称 */
|
||||
fileName = strrchr(srcFile, DIR_SPLIT_SYMBOL);
|
||||
if (fileName == NULL) {
|
||||
fileName = srcFile;
|
||||
} else {
|
||||
fileName++;
|
||||
}
|
||||
ret = HnpInstallPathGet(fileName, isForce, hnpCfg.version, hnpDstPath);
|
||||
if (ret != 0) {
|
||||
// 释放软链接占用的内存
|
||||
if (hnpCfg.links != NULL) {
|
||||
free(hnpCfg.links);
|
||||
hnpCfg.links = NULL;
|
||||
}
|
||||
int ret = sprintf_s(hnpFile, MAX_FILE_PATH_LEN, "%s/%s", srcPath, entry->d_name);
|
||||
return ret; /* 内部已打印日志 */
|
||||
}
|
||||
|
||||
/* hnp安装 */
|
||||
ret = HnpInstall(srcFile, hnpDstPath, &hnpCfg);
|
||||
// 释放软链接占用的内存
|
||||
if (hnpCfg.links != NULL) {
|
||||
free(hnpCfg.links);
|
||||
hnpCfg.links = NULL;
|
||||
}
|
||||
if (ret != 0) {
|
||||
/* 安装失败卸载当前包 */
|
||||
HnpUnInstall(hnpDstPath, hnpDstPath->hnpVersionPath, false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HnpInsatllPre(int uid, char *softwarePath[], int count, char *installPath, bool isForce)
|
||||
{
|
||||
char srcFile[count][MAX_FILE_PATH_LEN];
|
||||
char dstPath[MAX_FILE_PATH_LEN];
|
||||
NativeHnpPath hnpDstPath = {0};
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* 验证native软件包路径是否存在 */
|
||||
for (i = 0; i < count; i++) {
|
||||
if (GetRealPath(softwarePath[i], srcFile[i]) != 0) {
|
||||
HNP_LOGE("hnp install path invalid! src path=%s", softwarePath[i]);
|
||||
return HNP_ERRNO_INSTALLER_GET_REALPATH_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (installPath == NULL) {
|
||||
/* 拼接安装路径 */
|
||||
if (sprintf_s(dstPath, MAX_FILE_PATH_LEN, HNP_DEFAULT_INSTALL_ROOT_PATH"/%d", uid) < 0) {
|
||||
HNP_LOGE("hnp install sprintf unsuccess, uid:%d", uid);
|
||||
return HNP_ERRNO_INSTALLER_GET_HNP_PATH_FAILED;
|
||||
}
|
||||
|
||||
/* 验证安装路径是否存在 */
|
||||
if (access(dstPath, F_OK) != 0) {
|
||||
HNP_LOGE("hnp install uid path[%s] is not exist", dstPath);
|
||||
return HNP_ERRNO_INSTALLER_GET_REALPATH_FAILED;
|
||||
}
|
||||
|
||||
ret = sprintf_s(hnpDstPath.hnpBasePath, MAX_FILE_PATH_LEN, "%s/hnp/hnppublic", dstPath);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("hnp install sprintf hnp path unsuccess.");
|
||||
closedir(dir);
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
HNP_LOGE("hnp install public base path sprintf unsuccess.");
|
||||
return HNP_ERRNO_INSTALLER_GET_HNP_PATH_FAILED;
|
||||
}
|
||||
|
||||
/* 从hnp头文件获取头文件信息,由于大小不固定,内存在方法内申请,失败需要手动释放 */
|
||||
ret = HnpReadFromZipHead(hnpFile, &hnpHead);
|
||||
if (ret != 0) {
|
||||
closedir(dir);
|
||||
return ret; /* 内部已打印日志 */
|
||||
} else {
|
||||
if (GetRealPath(installPath, hnpDstPath.hnpBasePath) != 0) {
|
||||
HNP_LOGE("hnp install path[%s] is not exist", installPath);
|
||||
return HNP_ERRNO_INSTALLER_GET_REALPATH_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
/* 获取安装路径 */
|
||||
ret = HnpInstallPathGet(entry->d_name, isForce, hnpHead->hnpVersion, hnpDstPath);
|
||||
for (i = 0; i < count; i++) {
|
||||
HNP_LOGI("hnp install start now! src file=%s, dst path=%s, is force=%d", srcFile[i],
|
||||
hnpDstPath.hnpBasePath, isForce);
|
||||
ret = HnpReadAndInstall(srcFile[i], &hnpDstPath, isForce);
|
||||
HNP_LOGI("hnp install src file=%s end, ret=%d", srcFile[i], ret);
|
||||
if (ret != 0) {
|
||||
closedir(dir);
|
||||
free(hnpHead);
|
||||
return ret; /* 内部已打印日志 */
|
||||
}
|
||||
|
||||
/* hnp安装 */
|
||||
ret = HnpInstall(hnpFile, hnpDstPath, hnpHead);
|
||||
if (ret != 0) {
|
||||
closedir(dir);
|
||||
free(hnpHead);
|
||||
/* 安装失败卸载当前包 */
|
||||
HnpUnInstall(hnpDstPath, hnpDstPath->hnpVersionPath, false);
|
||||
return ret;
|
||||
}
|
||||
free(hnpHead);
|
||||
hnpHead = NULL;
|
||||
HNP_LOGI("install hnp path[%s], dst path[%s]", srcPath, hnpDstPath->hnpVersionPath);
|
||||
count++;
|
||||
}
|
||||
closedir(dir);
|
||||
if (count == 0) {
|
||||
HNP_LOGI("install hnp path[%s] is empty.", srcPath);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HnpCmdInstall(int argc, char *argv[])
|
||||
{
|
||||
char srcPath[MAX_FILE_PATH_LEN];
|
||||
char dstPath[MAX_FILE_PATH_LEN];
|
||||
unsigned long uid;
|
||||
char *installPath = NULL;
|
||||
char *softwarePath[MAX_SOFTWARE_NUM] = {0};
|
||||
int count = 0;
|
||||
int uid = 0;
|
||||
char *uidArg = NULL;
|
||||
bool isForce = false;
|
||||
int ret;
|
||||
NativeHnpPath hnpDstPath = {0};
|
||||
int ch;
|
||||
char *ptr;
|
||||
|
||||
if (argc < HNP_INDEX_5) {
|
||||
HNP_LOGE("hnp install args num[%u] unsuccess!", argc);
|
||||
return HNP_ERRNO_INSTALLER_ARGV_NUM_INVALID;
|
||||
optind = 1; // 从头开始遍历参数
|
||||
while ((ch = getopt_long(argc, argv, "hu:p:i:f", NULL, NULL)) != -1) {
|
||||
switch (ch) {
|
||||
case 'h' :
|
||||
return HNP_ERRNO_OPERATOR_ARGV_MISS;
|
||||
case 'u': //uid
|
||||
uidArg = optarg;
|
||||
int ret = HnpInstallerUidGet(uidArg, &uid);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("hnp install arg uid[%s] invalid", uidArg);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
case 'p': //hnp software path
|
||||
ptr = strstr(optarg, ".hnp");
|
||||
if ((ptr == NULL) || (strcmp(ptr, ".hnp") != 0)) {
|
||||
HNP_LOGE("package name[%s] invalid", optarg);
|
||||
return HNP_ERRNO_INSTALLER_GET_HNP_NAME_FAILED;
|
||||
}
|
||||
if ((count + 1) >= MAX_SOFTWARE_NUM) {
|
||||
HNP_LOGE("hnp install software must less than %d", MAX_SOFTWARE_NUM);
|
||||
return HNP_ERRNO_INSTALLER_SOFTWARE_NUM_OVERSIZE;
|
||||
}
|
||||
softwarePath[count++] = (char *)optarg;
|
||||
break;
|
||||
case 'i': //private package name
|
||||
installPath = (char *)optarg;
|
||||
break;
|
||||
case 'f': //is force
|
||||
isForce = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = HnpInstallerUidGet(argv[HNP_INDEX_2], &uid);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("hnp install arg uid[%s] invalid", argv[HNP_INDEX_2]);
|
||||
return ret;
|
||||
if ((uidArg == NULL) || (count == 0)) {
|
||||
HNP_LOGE("hnp install params invalid, uid[%s] hnp software num[%d]", uidArg, count);
|
||||
return HNP_ERRNO_OPERATOR_ARGV_MISS;
|
||||
}
|
||||
|
||||
/* 拼接安装路径 */
|
||||
if (sprintf_s(dstPath, MAX_FILE_PATH_LEN, HNP_DEFAULT_INSTALL_ROOT_PATH"%lu/", uid) < 0) {
|
||||
HNP_LOGE("hnp install sprintf unsuccess, uid:%lu", uid);
|
||||
return HNP_ERRNO_INSTALLER_GET_HNP_PATH_FAILED;
|
||||
}
|
||||
|
||||
/* 验证native软件包路径与安装路径是否存在 */
|
||||
if ((GetRealPath(argv[HNP_INDEX_3], srcPath) != 0) || (access(dstPath, F_OK) != 0)) {
|
||||
HNP_LOGE("hnp install path invalid! src path=%s, dst path=%s", argv[HNP_INDEX_3], dstPath);
|
||||
return HNP_ERRNO_INSTALLER_GET_REALPATH_FAILED;
|
||||
}
|
||||
|
||||
/* 获取参数是否需要强制覆盖 */
|
||||
if ((argc == HNP_INDEX_6) && (strcmp(argv[HNP_INDEX_5], "-f") == 0)) {
|
||||
isForce = true;
|
||||
}
|
||||
|
||||
if (strcmp(argv[HNP_INDEX_4], "null") == 0) {
|
||||
ret = sprintf_s(hnpDstPath.hnpBasePath, MAX_FILE_PATH_LEN, "%shnppublic/", dstPath);
|
||||
} else {
|
||||
ret = sprintf_s(hnpDstPath.hnpBasePath, MAX_FILE_PATH_LEN, "%shnp/%s/", dstPath, argv[HNP_INDEX_4]);
|
||||
}
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("hnp install public base path sprintf unsuccess.");
|
||||
return HNP_ERRNO_INSTALLER_GET_HNP_PATH_FAILED;
|
||||
}
|
||||
|
||||
HNP_LOGI("hnp install start now! src path=%s, dst path=%s, is force=%d", argv[HNP_INDEX_3], hnpDstPath.hnpBasePath,
|
||||
isForce);
|
||||
ret = HnpDirReadAndInstall(srcPath, &hnpDstPath, isForce);
|
||||
HNP_LOGI("hnp install end, ret=%d", ret);
|
||||
return ret;
|
||||
return HnpInsatllPre(uid, softwarePath, count, installPath, isForce);
|
||||
}
|
||||
|
||||
int HnpCmdUnInstall(int argc, char *argv[])
|
||||
static int HnpUnInstallPre(int uid, const char *hnpName, const char *version, char *uninstallPath)
|
||||
{
|
||||
unsigned long uid;
|
||||
char pathTmp[MAX_FILE_PATH_LEN];
|
||||
NativeHnpPath hnpDstPath = {0};
|
||||
int ret;
|
||||
|
||||
if (argc < HNP_INDEX_6) {
|
||||
HNP_LOGE("hnp uninstall args num[%u] unsuccess!", argc);
|
||||
return HNP_ERRNO_UNINSTALLER_ARGV_NUM_INVALID;
|
||||
}
|
||||
|
||||
ret = HnpInstallerUidGet(argv[HNP_INDEX_2], &uid);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("hnp installer arg uid[%s] invalid", argv[HNP_INDEX_2]);
|
||||
return HNP_ERRNO_INSTALLER_ARGV_UID_INVALID;
|
||||
}
|
||||
|
||||
if (strcmp(argv[HNP_INDEX_5], "null") == 0) {
|
||||
ret = sprintf_s(pathTmp, MAX_FILE_PATH_LEN, "hnppublic");
|
||||
if (uninstallPath == NULL) {
|
||||
/* 拼接基本路径 */
|
||||
if (sprintf_s(hnpDstPath.hnpBasePath, MAX_FILE_PATH_LEN, HNP_DEFAULT_INSTALL_ROOT_PATH"/%d/hnp/hnppublic",
|
||||
uid) < 0) {
|
||||
HNP_LOGE("hnp uninstall base path sprintf unsuccess,uid:%d, process name[%s]", uid, hnpName);
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
} else {
|
||||
ret = sprintf_s(pathTmp, MAX_FILE_PATH_LEN, "hnp/%s", argv[HNP_INDEX_5]);
|
||||
}
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("hnp uninstall path sprintf unsuccess.");
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
if (GetRealPath(uninstallPath, hnpDstPath.hnpBasePath) != 0) {
|
||||
HNP_LOGE("hnp uninstall path[%s] is not exist", uninstallPath);
|
||||
return HNP_ERRNO_UNINSTALLER_HNP_PATH_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
|
||||
if (sprintf_s(hnpDstPath.hnpVersionPath, MAX_FILE_PATH_LEN, HNP_DEFAULT_INSTALL_ROOT_PATH"%lu/%s/%s.org/%s_%s/",
|
||||
uid, pathTmp, argv[HNP_INDEX_3], argv[HNP_INDEX_3], argv[HNP_INDEX_4]) < 0) {
|
||||
HNP_LOGE("hnp uninstall path sprintf unsuccess, uid:%lu, program name[%s], version[%s]", uid,
|
||||
argv[HNP_INDEX_3], argv[HNP_INDEX_4]);
|
||||
if (sprintf_s(hnpDstPath.hnpSoftwarePath, MAX_FILE_PATH_LEN, "%s/%s.org", hnpDstPath.hnpBasePath, hnpName) < 0) {
|
||||
HNP_LOGE("hnp uninstall path sprintf unsuccess,base path:%s,process name[%s]", hnpDstPath.hnpBasePath, hnpName);
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
|
||||
if (sprintf_s(hnpDstPath.hnpVersionPath, MAX_FILE_PATH_LEN, "%s/%s_%s", hnpDstPath.hnpSoftwarePath, hnpName,
|
||||
version) < 0) {
|
||||
HNP_LOGE("hnp uninstall path sprintf unsuccess,software path:%s, process name[%s],version[%s]",
|
||||
hnpDstPath.hnpSoftwarePath, hnpName, version);
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
|
||||
@ -543,18 +487,7 @@ int HnpCmdUnInstall(int argc, char *argv[])
|
||||
return HNP_ERRNO_UNINSTALLER_HNP_PATH_NOT_EXIST;
|
||||
}
|
||||
|
||||
/* 拼接基本路径 */
|
||||
if (sprintf_s(hnpDstPath.hnpProgramPath, MAX_FILE_PATH_LEN, HNP_DEFAULT_INSTALL_ROOT_PATH"%lu/%s/%s.org/", uid,
|
||||
pathTmp, argv[HNP_INDEX_3]) < 0) {
|
||||
HNP_LOGE("hnp uninstall pro path sprintf unsuccess, uid:%lu, program name[%s]", uid, argv[HNP_INDEX_3]);
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
if (sprintf_s(hnpDstPath.hnpBasePath, MAX_FILE_PATH_LEN, HNP_DEFAULT_INSTALL_ROOT_PATH"%lu/%s/", uid,
|
||||
pathTmp) < 0) {
|
||||
HNP_LOGE("hnp uninstall base path sprintf unsuccess, uid:%lu, program name[%s]", uid, argv[HNP_INDEX_3]);
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
if (strcpy_s(hnpDstPath.hnpProgramName, MAX_FILE_PATH_LEN, argv[HNP_INDEX_3]) != EOK) {
|
||||
if (strcpy_s(hnpDstPath.hnpSoftwareName, MAX_FILE_PATH_LEN, hnpName) != EOK) {
|
||||
HNP_LOGE("hnp uninstall strcpy unsuccess.");
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
@ -562,6 +495,52 @@ int HnpCmdUnInstall(int argc, char *argv[])
|
||||
return HnpUnInstall(&hnpDstPath, hnpDstPath.hnpVersionPath, true);
|
||||
}
|
||||
|
||||
int HnpCmdUnInstall(int argc, char *argv[])
|
||||
{
|
||||
char *uninstallPath = NULL;
|
||||
int uid;
|
||||
char *uidArg = NULL;
|
||||
char *hnpName = NULL;
|
||||
char *version = NULL;
|
||||
int ret;
|
||||
int ch;
|
||||
|
||||
optind = 1; // 从头开始遍历参数
|
||||
while ((ch = getopt_long(argc, argv, "hu:n:v:i:", NULL, NULL)) != -1) {
|
||||
switch (ch) {
|
||||
case 'h' :
|
||||
return HNP_ERRNO_OPERATOR_ARGV_MISS;
|
||||
case 'u': //uid
|
||||
uidArg = optarg;
|
||||
ret = HnpInstallerUidGet(uidArg, &uid);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("hnp install arg uid[%s] invalid", uidArg);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
case 'n': //hnp software name
|
||||
hnpName = optarg;
|
||||
break;
|
||||
case 'v': //version
|
||||
version = optarg;
|
||||
break;
|
||||
case 'i': //package name
|
||||
uninstallPath = (char *)optarg;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((uidArg == NULL) || (hnpName == NULL) || (version == NULL)) {
|
||||
HNP_LOGE("hnp uninstall params invalid uid[%s], hnp software[%s], version[%s]", uidArg, hnpName, version);
|
||||
return HNP_ERRNO_OPERATOR_ARGV_MISS;
|
||||
}
|
||||
|
||||
return HnpUnInstallPre(uid, hnpName, version, uninstallPath);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -22,32 +22,30 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// 0x801201 打包命令参数错误
|
||||
#define HNP_ERRNO_PACK_ARGV_NUM_INVALID HNP_ERRNO_COMMON(HNP_MID_PACK, 0x1)
|
||||
// 0x801201 获取绝对路径失败
|
||||
#define HNP_ERRNO_PACK_GET_REALPATH_FAILED HNP_ERRNO_COMMON(HNP_MID_PACK, 0x1)
|
||||
|
||||
// 0x801202 获取绝对路径失败
|
||||
#define HNP_ERRNO_PACK_GET_REALPATH_FAILED HNP_ERRNO_COMMON(HNP_MID_PACK, 0x2)
|
||||
// 0x801202 组装hnp输出路径失败
|
||||
#define HNP_ERRNO_PACK_GET_HNP_PATH_FAILED HNP_ERRNO_COMMON(HNP_MID_PACK, 0x2)
|
||||
|
||||
// 0x801203 缺少操作参数
|
||||
#define HNP_ERRNO_PACK_MISS_OPERATOR_PARAM HNP_ERRNO_COMMON(HNP_MID_PACK, 0x3)
|
||||
// 0x801203 压缩目录失败
|
||||
#define HNP_ERRNO_PACK_ZIP_DIR_FAILED HNP_ERRNO_COMMON(HNP_MID_PACK, 0x3)
|
||||
|
||||
// 0x801204 读取配置文件流失败
|
||||
#define HNP_ERRNO_PACK_READ_FILE_STREAM_FAILED HNP_ERRNO_COMMON(HNP_MID_PACK, 0x4)
|
||||
/* hnp打包参数 */
|
||||
typedef struct HnpPackArgvStru {
|
||||
char *source; // 待打包目录
|
||||
char *output; // 打包后文件存放目录
|
||||
char *name; // 软件包名
|
||||
char *version; // 版本号
|
||||
} HnpPackArgv;
|
||||
|
||||
// 0x801205 解析json信息失败
|
||||
#define HNP_ERRNO_PACK_PARSE_JSON_FAILED HNP_ERRNO_COMMON(HNP_MID_PACK, 0x5)
|
||||
|
||||
// 0x801206 未找到json项
|
||||
#define HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND HNP_ERRNO_COMMON(HNP_MID_PACK, 0x6)
|
||||
|
||||
// 0x801207 解析json数组失败
|
||||
#define HNP_ERRNO_PACK_GET_ARRAY_ITRM_FAILED HNP_ERRNO_COMMON(HNP_MID_PACK, 0x7)
|
||||
|
||||
// 0x801208 组装hnp输出路径失败
|
||||
#define HNP_ERRNO_PACK_GET_HNP_PATH_FAILED HNP_ERRNO_COMMON(HNP_MID_PACK, 0x8)
|
||||
|
||||
// 0x801209 压缩目录失败
|
||||
#define HNP_ERRNO_PACK_ZIP_DIR_FAILED HNP_ERRNO_COMMON(HNP_MID_PACK, 0x9)
|
||||
/* hnp打包信息 */
|
||||
typedef struct HnpPackInfoStru {
|
||||
char source[MAX_FILE_PATH_LEN]; // 待打包目录
|
||||
char output[MAX_FILE_PATH_LEN]; // 打包后文件存放目录
|
||||
HnpCfgInfo cfgInfo; // hnp配置信息
|
||||
int hnpCfgExist; // 是否存在配置文件
|
||||
} HnpPackInfo;
|
||||
|
||||
int HnpCmdPack(int argc, char *argv[]);
|
||||
|
||||
|
@ -15,9 +15,10 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "securec.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "hnp_pack.h"
|
||||
|
||||
@ -25,16 +26,56 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static int PackHnp(const char *hnpSrcPath, const char *hnpDstPath, const char *hnpName, NativeHnpHead *hnpHead)
|
||||
static int AddHnpCfgFileToZip(char *zipPath, const char *hnpSrcPath, HnpCfgInfo *hnpCfg)
|
||||
{
|
||||
int ret;
|
||||
char *strPtr;
|
||||
int offset;
|
||||
char hnpCfgFile[MAX_FILE_PATH_LEN];
|
||||
char *buff;
|
||||
|
||||
// zip压缩文件内只保存相对路径,不保存绝对路径信息,偏移到压缩文件夹位置
|
||||
strPtr = strrchr(hnpSrcPath, DIR_SPLIT_SYMBOL);
|
||||
if (strPtr == NULL) {
|
||||
offset = 0;
|
||||
} else {
|
||||
offset = strPtr - hnpSrcPath + 1;
|
||||
}
|
||||
|
||||
// zip函数根据后缀是否'/'区分目录还是文件
|
||||
ret = sprintf_s(hnpCfgFile, MAX_FILE_PATH_LEN, "%s%c"HNP_CFG_FILE_NAME, hnpSrcPath + offset, DIR_SPLIT_SYMBOL);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
// 根据配置信息生成hnp.json内容
|
||||
ret = GetHnpJsonBuff(hnpCfg, &buff);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("get hnp json content by cfg info unsuccess.");
|
||||
return ret;
|
||||
}
|
||||
// 将hnp.json文件写入到.hnp压缩文件中
|
||||
ret = HnpAddFileToZip(zipPath, hnpCfgFile, buff, strlen(buff) + 1);
|
||||
free(buff);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("add file to zip failed.zip=%s, file=%s", zipPath, hnpCfgFile);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PackHnp(const char *hnpSrcPath, const char *hnpDstPath, HnpPackInfo *hnpPack)
|
||||
{
|
||||
int ret;
|
||||
char hnp_file_path[MAX_FILE_PATH_LEN];
|
||||
HnpCfgInfo *hnpCfg = &hnpPack->cfgInfo;
|
||||
|
||||
HNP_LOGI("PackHnp start. srcPath=%s, hnpName=%s, hnpVer=%s, hnpDstPath=%s ",
|
||||
hnpSrcPath, hnpName, hnpHead->hnpVersion, hnpDstPath);
|
||||
|
||||
hnpSrcPath, hnpCfg->name, hnpCfg->version, hnpDstPath);
|
||||
|
||||
/* 拼接hnp文件名 */
|
||||
ret = sprintf_s(hnp_file_path, MAX_FILE_PATH_LEN, "%s/%s.hnp", hnpDstPath, hnpName);
|
||||
ret = sprintf_s(hnp_file_path, MAX_FILE_PATH_LEN, "%s/%s.hnp", hnpDstPath, hnpCfg->name);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf unsuccess.");
|
||||
return HNP_ERRNO_PACK_GET_HNP_PATH_FAILED;
|
||||
@ -44,238 +85,151 @@ static int PackHnp(const char *hnpSrcPath, const char *hnpDstPath, const char *h
|
||||
ret = HnpZip(hnpSrcPath, hnp_file_path);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("zip dir unsuccess! srcPath=%s, hnpName=%s, hnpVer=%s, hnpDstPath=%s ret=%d",
|
||||
hnpSrcPath, hnpName, hnpHead->hnpVersion, hnpDstPath, ret);
|
||||
hnpSrcPath, hnpCfg->name, hnpCfg->version, hnpDstPath, ret);
|
||||
return HNP_ERRNO_PACK_ZIP_DIR_FAILED;
|
||||
}
|
||||
|
||||
hnpHead->magic = HNP_HEAD_MAGIC;
|
||||
hnpHead->version = HNP_HEAD_VERSION;
|
||||
hnpHead->headLen = sizeof(NativeHnpHead) + hnpHead->linkNum * sizeof(NativeBinLink);
|
||||
|
||||
/* 向生成的.hnp文件头写入配置信息 */
|
||||
ret = HnpWriteToZipHead(hnp_file_path, (char*)hnpHead, hnpHead->headLen);
|
||||
|
||||
HNP_LOGI("PackHnp end. srcPath=%s, hnpName=%s, hnpVer=%s, hnpDstPath=%s headlen=%d, linkNum=%d, ret=%d",
|
||||
hnpSrcPath, hnpName, hnpHead->hnpVersion, hnpDstPath, hnpHead->headLen, hnpHead->linkNum, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ParseLinksJsonToHnpHead(cJSON *linksItem, NativeHnpHead *hnpHead, NativeBinLink **linkArr)
|
||||
{
|
||||
NativeBinLink *linkArray = NULL;
|
||||
int i;
|
||||
|
||||
int linkArrayNum = cJSON_GetArraySize(linksItem);
|
||||
if (linkArrayNum != 0) {
|
||||
hnpHead->linkNum = linkArrayNum;
|
||||
linkArray = (NativeBinLink*)malloc(sizeof(NativeBinLink) * linkArrayNum);
|
||||
if (linkArray == NULL) {
|
||||
HNP_LOGE("malloc unsuccess.");
|
||||
return HNP_ERRNO_NOMEM;
|
||||
}
|
||||
for (i = 0; i < linkArrayNum; i++) {
|
||||
cJSON *link = cJSON_GetArrayItem(linksItem, i);
|
||||
if (link == NULL) {
|
||||
free(linkArray);
|
||||
return HNP_ERRNO_PACK_GET_ARRAY_ITRM_FAILED;
|
||||
}
|
||||
cJSON *sourceItem = cJSON_GetObjectItem(link, "source");
|
||||
if ((sourceItem == NULL) || (sourceItem->valuestring == NULL)) {
|
||||
HNP_LOGE("get source info in cfg unsuccess.");
|
||||
free(linkArray);
|
||||
return HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
if (strcpy_s(linkArray[i].source, MAX_FILE_PATH_LEN, sourceItem->valuestring) != EOK) {
|
||||
HNP_LOGE("strcpy unsuccess.");
|
||||
free(linkArray);
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
linkArray[i].target[0] = '\0'; //允许target不填,软链接默认使用原二进制名称
|
||||
cJSON *targetItem = cJSON_GetObjectItem(link, "target");
|
||||
if ((targetItem != NULL) && (targetItem->valuestring != NULL) &&
|
||||
(strcpy_s(linkArray[i].target, MAX_FILE_PATH_LEN, targetItem->valuestring) != EOK)) {
|
||||
HNP_LOGE("strcpy unsuccess.");
|
||||
free(linkArray);
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
}
|
||||
*linkArr = linkArray;
|
||||
} else {
|
||||
hnpHead->linkNum = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ParseJsonStreamToHnpHead(cJSON *json, char *name, NativeHnpHead *hnpHead, NativeBinLink **linkArr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
cJSON *typeItem = cJSON_GetObjectItem(json, "type");
|
||||
if ((typeItem == NULL) || (typeItem->valuestring == NULL)) {
|
||||
HNP_LOGE("get type info in cfg unsuccess.");
|
||||
return HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
if (strcmp(typeItem->valuestring, "hnp-config") != 0) {
|
||||
HNP_LOGE("type info not match.type=%s", typeItem->valuestring);
|
||||
return HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
cJSON *nameItem = cJSON_GetObjectItem(json, "name");
|
||||
if ((nameItem == NULL) || (nameItem->valuestring == NULL)) {
|
||||
HNP_LOGE("get name info in cfg unsuccess.");
|
||||
return HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
ret = strcpy_s(name, MAX_FILE_PATH_LEN, nameItem->valuestring);
|
||||
if (ret != EOK) {
|
||||
HNP_LOGE("strcpy unsuccess.");
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
cJSON *versionItem = cJSON_GetObjectItem(json, "version");
|
||||
if ((versionItem == NULL) || (versionItem->valuestring == NULL)) {
|
||||
HNP_LOGE("get version info in cfg unsuccess.");
|
||||
return HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
ret = strcpy_s(hnpHead->hnpVersion, HNP_VERSION_LEN, versionItem->valuestring);
|
||||
if (ret != EOK) {
|
||||
HNP_LOGE("strcpy unsuccess.");
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
cJSON *installItem = cJSON_GetObjectItem(json, "install");
|
||||
if (installItem == NULL) {
|
||||
HNP_LOGE("get install info in cfg unsuccess.");
|
||||
return HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND;
|
||||
}
|
||||
cJSON *linksItem = cJSON_GetObjectItem(installItem, "links");
|
||||
if (linksItem != NULL) {
|
||||
ret = ParseLinksJsonToHnpHead(linksItem, hnpHead, linkArr);
|
||||
/* 如果软件包中不存在hnp.json文件,则需要在hnp压缩文件中添加 */
|
||||
if (hnpPack->hnpCfgExist == 0) {
|
||||
ret = AddHnpCfgFileToZip(hnp_file_path, hnpSrcPath, &hnpPack->cfgInfo);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("add file to zip failed ret=%d. zip=%s, src=%s",
|
||||
ret, hnp_file_path, hnpSrcPath);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
hnpHead->linkNum = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ParseHnpCfgToHead(const char *hnpCfgPath, char *name, NativeHnpHead *hnpHead, NativeBinLink **linkArr)
|
||||
{
|
||||
int ret;
|
||||
char *cfgStream = NULL;
|
||||
cJSON *json;
|
||||
int size;
|
||||
|
||||
ret = ReadFileToStream(hnpCfgPath, &cfgStream, &size);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("read cfg file[%s] unsuccess.", hnpCfgPath);
|
||||
return HNP_ERRNO_PACK_READ_FILE_STREAM_FAILED;
|
||||
}
|
||||
json = cJSON_Parse(cfgStream);
|
||||
free(cfgStream);
|
||||
if (json == NULL) {
|
||||
HNP_LOGE("parse json file[%s] unsuccess.", hnpCfgPath);
|
||||
return HNP_ERRNO_PACK_PARSE_JSON_FAILED;
|
||||
}
|
||||
ret = ParseJsonStreamToHnpHead(json, name, hnpHead, linkArr);
|
||||
cJSON_Delete(json);
|
||||
HNP_LOGI("PackHnp end. srcPath=%s, hnpName=%s, hnpVer=%s, hnpDstPath=%s, linkNum=%d, ret=%d",
|
||||
hnpSrcPath, hnpCfg->name, hnpCfg->version, hnpDstPath, hnpCfg->linkNum, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int PackHnpWithCfg(const char *hnpSrcPath, const char *hnpDstPath, const char *hnpCfgPath)
|
||||
static int GetHnpCfgInfo(const char *hnpCfgPath, const char *sourcePath, HnpCfgInfo *hnpCfg)
|
||||
{
|
||||
NativeHnpHead head;
|
||||
NativeHnpHead *hnpHead;
|
||||
NativeBinLink *linkArr = NULL;
|
||||
char name[MAX_FILE_PATH_LEN] = {0};
|
||||
int ret;
|
||||
char linksource[MAX_FILE_PATH_LEN] = {0};
|
||||
|
||||
HNP_LOGI("pack hnp start. srcPath=%s, hnpCfg=%s, hnpDstPath=%s",
|
||||
hnpSrcPath, hnpCfgPath, hnpDstPath);
|
||||
|
||||
ret = ParseHnpCfgToHead(hnpCfgPath, name, &head, &linkArr);
|
||||
int ret = ParseHnpCfgFile(hnpCfgPath, hnpCfg);
|
||||
if (ret != 0) {
|
||||
HNP_LOGE("parse hnp cfg[%s] unsuccess! ret=%d", hnpCfgPath, ret);
|
||||
return ret;
|
||||
}
|
||||
int headLen = sizeof(NativeHnpHead) + head.linkNum * sizeof(NativeBinLink);
|
||||
|
||||
if (head.linkNum != 0) {
|
||||
hnpHead = (NativeHnpHead*)malloc(headLen);
|
||||
if (hnpHead == NULL) {
|
||||
free(linkArr);
|
||||
return HNP_ERRNO_NOMEM;
|
||||
/* 校验软连接的source文件是否存在 */
|
||||
linkArr = hnpCfg->links;
|
||||
for (unsigned int i = 0; i < hnpCfg->linkNum; i++, linkArr++) {
|
||||
int ret = sprintf_s(linksource, MAX_FILE_PATH_LEN, "%s/%s", sourcePath, linkArr->source);
|
||||
if (ret < 0) {
|
||||
free(hnpCfg->links);
|
||||
hnpCfg->links = NULL;
|
||||
HNP_LOGE("sprintf unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
(void)memcpy_s(hnpHead, headLen, &head, sizeof(NativeHnpHead));
|
||||
(void)memcpy_s(hnpHead->links, sizeof(NativeBinLink) * head.linkNum,
|
||||
linkArr, sizeof(NativeBinLink) * head.linkNum);
|
||||
if (access(linksource, F_OK) != 0) {
|
||||
free(hnpCfg->links);
|
||||
hnpCfg->links = NULL;
|
||||
HNP_LOGE("links source[%s] not exist.", linksource);
|
||||
return HNP_ERRNO_PACK_GET_REALPATH_FAILED;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ParsePackArgs(HnpPackArgv *packArgv, HnpPackInfo *packInfo)
|
||||
{
|
||||
char cfgPath[MAX_FILE_PATH_LEN];
|
||||
|
||||
if (packArgv->source == NULL) {
|
||||
HNP_LOGE("source dir is null.");
|
||||
return HNP_ERRNO_OPERATOR_ARGV_MISS;
|
||||
}
|
||||
if (GetRealPath(packArgv->source, packInfo->source) != 0) {
|
||||
HNP_LOGE("source dir path=%s is invalid.", packArgv->source);
|
||||
return HNP_ERRNO_PACK_GET_REALPATH_FAILED;
|
||||
}
|
||||
if (packArgv->output == NULL) {
|
||||
packArgv->output = ".";
|
||||
}
|
||||
|
||||
if (GetRealPath(packArgv->output, packInfo->output) != 0) {
|
||||
HNP_LOGE("output dir path=%s is invalid.", packArgv->output);
|
||||
return HNP_ERRNO_PACK_GET_REALPATH_FAILED;
|
||||
}
|
||||
/* 确认hnp.json文件是否存在,存在则对hnp.json文件进行解析并校验内容是否正确 */
|
||||
int ret = sprintf_s(cfgPath, MAX_FILE_PATH_LEN, "%s/"HNP_CFG_FILE_NAME, packInfo->source);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
}
|
||||
if (access(cfgPath, F_OK) != 0) {
|
||||
/* hnp.json文件不存在则要求用户传入name和version信息 */
|
||||
if ((packArgv->name == NULL) || (packArgv->version == NULL)) {
|
||||
HNP_LOGE("name or version argv is miss.");
|
||||
return HNP_ERRNO_OPERATOR_ARGV_MISS;
|
||||
}
|
||||
if (strcpy_s(packInfo->cfgInfo.name, MAX_FILE_PATH_LEN, packArgv->name) != EOK) {
|
||||
HNP_LOGE("strcpy name argv unsuccess.");
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
if (strcpy_s(packInfo->cfgInfo.version, HNP_VERSION_LEN, packArgv->version) != EOK) {
|
||||
HNP_LOGE("strcpy version argv unsuccess.");
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
packInfo->hnpCfgExist = 0;
|
||||
} else {
|
||||
hnpHead = &head;
|
||||
ret = GetHnpCfgInfo(cfgPath, packInfo->source, &packInfo->cfgInfo);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
packInfo->hnpCfgExist = 1;
|
||||
}
|
||||
|
||||
HNP_LOGI("pack hnp end. ret=%d, hnpName=%s, version=%s, linksNum=%d",
|
||||
ret, name, hnpHead->hnpVersion, hnpHead->linkNum);
|
||||
|
||||
ret = PackHnp(hnpSrcPath, hnpDstPath, name, hnpHead);
|
||||
|
||||
if (head.linkNum != 0) {
|
||||
free(linkArr);
|
||||
free(hnpHead);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HnpCmdPack(int argc, char *argv[])
|
||||
{
|
||||
int index = 0;
|
||||
char srcPath[MAX_FILE_PATH_LEN];
|
||||
char dstPath[MAX_FILE_PATH_LEN];
|
||||
char cfgPath[MAX_FILE_PATH_LEN] = {0};
|
||||
char *name = NULL;
|
||||
char *version = NULL;
|
||||
HnpPackArgv packArgv = {0};
|
||||
HnpPackInfo packInfo = {0};
|
||||
int opt;
|
||||
|
||||
if (argc < HNP_INDEX_4) {
|
||||
HNP_LOGE("pack args num[%u] unsuccess!", argc);
|
||||
return HNP_ERRNO_PACK_ARGV_NUM_INVALID;
|
||||
}
|
||||
|
||||
if ((GetRealPath(argv[HNP_INDEX_2], srcPath) != 0) || (GetRealPath(argv[HNP_INDEX_3], dstPath) != 0)) {
|
||||
HNP_LOGE("pack path invalid! srcPath=%s, dstPath=%s", argv[HNP_INDEX_2], argv[HNP_INDEX_3]);
|
||||
return HNP_ERRNO_PACK_GET_REALPATH_FAILED;
|
||||
}
|
||||
|
||||
index = HNP_INDEX_4;
|
||||
while (index < argc) {
|
||||
if ((!strcmp(argv[index], "-name")) && (index + 1 < argc)) {
|
||||
name = argv[++index];
|
||||
} else if ((!strcmp(argv[index], "-v")) && (index + 1 < argc)) {
|
||||
version = argv[++index];
|
||||
} else if ((!strcmp(argv[index], "-cfg")) && (index + 1 < argc)) {
|
||||
if (GetRealPath(argv[++index], cfgPath) != 0) {
|
||||
HNP_LOGE("cfg path[%s] invalid!", argv[index]);
|
||||
return HNP_ERRNO_PACK_GET_REALPATH_FAILED;
|
||||
}
|
||||
optind = 1; // 从头开始遍历参数
|
||||
while ((opt = getopt_long(argc, argv, "hi:o:n:v:", NULL, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'h' :
|
||||
return HNP_ERRNO_OPERATOR_ARGV_MISS;
|
||||
case 'i' :
|
||||
packArgv.source = optarg;
|
||||
break;
|
||||
case 'o' :
|
||||
packArgv.output = optarg;
|
||||
break;
|
||||
case 'n' :
|
||||
packArgv.name = optarg;
|
||||
break;
|
||||
case 'v' :
|
||||
packArgv.version = optarg;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
if ((name != NULL) && (strlen(name) != 0) && (version != NULL) && (strlen(version) != 0)) {
|
||||
NativeHnpHead hnpHead;
|
||||
hnpHead.linkNum = 0;
|
||||
if (strcpy_s(hnpHead.hnpVersion, HNP_VERSION_LEN, version) != EOK) {
|
||||
HNP_LOGE("strcpy unsuccess.");
|
||||
return HNP_ERRNO_BASE_COPY_FAILED;
|
||||
}
|
||||
return PackHnp(srcPath, dstPath, name, &hnpHead);
|
||||
// 解析参数并生成打包信息
|
||||
int ret = ParsePackArgs(&packArgv, &packInfo);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (cfgPath[0] != '\0') {
|
||||
return PackHnpWithCfg(srcPath, dstPath, cfgPath);
|
||||
// 根据打包信息进行打包操作
|
||||
ret = PackHnp(packInfo.source, packInfo.output, &packInfo);
|
||||
|
||||
// 释放软链接占用的内存
|
||||
if (packInfo.cfgInfo.links != NULL) {
|
||||
free(packInfo.cfgInfo.links);
|
||||
packInfo.cfgInfo.links = NULL;
|
||||
}
|
||||
|
||||
HNP_LOGE("pack args parse miss!");
|
||||
|
||||
return HNP_ERRNO_PACK_MISS_OPERATOR_PARAM;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -32,10 +32,13 @@ if (!defined(ohos_lite)) {
|
||||
"${appspawn_path}/service/hnp/base",
|
||||
"${appspawn_path}/service/hnp/pack/include",
|
||||
"${appspawn_path}/service/hnp/installer/include",
|
||||
"${appspawn_path}/interfaces/innerkits/hnp/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${appspawn_path}/interfaces/innerkits/hnp/src/hnp_api.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_file.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_json.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_log.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_sal.c",
|
||||
"${appspawn_path}/service/hnp/base/hnp_zip.c",
|
||||
|
@ -30,12 +30,13 @@
|
||||
#include "hnp_base.h"
|
||||
#include "hnp_pack.h"
|
||||
#include "hnp_installer.h"
|
||||
#include "hnp_api.h"
|
||||
#include "securec.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
#define HNP_BASE_PATH "/data/app/el1/bundle/10000"
|
||||
#define HNP_BASE_PATH "/data/app/el1/bundle/10000/hnp"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -81,14 +82,17 @@ void HnpPackWithoutBin(void)
|
||||
EXPECT_EQ(mkdir("./hnp_out", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
char arg1[] = "hnpcli";
|
||||
char arg2[] = "pack";
|
||||
char arg3[] = "./hnp_sample";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "-name";
|
||||
char arg6[] = "sample";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.1";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
|
||||
char arg3[] = "-i";
|
||||
char arg4[] = "./hnp_sample";
|
||||
char arg5[] = "-o";
|
||||
char arg6[] = "./hnp_out";
|
||||
char arg7[] = "-n";
|
||||
char arg8[] = "sample";
|
||||
char arg9[] = "-v";
|
||||
char arg10[] = "1.1";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), 0);
|
||||
}
|
||||
|
||||
@ -112,14 +116,17 @@ void HnpPackWithBin(void)
|
||||
EXPECT_EQ(mkdir("hnp_out", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
char arg1[] = "hnpcli";
|
||||
char arg2[] = "pack";
|
||||
char arg3[] = "./hnp_sample";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "-name";
|
||||
char arg6[] = "sample";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.1";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
|
||||
char arg3[] = "-i";
|
||||
char arg4[] = "./hnp_sample";
|
||||
char arg5[] = "-o";
|
||||
char arg6[] = "./hnp_out";
|
||||
char arg7[] = "-n";
|
||||
char arg8[] = "sample";
|
||||
char arg9[] = "-v";
|
||||
char arg10[] = "1.1";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), 0);
|
||||
}
|
||||
|
||||
@ -136,10 +143,47 @@ void HnpPackWithBinDelete(void)
|
||||
EXPECT_EQ(rmdir("hnp_out"), 0);
|
||||
}
|
||||
|
||||
void HnpPackWithSimple2Bin(void)
|
||||
{
|
||||
EXPECT_EQ(mkdir("hnp_sample2", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir("hnp_sample2/bin", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
FILE *fp = fopen("hnp_sample2/bin/out", "wb");
|
||||
EXPECT_NE(fp, nullptr);
|
||||
(void)fclose(fp);
|
||||
EXPECT_EQ(mkdir("hnp_out2", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
char arg1[] = "hnpcli";
|
||||
char arg2[] = "pack";
|
||||
char arg3[] = "-i";
|
||||
char arg4[] = "./hnp_sample2";
|
||||
char arg5[] = "-o";
|
||||
char arg6[] = "./hnp_out2";
|
||||
char arg7[] = "-n";
|
||||
char arg8[] = "sample2";
|
||||
char arg9[] = "-v";
|
||||
char arg10[] = "1.1";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), 0);
|
||||
}
|
||||
|
||||
void HnpPackWithBinSimple2Delete(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = remove("hnp_out2/sample2.hnp");
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret = remove("hnp_sample2/bin/out");
|
||||
EXPECT_EQ(ret, 0);
|
||||
EXPECT_EQ(rmdir("hnp_sample2/bin"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_sample2"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_out2"), 0);
|
||||
}
|
||||
|
||||
void HnpPackWithCfg(void)
|
||||
{
|
||||
FILE *fp;
|
||||
int whiteLen;
|
||||
int whitelen;
|
||||
|
||||
EXPECT_EQ(mkdir("hnp_sample", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir("hnp_sample/bin", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
@ -150,25 +194,25 @@ void HnpPackWithCfg(void)
|
||||
fp = fopen("hnp_sample/bin/out2", "wb");
|
||||
EXPECT_NE(fp, NULL);
|
||||
(void)fclose(fp);
|
||||
fp = fopen("hnp.cfg", "w");
|
||||
fp = fopen("hnp_sample/hnp.json", "w");
|
||||
EXPECT_NE(fp, nullptr);
|
||||
(void)fclose(fp);
|
||||
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "pack";
|
||||
char arg3[] = "./hnp_sample";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "-cfg";
|
||||
char arg6[] = "./hnp.cfg";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-i";
|
||||
char arg4[] = "./hnp_sample";
|
||||
char arg5[] = "-o";
|
||||
char arg6[] = "./hnp_out";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
char cfg[] = "{\"type\":\"hnp-config\",\"name\":\"sample\",\"version\":\"1.1\",\"install\":"
|
||||
"{\"links\":[{\"source\":\"bin/out\",\"target\":\"outt\"},{\"source\":\"bin/out2\","
|
||||
"\"target\":\"out2\"}]}}";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
whiteLen = fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp);
|
||||
fp = fopen("hnp_sample/hnp.json", "w");
|
||||
whitelen = fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp);
|
||||
(void)fclose(fp);
|
||||
EXPECT_EQ(whiteLen, strlen(cfg) + 1);
|
||||
EXPECT_EQ(whitelen, strlen(cfg) + 1);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), 0);
|
||||
}
|
||||
@ -183,7 +227,7 @@ void HnpPackWithCfgDelete(void)
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret = remove("hnp_sample/bin/out2");
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret = remove("hnp.cfg");
|
||||
ret = remove("hnp_sample/hnp.json");
|
||||
EXPECT_EQ(ret, 0);
|
||||
EXPECT_EQ(rmdir("hnp_sample/bin"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_sample"), 0);
|
||||
@ -194,11 +238,12 @@ void HnpInstall(void)
|
||||
{
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "install";
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char arg6[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char arg7[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), 0);
|
||||
@ -208,11 +253,13 @@ void HnpUnInstall(void)
|
||||
{
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "uninstall";
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "hnp_sample";
|
||||
char arg5[] = "1.1";
|
||||
char arg6[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-n";
|
||||
char arg6[] = "hnp_sample";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.1";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdUnInstall(argc, argv), 0);
|
||||
@ -221,12 +268,15 @@ void HnpUnInstall(void)
|
||||
void HnpInstallPrivate(void)
|
||||
{
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "uninstall";
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "test";
|
||||
char arg6[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg2[] = "install";
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char arg7[] = "-i";
|
||||
char arg8[] = HNP_BASE_PATH"/test";
|
||||
char arg9[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), 0);
|
||||
@ -236,11 +286,15 @@ void HnpUnInstallPrivate(void)
|
||||
{
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "uninstall";
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "hnp_sample";
|
||||
char arg5[] = "1.1";
|
||||
char arg6[] = "test";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-n";
|
||||
char arg6[] = "hnp_sample";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.1";
|
||||
char arg9[] = "-i";
|
||||
char arg10[] = "test";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdUnInstall(argc, argv), 0);
|
||||
@ -275,22 +329,24 @@ HWTEST(HnpInstallerTest, Hnp_Install_001, TestSize.Level0)
|
||||
char* argv[] = {arg1, arg2};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_INSTALLER_ARGV_NUM_INVALID);
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_OPERATOR_ARGV_MISS);
|
||||
}
|
||||
{ // param uid is invalid
|
||||
char arg3[] = "asd1231";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "asd1231";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_INSTALLER_ARGV_UID_INVALID);
|
||||
}
|
||||
{ // ok
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), 0);
|
||||
@ -321,21 +377,23 @@ HWTEST(HnpInstallerTest, Hnp_Install_002, TestSize.Level0)
|
||||
char arg2[] = "install";
|
||||
|
||||
{ // dir exist but force is false
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), 0);
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_INSTALLER_PATH_IS_EXIST);
|
||||
}
|
||||
{ //ok
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char arg6[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char arg7[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/hnppublic/bin/out", F_OK), 0);
|
||||
@ -364,10 +422,11 @@ HWTEST(HnpInstallerTest, Hnp_Install_003, TestSize.Level0)
|
||||
{ // scr path bin not exist
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
HnpPackWithoutBin();
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), 0);
|
||||
@ -378,10 +437,11 @@ HWTEST(HnpInstallerTest, Hnp_Install_003, TestSize.Level0)
|
||||
{ //ok
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
HnpPackWithBin();
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), 0);
|
||||
@ -410,42 +470,41 @@ HWTEST(HnpInstallerTest, Hnp_Install_004, TestSize.Level0)
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "install";
|
||||
|
||||
{ //src path file is not hnp and size is small than head
|
||||
FILE *fp = fopen("./hnp_out/example.zip", "wb");
|
||||
int data[5] = {1, 2, 3, 4, 5};
|
||||
EXPECT_NE(fp, NULL);
|
||||
fwrite(data, sizeof(int), 5, fp);
|
||||
(void)fclose(fp);
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char arg6[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_BASE_FILE_READ_FAILED);
|
||||
remove("./hnp_out/example.zip");
|
||||
}
|
||||
{ //src path file is not hnp
|
||||
FILE *fp = fopen("./hnp_out/example.zip", "wb");
|
||||
int data[15] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||
EXPECT_NE(fp, NULL);
|
||||
fwrite(data, sizeof(int), 15, fp);
|
||||
(void)fclose(fp);
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char arg6[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/example.zip";
|
||||
char arg7[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_BASE_MAGIC_CHECK_FAILED);
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_INSTALLER_GET_HNP_NAME_FAILED);
|
||||
remove("./hnp_out/example.zip");
|
||||
}
|
||||
{ // install dir path is invalid
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char arg7[] = "-i";
|
||||
char arg8[] = "/test";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_INSTALLER_GET_REALPATH_FAILED);
|
||||
}
|
||||
{ //ok
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char arg6[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char arg7[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/hnppublic/bin/out", F_OK), 0);
|
||||
@ -475,11 +534,12 @@ HWTEST(HnpInstallerTest, Hnp_Install_005, TestSize.Level0)
|
||||
char arg2[] = "install";
|
||||
|
||||
{ //ok
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char arg6[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char arg7[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/hnppublic/bin/outt", F_OK), 0);
|
||||
@ -504,21 +564,26 @@ HWTEST(HnpInstallerTest, Hnp_Install_006, TestSize.Level0)
|
||||
GTEST_LOG_(INFO) << "Hnp_Install_006 start";
|
||||
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH"/test", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
|
||||
HnpPackWithCfg();
|
||||
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "install";
|
||||
|
||||
{ //ok
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "test";
|
||||
char arg6[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char arg7[] = "-i";
|
||||
char arg8[] = HNP_BASE_PATH"/test";
|
||||
char arg9[] = "-f";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/hnp/test/bin/outt", F_OK), 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/hnp/test/bin/out2", F_OK), 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/test/bin/outt", F_OK), 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/test/bin/out2", F_OK), 0);
|
||||
}
|
||||
|
||||
HnpDeleteFolder(HNP_BASE_PATH);
|
||||
@ -553,28 +618,31 @@ HWTEST(HnpInstallerTest, Hnp_Install_007, TestSize.Level0)
|
||||
char arg2[] = "install";
|
||||
|
||||
{ // src dir path is invalid
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_in";
|
||||
char arg5[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_in/sample.hnp";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_INSTALLER_GET_REALPATH_FAILED);
|
||||
}
|
||||
{ // dst dir path is invalid
|
||||
char arg3[] = "10001";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10001";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_INSTALLER_GET_REALPATH_FAILED);
|
||||
}
|
||||
{ // ok
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-p";
|
||||
char arg6[] = "./hnp_out/sample.hnp";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdInstall(argc, argv), 0);
|
||||
@ -587,6 +655,107 @@ HWTEST(HnpInstallerTest, Hnp_Install_007, TestSize.Level0)
|
||||
GTEST_LOG_(INFO) << "Hnp_Install_007 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Hnp_Install_API_001
|
||||
* @tc.desc: Verify set Arg if NativeInstallHnp succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:issueI9DQSE
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST(HnpInstallerTest, Hnp_Install_API_001, TestSize.Level0)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "Hnp_Install_API_001 start";
|
||||
|
||||
int ret;
|
||||
const char *packages[1] = {"./hnp_out/sample.hnp"};
|
||||
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH"/test", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
|
||||
HnpPackWithCfg();
|
||||
|
||||
{ //param is invalid
|
||||
ret = NativeInstallHnp(NULL, packages, 1, HNP_BASE_PATH"/test", 1);
|
||||
EXPECT_EQ(ret, HNP_API_ERRNO_PARAM_INVALID);
|
||||
}
|
||||
{ //ok
|
||||
ret = NativeInstallHnp("10000", packages, 1, HNP_BASE_PATH"/test", 1);
|
||||
EXPECT_EQ(ret, 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/test/bin/outt", F_OK), 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/test/bin/out2", F_OK), 0);
|
||||
}
|
||||
|
||||
HnpDeleteFolder(HNP_BASE_PATH);
|
||||
HnpPackWithCfgDelete();
|
||||
|
||||
GTEST_LOG_(INFO) << "Hnp_Install_API_001 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Hnp_Install_API_002
|
||||
* @tc.desc: Verify set Arg if NativeInstallHnp succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:issueI9DQSE
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST(HnpInstallerTest, Hnp_Install_API_002, TestSize.Level0)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "Hnp_Install_API_002 start";
|
||||
|
||||
int ret;
|
||||
const char *packages[1] = {"./hnp_out/sample.hnp"};
|
||||
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH"/test", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
|
||||
HnpPackWithCfg();
|
||||
|
||||
{ //st dir path is invalid
|
||||
ret = NativeInstallHnp("10001", packages, 1, NULL, 1);
|
||||
EXPECT_NE(ret, 0);
|
||||
}
|
||||
|
||||
HnpDeleteFolder(HNP_BASE_PATH);
|
||||
HnpPackWithCfgDelete();
|
||||
|
||||
GTEST_LOG_(INFO) << "Hnp_Install_API_002 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Hnp_Install_API_003
|
||||
* @tc.desc: Verify more than 1 hnp package if NativeInstallHnp succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:issueI9DQSE
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST(HnpInstallerTest, Hnp_Install_API_003, TestSize.Level0)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "Hnp_Install_API_003 start";
|
||||
|
||||
int ret;
|
||||
const char *packages[2] = {"./hnp_out/sample.hnp", "./hnp_out2/sample2.hnp"};
|
||||
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH"/test", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
|
||||
HnpPackWithCfg();
|
||||
HnpPackWithSimple2Bin();
|
||||
|
||||
{ //ok
|
||||
ret = NativeInstallHnp("10000", packages, 2, HNP_BASE_PATH"/test", 1);
|
||||
EXPECT_EQ(ret, 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/test/bin/outt", F_OK), 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/test/bin/out2", F_OK), 0);
|
||||
EXPECT_EQ(access(HNP_BASE_PATH"/test/bin/out", F_OK), 0);
|
||||
}
|
||||
|
||||
HnpDeleteFolder(HNP_BASE_PATH);
|
||||
HnpPackWithCfgDelete();
|
||||
HnpPackWithBinSimple2Delete();
|
||||
|
||||
GTEST_LOG_(INFO) << "Hnp_Install_API_003 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Hnp_UnInstall_001
|
||||
* @tc.desc: Verify set Arg if HnpCmdUnInstall succeed.
|
||||
@ -609,24 +778,28 @@ HWTEST(HnpInstallerTest, Hnp_UnInstall_001, TestSize.Level0)
|
||||
char* argv[] = {arg1, arg2};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdUnInstall(argc, argv), HNP_ERRNO_UNINSTALLER_ARGV_NUM_INVALID);
|
||||
EXPECT_EQ(HnpCmdUnInstall(argc, argv), HNP_ERRNO_OPERATOR_ARGV_MISS);
|
||||
}
|
||||
{ // param uid is invalid
|
||||
char arg3[] = "asd1231";
|
||||
char arg4[] = "sample";
|
||||
char arg5[] = "1.1";
|
||||
char arg6[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "asd1231";
|
||||
char arg5[] = "-n";
|
||||
char arg6[] = "sample";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.1";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdUnInstall(argc, argv), HNP_ERRNO_INSTALLER_ARGV_UID_INVALID);
|
||||
}
|
||||
{ // ok
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "sample";
|
||||
char arg5[] = "1.1";
|
||||
char arg6[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-n";
|
||||
char arg6[] = "sample";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.1";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdUnInstall(argc, argv), 0);
|
||||
@ -650,17 +823,36 @@ HWTEST(HnpInstallerTest, Hnp_UnInstall_002, TestSize.Level0)
|
||||
GTEST_LOG_(INFO) << "Hnp_UnInstall_002 start";
|
||||
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH"/test", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
HnpPackWithCfg();
|
||||
HnpInstallPrivate();
|
||||
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "uninstall";
|
||||
{ // param uninstall path is invalid
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-n";
|
||||
char arg6[] = "sample";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.1";
|
||||
char arg9[] = "-i";
|
||||
char arg10[] = "/test";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdUnInstall(argc, argv), HNP_ERRNO_UNINSTALLER_HNP_PATH_NOT_EXIST);
|
||||
}
|
||||
{ // ok
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "sample";
|
||||
char arg5[] = "1.1";
|
||||
char arg6[] = "test";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-n";
|
||||
char arg6[] = "sample";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.1";
|
||||
char arg9[] = "-i";
|
||||
char arg10[] = HNP_BASE_PATH"/test";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdUnInstall(argc, argv), 0);
|
||||
@ -691,31 +883,37 @@ HWTEST(HnpInstallerTest, Hnp_UnInstall_003, TestSize.Level0)
|
||||
char arg2[] = "uninstall";
|
||||
|
||||
{ // param software name is invalid
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "sample2";
|
||||
char arg5[] = "1.1";
|
||||
char arg6[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-n";
|
||||
char arg6[] = "sample2";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.1";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdUnInstall(argc, argv), HNP_ERRNO_UNINSTALLER_HNP_PATH_NOT_EXIST);
|
||||
}
|
||||
{ // param software version is invalid
|
||||
char arg3[] = "10001";
|
||||
char arg4[] = "sample";
|
||||
char arg5[] = "1.3";
|
||||
char arg6[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10001";
|
||||
char arg5[] = "-n";
|
||||
char arg6[] = "sample";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.3";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdUnInstall(argc, argv), HNP_ERRNO_UNINSTALLER_HNP_PATH_NOT_EXIST);
|
||||
}
|
||||
{ // ok
|
||||
char arg3[] = "10000";
|
||||
char arg4[] = "sample";
|
||||
char arg5[] = "1.1";
|
||||
char arg6[] = "null";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg3[] = "-u";
|
||||
char arg4[] = "10000";
|
||||
char arg5[] = "-n";
|
||||
char arg6[] = "sample";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.1";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdUnInstall(argc, argv), 0);
|
||||
@ -727,4 +925,66 @@ HWTEST(HnpInstallerTest, Hnp_UnInstall_003, TestSize.Level0)
|
||||
GTEST_LOG_(INFO) << "Hnp_UnInstall_003 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Hnp_UnInstall_API_001
|
||||
* @tc.desc: Verify param invalid API NativeUnInstallHnp succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:issueI9DQSE
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST(HnpInstallerTest, Hnp_UnInstall_API_001, TestSize.Level0)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "Hnp_UnInstall_API_001 start";
|
||||
|
||||
int ret;
|
||||
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH"/test", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
HnpPackWithCfg();
|
||||
HnpInstallPrivate();
|
||||
|
||||
{ // param is invalid
|
||||
ret = NativeUnInstallHnp(NULL, "sample", "1.1", "/test");
|
||||
EXPECT_EQ(ret, HNP_API_ERRNO_PARAM_INVALID);
|
||||
}
|
||||
{ // ok
|
||||
ret = NativeUnInstallHnp("10000", "sample", "1.1", HNP_BASE_PATH"/test");
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
HnpDeleteFolder(HNP_BASE_PATH);
|
||||
HnpPackWithCfgDelete();
|
||||
|
||||
GTEST_LOG_(INFO) << "Hnp_UnInstall_API_001 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Hnp_UnInstall_API_002
|
||||
* @tc.desc: Verify path invalid API NativeUnInstallHnp succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:issueI9DQSE
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST(HnpInstallerTest, Hnp_UnInstall_API_002, TestSize.Level0)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "Hnp_UnInstall_API_002 start";
|
||||
|
||||
int ret;
|
||||
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir(HNP_BASE_PATH"/test", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
HnpPackWithCfg();
|
||||
HnpInstallPrivate();
|
||||
|
||||
{ // param uninstall path is invalid
|
||||
ret = NativeUnInstallHnp("10000", "sample", "1.1", "/test");
|
||||
EXPECT_NE(ret, 0);
|
||||
}
|
||||
|
||||
HnpDeleteFolder(HNP_BASE_PATH);
|
||||
HnpPackWithCfgDelete();
|
||||
|
||||
GTEST_LOG_(INFO) << "Hnp_UnInstall_API_002 end";
|
||||
}
|
||||
|
||||
}
|
@ -85,45 +85,38 @@ HWTEST(HnpPackTest, Hnp_Pack_001, TestSize.Level0)
|
||||
// clear resource before test
|
||||
remove("./hnp_out/sample.hnp");
|
||||
rmdir("hnp_out");
|
||||
remove("hnp_sample/hnp.json");
|
||||
rmdir("hnp_sample");
|
||||
remove("hnp.cfg");
|
||||
|
||||
|
||||
EXPECT_EQ(mkdir("hnp_sample", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir("hnp_out", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "pack";
|
||||
|
||||
char arg1[] = "hnp", arg2[] = "pack";
|
||||
|
||||
{ // param num not enough
|
||||
char* argv[] = {arg1, arg2};
|
||||
char *argv[] = {arg1, arg2};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_ARGV_NUM_INVALID);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_OPERATOR_ARGV_MISS);
|
||||
}
|
||||
{ // src dir path is invalid
|
||||
char arg3[] = "./hnp_sample2";
|
||||
char arg4[] = "./hnp_out";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4};
|
||||
char arg3[] = "-i", arg4[] = "./hnp_sample2", arg5[] = "-o", arg6[] = "./hnp_out";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_GET_REALPATH_FAILED);
|
||||
}
|
||||
{ // no name and version
|
||||
char arg3[] = "./hnp_sample";
|
||||
char arg4[] = "./hnp_out";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4};
|
||||
char arg3[] = "-i", arg4[] = "./hnp_sample", arg5[] = "-o", arg6[] = "./hnp_out";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_MISS_OPERATOR_PARAM);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_OPERATOR_ARGV_MISS);
|
||||
}
|
||||
{ // ok
|
||||
char arg3[] = "./hnp_sample";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "-name";
|
||||
char arg6[] = "sample";
|
||||
char arg7[] = "-v";
|
||||
char arg8[] = "1.1";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
|
||||
char arg3[] = "-i", arg4[] = "./hnp_sample", arg5[] = "-o", arg6[] = "./hnp_out";
|
||||
char arg7[] = "-n", arg8[] = "sample", arg9[] = "-v", arg10[] = "1.1";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), 0);
|
||||
@ -149,46 +142,29 @@ HWTEST(HnpPackTest, Hnp_Pack_002, TestSize.Level0)
|
||||
|
||||
EXPECT_EQ(mkdir("hnp_sample", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir("hnp_out", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
FILE *fp = fopen("hnp.cfg", "w");
|
||||
FILE *fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_NE(fp, nullptr);
|
||||
fclose(fp);
|
||||
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "pack";
|
||||
char arg3[] = "./hnp_sample";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "-cfg";
|
||||
|
||||
{ // cfg file path is invalid
|
||||
char arg6[] = "./hnp2.cfg";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
char arg1[] = "hnp", arg2[] = "pack";
|
||||
char arg3[] = "-i", arg4[] = "./hnp_sample", arg5[] = "-o", arg6[] = "./hnp_out";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_GET_REALPATH_FAILED);
|
||||
}
|
||||
{ // cfg file content is empty
|
||||
char arg6[] = "./hnp.cfg";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_READ_FILE_STREAM_FAILED);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_BASE_READ_FILE_STREAM_FAILED);
|
||||
}
|
||||
{ // cfg file not json formaat
|
||||
char cfg[] = "this is for test!";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_EQ(fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp), strlen(cfg) + 1);
|
||||
fclose(fp);
|
||||
|
||||
char arg6[] = "./hnp.cfg";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_PARSE_JSON_FAILED);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_BASE_PARSE_JSON_FAILED);
|
||||
}
|
||||
|
||||
EXPECT_EQ(remove("./hnp_sample/hnp.json"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_sample"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_out"), 0);
|
||||
EXPECT_EQ(remove("hnp.cfg"), 0);
|
||||
|
||||
GTEST_LOG_(INFO) << "Hnp_Pack_002 end";
|
||||
}
|
||||
@ -206,43 +182,39 @@ HWTEST(HnpPackTest, Hnp_Pack_003, TestSize.Level0)
|
||||
|
||||
EXPECT_EQ(mkdir("hnp_sample", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir("hnp_out", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
FILE *fp = fopen("hnp.cfg", "w");
|
||||
FILE *fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_NE(fp, nullptr);
|
||||
fclose(fp);
|
||||
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "pack";
|
||||
char arg3[] = "./hnp_sample";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "-cfg";
|
||||
char arg6[] = "./hnp.cfg";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg1[] = "hnp", arg2[] = "pack";
|
||||
char arg3[] = "-i", arg4[] = "./hnp_sample", arg5[] = "-o", arg6[] = "./hnp_out";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
{ // cfg file content has not type item
|
||||
char cfg[] = "{\"typ\":\"hnp-config\",\"name\":\"sample\",\"version\":\"1.1\",\"install\":"
|
||||
"{\"links\":[{\"source\":\"bin/out\",\"target\":\"out\"},{\"source\":\"bin/out2\","
|
||||
"\"target\":\"out2\"}]}}";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_EQ(fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp), strlen(cfg) + 1);
|
||||
fclose(fp);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND);
|
||||
}
|
||||
{ // type item value is not expected
|
||||
char cfg[] = "{\"type\":\"hnpconfig\",\"name\":\"sample\",\"version\":\"1.1\",\"install\":"
|
||||
"{\"links\":[{\"source\":\"bin/out\",\"target\":\"out\"},{\"source\":\"bin/out2\","
|
||||
"\"target\":\"out2\"}]}}";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_EQ(fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp), strlen(cfg) + 1);
|
||||
fclose(fp);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND);
|
||||
}
|
||||
|
||||
EXPECT_EQ(remove("./hnp_sample/hnp.json"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_sample"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_out"), 0);
|
||||
EXPECT_EQ(remove("hnp.cfg"), 0);
|
||||
|
||||
GTEST_LOG_(INFO) << "Hnp_Pack_003 end";
|
||||
}
|
||||
@ -260,53 +232,49 @@ HWTEST(HnpPackTest, Hnp_Pack_004, TestSize.Level0)
|
||||
|
||||
EXPECT_EQ(mkdir("hnp_sample", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir("hnp_out", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
FILE *fp = fopen("hnp.cfg", "w");
|
||||
FILE *fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_NE(fp, nullptr);
|
||||
fclose(fp);
|
||||
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "pack";
|
||||
char arg3[] = "./hnp_sample";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "-cfg";
|
||||
char arg6[] = "./hnp.cfg";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg1[] = "hnp", arg2[] = "pack";
|
||||
char arg3[] = "-i", arg4[] = "./hnp_sample", arg5[] = "-o", arg6[] = "./hnp_out";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
{ // cfg file content has not name item
|
||||
char cfg[] = "{\"type\":\"hnp-config\",\"version\":\"1.1\",\"install\":"
|
||||
"{\"links\":[{\"source\":\"bin/out\",\"target\":\"out\"},{\"source\":\"bin/out2\","
|
||||
"\"target\":\"out2\"}]}}";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_EQ(fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp), strlen(cfg) + 1);
|
||||
fclose(fp);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND);
|
||||
}
|
||||
{ // cfg file content has not version item
|
||||
char cfg[] = "{\"type\":\"hnp-config\",\"name\":\"sample\",\"install\":"
|
||||
"{\"links\":[{\"source\":\"bin/out\",\"target\":\"out\"},{\"source\":\"bin/out2\","
|
||||
"\"target\":\"out2\"}]}}";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_EQ(fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp), strlen(cfg) + 1);
|
||||
fclose(fp);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND);
|
||||
}
|
||||
{ // cfg file content has not install item
|
||||
char cfg[] = "{\"type\":\"hnp-config\",\"name\":\"sample\",\"version\":\"1.1\",\"uninstall\":"
|
||||
"{\"links\":[{\"source\":\"bin/out\",\"target\":\"out\"},{\"source\":\"bin/out2\","
|
||||
"\"target\":\"out2\"}]}}";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_EQ(fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp), strlen(cfg) + 1);
|
||||
fclose(fp);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND);
|
||||
}
|
||||
|
||||
EXPECT_EQ(remove("./hnp_sample/hnp.json"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_sample"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_out"), 0);
|
||||
EXPECT_EQ(remove("hnp.cfg"), 0);
|
||||
|
||||
GTEST_LOG_(INFO) << "Hnp_Pack_004 end";
|
||||
}
|
||||
@ -324,44 +292,46 @@ HWTEST(HnpPackTest, Hnp_Pack_005, TestSize.Level0)
|
||||
|
||||
EXPECT_EQ(mkdir("hnp_sample", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir("hnp_out", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
FILE *fp = fopen("hnp.cfg", "w");
|
||||
FILE *fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_NE(fp, nullptr);
|
||||
fclose(fp);
|
||||
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "pack";
|
||||
char arg3[] = "./hnp_sample";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "-cfg";
|
||||
char arg6[] = "./hnp.cfg";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg1[] = "hnp", arg2[] = "pack";
|
||||
char arg3[] = "-i", arg4[] = "./hnp_sample", arg5[] = "-o", arg6[] = "./hnp_out";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
{ // link arry item has not source item
|
||||
char cfg[] = "{\"type\":\"hnp-config\",\"name\":\"sample\",\"version\":\"1.1\",\"install\":"
|
||||
"{\"links\":[{\"src\":\"bin/out\",\"target\":\"out\"},{\"source\":\"bin/out2\","
|
||||
"\"target\":\"out2\"}]}}";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_EQ(fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp), strlen(cfg) + 1);
|
||||
fclose(fp);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_PARSE_ITEM_NO_FOUND);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_BASE_PARSE_ITEM_NO_FOUND);
|
||||
}
|
||||
{ // ok, link arry item has not target item
|
||||
char cfg[] = "{\"type\":\"hnp-config\",\"name\":\"sample\",\"version\":\"1.1\",\"install\":"
|
||||
"{\"links\":[{\"source\":\"bin/out\",\"tar\":\"out\"},{\"source\":\"bin/out2\","
|
||||
"{\"links\":[{\"source\":\"a.out\",\"tar\":\"out\"},{\"source\":\"a.out\","
|
||||
"\"target\":\"out2\"}]}}";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_EQ(fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp), strlen(cfg) + 1);
|
||||
fclose(fp);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_GET_REALPATH_FAILED);
|
||||
|
||||
FILE *fp = fopen("./hnp_sample/a.out", "w");
|
||||
EXPECT_NE(fp, nullptr);
|
||||
fclose(fp);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), 0);
|
||||
EXPECT_EQ(remove("./hnp_sample/a.out"), 0);
|
||||
EXPECT_EQ(remove("./hnp_out/sample.hnp"), 0);
|
||||
}
|
||||
|
||||
EXPECT_EQ(remove("./hnp_sample/hnp.json"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_sample"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_out"), 0);
|
||||
EXPECT_EQ(remove("hnp.cfg"), 0);
|
||||
|
||||
GTEST_LOG_(INFO) << "Hnp_Pack_005 end";
|
||||
}
|
||||
@ -379,22 +349,18 @@ HWTEST(HnpPackTest, Hnp_Pack_006, TestSize.Level0)
|
||||
|
||||
EXPECT_EQ(mkdir("hnp_sample", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
EXPECT_EQ(mkdir("hnp_out", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0);
|
||||
FILE *fp = fopen("hnp.cfg", "w");
|
||||
FILE *fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_NE(fp, nullptr);
|
||||
fclose(fp);
|
||||
|
||||
char arg1[] = "hnp";
|
||||
char arg2[] = "pack";
|
||||
char arg3[] = "./hnp_sample";
|
||||
char arg4[] = "./hnp_out";
|
||||
char arg5[] = "-cfg";
|
||||
char arg6[] = "./hnp.cfg";
|
||||
char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
char arg1[] = "hnp", arg2[] = "pack";
|
||||
char arg3[] = "-i", arg4[] = "./hnp_sample", arg5[] = "-o", arg6[] = "./hnp_out";
|
||||
char *argv[] = {arg1, arg2, arg3, arg4, arg5, arg6};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
|
||||
{ // ok. no links item in install item
|
||||
char cfg[] = "{\"type\":\"hnp-config\",\"name\":\"sample\",\"version\":\"1.1\",\"install\":{}}";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_EQ(fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp), strlen(cfg) + 1);
|
||||
fclose(fp);
|
||||
|
||||
@ -404,7 +370,7 @@ HWTEST(HnpPackTest, Hnp_Pack_006, TestSize.Level0)
|
||||
{ // ok. no array in links item
|
||||
char cfg[] = "{\"type\":\"hnp-config\",\"name\":\"sample\",\"version\":\"1.1\",\"install\":"
|
||||
"{\"links\":[]}}";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_EQ(fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp), strlen(cfg) + 1);
|
||||
fclose(fp);
|
||||
|
||||
@ -413,19 +379,25 @@ HWTEST(HnpPackTest, Hnp_Pack_006, TestSize.Level0)
|
||||
}
|
||||
{ // ok. 2 links
|
||||
char cfg[] = "{\"type\":\"hnp-config\",\"name\":\"sample\",\"version\":\"1.1\",\"install\":"
|
||||
"{\"links\":[{\"source\":\"bin/out\",\"target\":\"out\"},{\"source\":\"bin/out2\","
|
||||
"{\"links\":[{\"source\":\"a.out\",\"target\":\"out\"},{\"source\":\"a.out\","
|
||||
"\"target\":\"out2\"}]}}";
|
||||
fp = fopen("./hnp.cfg", "w");
|
||||
fp = fopen("./hnp_sample/hnp.json", "w");
|
||||
EXPECT_EQ(fwrite(cfg, sizeof(char), strlen(cfg) + 1, fp), strlen(cfg) + 1);
|
||||
fclose(fp);
|
||||
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), HNP_ERRNO_PACK_GET_REALPATH_FAILED);
|
||||
|
||||
FILE *fp = fopen("./hnp_sample/a.out", "w");
|
||||
EXPECT_NE(fp, nullptr);
|
||||
fclose(fp);
|
||||
EXPECT_EQ(HnpCmdPack(argc, argv), 0);
|
||||
EXPECT_EQ(remove("./hnp_sample/a.out"), 0);
|
||||
EXPECT_EQ(remove("./hnp_out/sample.hnp"), 0);
|
||||
}
|
||||
|
||||
EXPECT_EQ(remove("./hnp_sample/hnp.json"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_sample"), 0);
|
||||
EXPECT_EQ(rmdir("hnp_out"), 0);
|
||||
EXPECT_EQ(remove("hnp.cfg"), 0);
|
||||
|
||||
GTEST_LOG_(INFO) << "Hnp_Pack_006 end";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user