int remove_volume_data(const char *pathIn) {
if (pathIn == nullptr) {
return -1;
}
if(strlen(pathIn) >= sizeof(gPathBuf)) {
return -2;
}
if(strlen(pathIn) == 0) {
return -3;
}
if(pathIn[0] == '/') {
return -4;
}
const char *root_path = "/root/d/car/c4/data";
snprintf(gPathBuf,sizeof(gPathBuf),"%s",pathIn);
trimLastSlash(gPathBuf);
snprintf(gParentPathBuf,sizeof(gParentPathBuf),"%s",gPathBuf);
char *dir = strtok(gPathBuf, "/");
if (dir != nullptr) {
removeDirsSkipDir(root_path, dir);
while (dir != nullptr) {
const size_t n1 = strlen(gParentPathBuf);
const size_t n2 = strlen(dir);
if(n1 + n2 + 1 < sizeof(gParentPathBuf)) {
strcat(gParentPathBuf,"/");
strcat(gParentPathBuf,dir);
}
else {
return -4;
}
//gParentPathBuf exist?
if(0 != access(gParentPathBuf,F_OK)) {
return 0;
}
//is directory?
struct stat file_info{};
int result = stat(gParentPathBuf, &file_info);
if(result != 0) {
return 0;
}
if((S_IFDIR & file_info.st_mode) == 0) {
return -5;
}
dir = strtok(nullptr, "/");
if (dir != nullptr) {
removeDirsSkipDir(gParentPathBuf, dir);
}
}
}
return 0;
}
remove_volume_data
最新推荐文章于 2024-07-10 16:47:58 发布