MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / make_dirs

Function make_dirs

tools/comdb2ar/util.cpp:216–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216void make_dirs(const std::string& dirname)
217// Ensure that a directory given by absolute path dirname exists
218{
219 struct stat st;
220 static int extentsize = -1;
221 static std::map<std::string, bool> files;
222 bool isdir = false;
223
224 if (stat(dirname.c_str(), &st) == 0 && ((st.st_mode & S_IFMT) == S_IFDIR))
225 isdir = true;
226
227 if (extentsize == -1) {
228 FILE *f;
229 int sz;
230
231 extentsize = 0;
232 f = fopen("/bb/data/comdb2_xfs_extent_size", "r");
233 if (f != NULL) {
234 char line[512];
235 while (fgets(line, sizeof(line), f)) {
236 char *s = strchr(line, '\n');
237 if (*s) *s = 0;
238 s = line;
239 while (*s && isspace(*s)) s++;
240 if (*s == '#') continue;
241 sz = atoi(s);
242 if (sz > 0) extentsize = sz;
243 }
244 }
245 }
246 if (extentsize > 0 && isdir && !files[dirname]) {
247 std::stringstream xfscmd;
248 xfscmd << "/usr/sbin/xfs_io -c 'extsize " << extentsize << "' " << dirname;
249
250 // set default extent size for database directories
251 std::clog << ">>>>>> " << xfscmd.str() << std::endl;
252 int rc = std::system(xfscmd.str().c_str());
253 if (rc == -1)
254 std::cerr << "system() returns rc = " << rc << std::endl;
255 files[dirname] = true;
256 }
257
258 if(stat(dirname.c_str(), &st) == 0) {
259 if((st.st_mode & S_IFMT) == S_IFDIR) {
260 // This already exists as a directory (or a symlink to a directory)
261 // so leave it alone. This check exists because "mkdir -p /bb/bin"
262 // would fail on sundev5 due to /bb/bin being a symlink to
263 // /bb/sys/opbin.
264 return;
265 }
266 }
267
268
269 // Yes, this is lazy. Sorry.
270 std::string cmd("mkdir -p " + dirname);
271
272 int rc = std::system(cmd.c_str());
273 if(rc) {

Callers 3

deserialise_databaseFunction · 0.85
output_fileFunction · 0.85
clear_log_folderFunction · 0.85

Calls 2

ErrorClass · 0.85
statClass · 0.70

Tested by

no test coverage detected