mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-12-04 13:28:42 +00:00
commit
4c10531647
@ -38,7 +38,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef MAX_FILE_PATH_LEN
|
||||
#define MAX_FILE_PATH_LEN PATH_MAX
|
||||
#define MAX_FILE_PATH_LEN 4096
|
||||
#endif
|
||||
|
||||
#define HNP_VERSION_LEN 32
|
||||
@ -266,20 +266,20 @@ int HnpFileCountGet(const char *path, int *count);
|
||||
|
||||
#ifdef HNP_CLI
|
||||
#define HNP_LOGI(args, ...) \
|
||||
HnpLogPrintf(HNP_LOG_INFO, "HNP", args, ##__VA_ARGS__)
|
||||
HnpLogPrintf(HNP_LOG_INFO, "HNP", "[%{public}s:%{public}d]" args, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
|
||||
#else
|
||||
#define HNP_LOGI(args, ...) \
|
||||
HILOG_INFO(LOG_CORE, "[%{public}s:%{public}d]" args, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__); \
|
||||
HnpLogPrintf(HNP_LOG_INFO, "HNP", args, ##__VA_ARGS__)
|
||||
HnpLogPrintf(HNP_LOG_INFO, "HNP", "[%{public}s:%{public}d]" args, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifdef HNP_CLI
|
||||
#define HNP_LOGE(args, ...) \
|
||||
HnpLogPrintf(HNP_LOG_ERROR, "HNP", args, ##__VA_ARGS__)
|
||||
HnpLogPrintf(HNP_LOG_ERROR, "HNP", "[%{public}s:%{public}d]" args, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
|
||||
#else
|
||||
#define HNP_LOGE(args, ...) \
|
||||
HILOG_ERROR(LOG_CORE, "[%{public}s:%{public}d]" args, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__); \
|
||||
HnpLogPrintf(HNP_LOG_ERROR, "HNP", args, ##__VA_ARGS__)
|
||||
HnpLogPrintf(HNP_LOG_ERROR, "HNP", "[%{public}s:%{public}d]" args, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -118,13 +118,18 @@ int HnpWriteInfoToFile(const char* filePath, char *buff, int len)
|
||||
|
||||
int GetRealPath(char *srcPath, char *realPath)
|
||||
{
|
||||
char dstTmpPath[PATH_MAX];
|
||||
char dstTmpPath[MAX_FILE_PATH_LEN];
|
||||
|
||||
if (srcPath == NULL || realPath == NULL) {
|
||||
return HNP_ERRNO_PARAM_INVALID;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
DWORD ret = GetFullPathName(srcPath, PATH_MAX, dstTmpPath, NULL);
|
||||
// 使用wchar_t支持处理字符串长度超过260的路径字符串
|
||||
wchar_t wideSrcPath[MAX_FILE_PATH_LEN] = {0};
|
||||
wchar_t wideDstPathExt[MAX_FILE_PATH_LEN] = {0};
|
||||
MultiByteToWideChar(CP_ACP, 0, srcPath, -1, wideSrcPath, MAX_FILE_PATH_LEN);
|
||||
DWORD ret = GetFullPathNameW(wideSrcPath, MAX_FILE_PATH_LEN, wideDstPathExt, NULL);
|
||||
WideCharToMultiByte(CP_ACP, 0, wideDstPathExt, -1, dstTmpPath, MAX_FILE_PATH_LEN, NULL, NULL);
|
||||
#else
|
||||
char *ret = realpath(srcPath, dstTmpPath);
|
||||
#endif
|
||||
|
@ -54,6 +54,20 @@ static void TransPath(const char *input, char *output)
|
||||
output[len] = '\0';
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// 转换char路径字符串为wchar_t宽字符串,支持路径字符串长度超过260
|
||||
static bool TransWidePath(const char *inPath, wchar_t *outPath)
|
||||
{
|
||||
wchar_t tmpPath[MAX_FILE_PATH_LEN] = {0};
|
||||
MultiByteToWideChar(CP_ACP, 0, inPath, -1, tmpPath, MAX_FILE_PATH_LEN);
|
||||
if (swprintf_s(outPath, MAX_FILE_PATH_LEN, L"\\\\?\\%ls", tmpPath) < 0) {
|
||||
HNP_LOGE("swprintf unsuccess.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// 向zip压缩包中添加文件
|
||||
static int ZipAddFile(const char* file, int offset, zipFile zf)
|
||||
{
|
||||
@ -62,14 +76,26 @@ static int ZipAddFile(const char* file, int offset, zipFile zf)
|
||||
char transPath[MAX_FILE_PATH_LEN];
|
||||
int len;
|
||||
FILE *f;
|
||||
struct stat buffer = {0};
|
||||
zip_fileinfo fileInfo = {0};
|
||||
|
||||
if (stat(file, &buffer) != 0) {
|
||||
#ifdef _WIN32
|
||||
struct _stat buffer = {0};
|
||||
// 使用wchar_t支持处理字符串长度超过260的路径字符串
|
||||
wchar_t wideFullPath[MAX_FILE_PATH_LEN] = {0};
|
||||
if (!TransWidePath(file, wideFullPath)) {
|
||||
return HNP_ERRNO_BASE_STAT_FAILED;
|
||||
}
|
||||
if (_wstat(wideFullPath, &buffer) != 0) {
|
||||
HNP_LOGE("get filefile[%{public}s] stat fail.", file);
|
||||
return HNP_ERRNO_BASE_STAT_FAILED;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
buffer.st_mode |= S_IXOTH;
|
||||
#else
|
||||
struct stat buffer = {0};
|
||||
if (stat(file, &buffer) != 0) {
|
||||
HNP_LOGE("get filefile[%{public}s] stat fail.", file);
|
||||
return HNP_ERRNO_BASE_STAT_FAILED;
|
||||
}
|
||||
#endif
|
||||
fileInfo.external_fa = (buffer.st_mode & 0xFFFF) << ZIP_EXTERNAL_FA_OFFSET;
|
||||
TransPath(file, transPath);
|
||||
@ -79,7 +105,11 @@ static int ZipAddFile(const char* file, int offset, zipFile zf)
|
||||
HNP_LOGE("open new file[%{public}s] in zip unsuccess ", file);
|
||||
return HNP_ERRNO_BASE_CREATE_ZIP_FAILED;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
f = _wfopen(wideFullPath, L"rb");
|
||||
#else
|
||||
f = fopen(file, "rb");
|
||||
#endif
|
||||
if (f == NULL) {
|
||||
HNP_LOGE("open file[%{public}s] unsuccess ", file);
|
||||
return HNP_ERRNO_BASE_FILE_OPEN_FAILED;
|
||||
@ -97,9 +127,15 @@ static int ZipAddFile(const char* file, int offset, zipFile zf)
|
||||
static int IsDirPath(struct dirent *entry, char *fullPath, int *isDir)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
DWORD fileAttr = GetFileAttributes(fullPath);
|
||||
// 使用wchar_t支持处理字符串长度超过260的路径字符串
|
||||
wchar_t wideFullPath[MAX_FILE_PATH_LEN] = {0};
|
||||
if (!TransWidePath(fullPath, wideFullPath)) {
|
||||
return HNP_ERRNO_GET_FILE_ATTR_FAILED;
|
||||
}
|
||||
DWORD fileAttr = GetFileAttributesW(wideFullPath);
|
||||
if (fileAttr == INVALID_FILE_ATTRIBUTES) {
|
||||
HNP_LOGE("get file[%{public}s] attr unsuccess.", fullPath);
|
||||
DWORD err = GetLastError();
|
||||
HNP_LOGE("get file[%{public}s] attr unsuccess, errno[%{public}lu].", fullPath, err);
|
||||
return HNP_ERRNO_GET_FILE_ATTR_FAILED;
|
||||
}
|
||||
*isDir = (int)(fileAttr & FILE_ATTRIBUTE_DIRECTORY);
|
||||
@ -149,7 +185,7 @@ static int ZipAddDir(const char *sourcePath, int offset, zipFile zf)
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
||||
continue;
|
||||
}
|
||||
if (sprintf_s(fullPath, MAX_FILE_PATH_LEN, "%s%c%s", sourcePath, DIR_SPLIT_SYMBOL, entry->d_name) < 0) {
|
||||
if (sprintf_s(fullPath, MAX_FILE_PATH_LEN, "%s%s", sourcePath, entry->d_name) < 0) {
|
||||
HNP_LOGE("sprintf unsuccess.");
|
||||
closedir(dir);
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
|
@ -40,7 +40,6 @@ Native包管理功能模块提供了对Native软件的打包、安装、卸载
|
||||
注:
|
||||
1. 用户在配置文件中指定了软链接关系则安装时根据用户配置进行软链接设置。如果用户不使用配置文件或者配置文件中没有设置软链接,则安装时默认将软件包内bin目录下的可执行二进制都进行软链接。
|
||||
2. 为了保证bin目录里面的二进制执行过程中能自动加载lib下的库文件,则需要在编译二进制时增加以下rpath链接选项,指明库文件和二进制的相对位置关系(${ORIGIN}为当前二进制位置)。
|
||||
3. native软件包文件目录中不支持中文目录。
|
||||
|
||||
```
|
||||
ldflags = [
|
||||
@ -48,6 +47,8 @@ Native包管理功能模块提供了对Native软件的打包、安装、卸载
|
||||
"-Wl,--disable-new-dtags",
|
||||
]
|
||||
```
|
||||
3. native软件包文件目录中不支持中文目录。
|
||||
4. 打包文件路径长度不超过4096个字符。
|
||||
|
||||
样例:
|
||||
```
|
||||
|
@ -75,7 +75,7 @@ static int PackHnp(const char *hnpSrcPath, const char *hnpDstPath, HnpPackInfo *
|
||||
hnpSrcPath, hnpCfg->name, hnpCfg->version, hnpDstPath);
|
||||
|
||||
/* 拼接hnp文件名 */
|
||||
ret = sprintf_s(hnp_file_path, MAX_FILE_PATH_LEN, "%s/%s.hnp", hnpDstPath, hnpCfg->name);
|
||||
ret = sprintf_s(hnp_file_path, MAX_FILE_PATH_LEN, "%s%c%s.hnp", hnpDstPath, DIR_SPLIT_SYMBOL, hnpCfg->name);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf unsuccess.");
|
||||
return HNP_ERRNO_PACK_GET_HNP_PATH_FAILED;
|
||||
@ -157,7 +157,7 @@ static int ParsePackArgs(HnpPackArgv *packArgv, HnpPackInfo *packInfo)
|
||||
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);
|
||||
int ret = sprintf_s(cfgPath, MAX_FILE_PATH_LEN, "%s%c"HNP_CFG_FILE_NAME, packInfo->source, DIR_SPLIT_SYMBOL);
|
||||
if (ret < 0) {
|
||||
HNP_LOGE("sprintf unsuccess.");
|
||||
return HNP_ERRNO_BASE_SPRINTF_FAILED;
|
||||
|
Loading…
Reference in New Issue
Block a user