mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
82 lines
2.5 KiB
C++
82 lines
2.5 KiB
C++
/*
|
|
* Copyright (c) 2023 Fancy Code.
|
|
* 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 "HuntingUpgradeTestTool.h"
|
|
#include "ILog.h"
|
|
#include "LinuxApi.h"
|
|
#include "UpgradeTool.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
void HuntingUpgradeTestTool::Init(void)
|
|
{
|
|
}
|
|
void HuntingUpgradeTestTool::UnInit(void)
|
|
{
|
|
if (access(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test", F_OK) == 0) {
|
|
fx_system("rm -rf " SD_CARD_MOUNT_PATH);
|
|
}
|
|
}
|
|
void HuntingUpgradeTestTool::CreateUpgradeFile(void)
|
|
{
|
|
CheckDirectory(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test");
|
|
fx_system("touch " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test");
|
|
UpgradeTool::GetInstance()->PackFile(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test",
|
|
SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH,
|
|
"6.4.5.6",
|
|
"hunting",
|
|
"dgiot",
|
|
"app");
|
|
}
|
|
bool HuntingUpgradeTestTool::CheckDirectory(const char *filepath)
|
|
{
|
|
LogInfo("CheckDirectory:%s\n", filepath);
|
|
char *path = nullptr;
|
|
char *sep = nullptr;
|
|
struct stat st = {0};
|
|
|
|
path = strdup(filepath);
|
|
if (!path) {
|
|
LogError("strdup\n");
|
|
return false;
|
|
}
|
|
|
|
for (sep = strchr(path, '/'); sep != NULL; sep = strchr(sep + 1, '/')) {
|
|
*sep = '\0';
|
|
if (strlen(path) == 0) {
|
|
*sep = '/';
|
|
continue;
|
|
}
|
|
if (stat(path, &st) == -1) {
|
|
if (errno == ENOENT) {
|
|
if (mkdir(path, 0755) == -1) {
|
|
LogError("mkdir path failed:%s\n", path);
|
|
free(path);
|
|
return false;
|
|
}
|
|
}
|
|
else {
|
|
LogError("stat\n");
|
|
free(path);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
*sep = '/';
|
|
}
|
|
free(path);
|
|
return true;
|
|
} |