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

Function check_dest_dir

tools/comdb2ar/deserialise.cpp:324–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322}
323
324static bool check_dest_dir(const std::string& dir)
325// REALLY REALLY REALLY important safety check - without this
326// we may end up deleting *.dta from /bb/data!
327// Only allow 3rd level subdirectories or greater (e.g. /bb/data/mydb)
328{
329 size_t pos = 0;
330 int levels = 0;
331
332 /* skip the check if the destination directory is empty */
333 if (empty_dir(dir))
334 return false;
335
336 while(pos < dir.length()) {
337 size_t match = dir.find('/', pos);
338
339 if(match == std::string::npos) {
340 // No more matches
341 match = dir.length();
342 }
343
344 if(match > pos) {
345 levels++;
346 }
347
348 pos = match + 1;
349 }
350
351 if(levels < 3) return false;
352
353 return true;
354}
355
356#define write_size (1000*1024)
357

Callers 1

deserialise_databaseFunction · 0.85

Calls 1

empty_dirFunction · 0.85

Tested by

no test coverage detected