| 322 | } |
| 323 | |
| 324 | static 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 |
no test coverage detected