MCPcopy Create free account
hub / github.com/KasperskyLab/hrtng / save

Function save

src/deinline.cpp:1096–1162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1094 return basePath;
1095 }
1096 void save()
1097 {
1098 qstring basePath = getBasePath(true);
1099 basePath.append('/');
1100 uint32 cnt = 0;
1101 for (auto inl : *this) {
1102 if (inl->bLib || inl->bTmp)
1103 continue; //do not overwrite inline files was loaded from lib
1104 qstring path = inl->name;
1105 size_t pdir = 0;
1106 for (size_t p = 0; p < path.size(); p++) {
1107 //sanitize_file_name(&path[pprev], p - pprev);
1108 switch (path[p]) {
1109 case ':':
1110 case '?':
1111 case '*':
1112 case '<':
1113 case '>':
1114 case '|':
1115 case '\'':
1116 case '\"':
1117 case ' ':
1118 path[p] = '_';
1119 break;
1120 case '.':
1121 {
1122 if (pdir == p) {
1123 path.remove(pdir, 1); //avoid duplicates "..."
1124 p--;
1125 break;
1126 }
1127 // make dir in form 'Name'
1128 //path[pdir] = qtoupper(path[pdir]);
1129 //for (auto i = pdir + 1; i < p; i++)
1130 // path[i] = qtolower(path[i]);
1131 qstring dir = basePath + path.substr(0, p);
1132#ifdef _WIN32
1133 if(qmkdir(dir.c_str(), 0) < 0)
1134#else
1135 if(qmkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0)
1136#endif
1137 Log(llError, "Error %d on mkdir(\"%s\")\n", get_qerrno(), basePath.c_str());
1138 path[p] = '/';
1139 pdir = p + 1;
1140 break;
1141 }
1142 }
1143 }
1144 qstring fullpath(basePath); fullpath.append(path);
1145 fullpath = unique_nameD(fullpath.c_str(), "-", [](const qstring& n) {qstring p(n); p.append(".inl"); return !qfileexist(p.c_str()); });
1146 fullpath.append(".inl");
1147 FILE *fd = qfopen(fullpath.c_str(), "wb");
1148 if(!fd) {
1149 Log(llError, "Could not open '%s' for writing!\n", fullpath.c_str());
1150 } else {
1151 bytevec_t buf;
1152 inl->serialize(buf);
1153 qfwrite(fd, &buf[0], buf.size());

Callers

nothing calls this directly

Calls 7

getBasePathFunction · 0.85
LogFunction · 0.85
unique_nameDFunction · 0.85
appendMethod · 0.80
sizeMethod · 0.80
removeMethod · 0.80
serializeMethod · 0.80

Tested by

no test coverage detected