mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-12 05:40:03 +08:00
Match-id-b08926bead0de9d389a4ccbc630730c47db50300
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: ascend-docker-cli工具实用函数模块
|
||||
*/
|
||||
#include "utils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
@@ -14,7 +17,7 @@
|
||||
#include "securec.h"
|
||||
#include "logging.h"
|
||||
|
||||
int IsStrEqual(const char *s1, const char *s2)
|
||||
static int IsStrEqual(const char *s1, const char *s2)
|
||||
{
|
||||
return (!strcmp(s1, s2));
|
||||
}
|
||||
@@ -107,28 +110,11 @@ int MkDir(const char *dir, int mode)
|
||||
return mkdir(dir, mode);
|
||||
}
|
||||
|
||||
int MakeParentDir(const char *path, mode_t mode)
|
||||
int VerifyPathInfo(const struct PathInfo* pathInfo)
|
||||
{
|
||||
if (*path == '\0' || *path == '.') {
|
||||
return 0;
|
||||
}
|
||||
if (CheckDirExists(path) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char parentPath[BUF_SIZE] = {0};
|
||||
GetParentPathStr(path, parentPath, BUF_SIZE);
|
||||
if (strlen(parentPath) > 0 && MakeParentDir(parentPath, mode) < 0) {
|
||||
if (pathInfo == NULL || pathInfo->dst == NULL || pathInfo->src == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct stat s;
|
||||
int ret = stat(path, &s);
|
||||
if (ret < 0) {
|
||||
logError("error: failed to stat path: %s\n", path);
|
||||
return (MkDir(path, mode));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -165,6 +151,31 @@ int GetParentPathStr(const char *path, char *parent, size_t bufSize)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MakeParentDir(const char *path, mode_t mode)
|
||||
{
|
||||
if (*path == '\0' || *path == '.') {
|
||||
return 0;
|
||||
}
|
||||
if (CheckDirExists(path) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char parentPath[BUF_SIZE] = {0};
|
||||
GetParentPathStr(path, parentPath, BUF_SIZE);
|
||||
if (strlen(parentPath) > 0 && MakeParentDir(parentPath, mode) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct stat s;
|
||||
int ret = stat(path, &s);
|
||||
if (ret < 0) {
|
||||
logError("error: failed to stat path: %s\n", path);
|
||||
return (MkDir(path, mode));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CreateFile(const char *path, mode_t mode)
|
||||
{
|
||||
char resolvedPath[PATH_MAX] = {0};
|
||||
@@ -182,14 +193,6 @@ int CreateFile(const char *path, mode_t mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VerfifyPathInfo(const struct PathInfo* pathInfo)
|
||||
{
|
||||
if (pathInfo == NULL || pathInfo->dst == NULL || pathInfo->src == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Mount(const char *src, const char *dst)
|
||||
{
|
||||
static const unsigned long remountFlags = MS_BIND | MS_REMOUNT | MS_RDONLY | MS_NOSUID;
|
||||
|
Reference in New Issue
Block a user