| 322 | |
| 323 | #ifndef MMKV_APPLE |
| 324 | extern bool mkPath(const MMKVPath_t &str) { |
| 325 | char *path = strdup(str.c_str()); |
| 326 | |
| 327 | struct stat sb = {}; |
| 328 | bool done = false; |
| 329 | char *slash = path; |
| 330 | |
| 331 | while (!done) { |
| 332 | slash += strspn(slash, "/"); |
| 333 | slash += strcspn(slash, "/"); |
| 334 | |
| 335 | done = (*slash == '\0'); |
| 336 | *slash = '\0'; |
| 337 | |
| 338 | if (stat(path, &sb) != 0) { |
| 339 | if (errno != ENOENT || mkdir(path, 0777) != 0) { |
| 340 | MMKVWarning("%s : %s", path, strerror(errno)); |
| 341 | // there's report that some Android devices might not have access permission on parent dir |
| 342 | if (done) { |
| 343 | free(path); |
| 344 | return false; |
| 345 | } |
| 346 | goto LContinue; |
| 347 | } |
| 348 | } else if (!S_ISDIR(sb.st_mode)) { |
| 349 | MMKVWarning("%s: %s", path, strerror(ENOTDIR)); |
| 350 | free(path); |
| 351 | return false; |
| 352 | } |
| 353 | LContinue: |
| 354 | *slash = '/'; |
| 355 | } |
| 356 | free(path); |
| 357 | |
| 358 | return true; |
| 359 | } |
| 360 | #else |
| 361 | // avoid using so-called privacy API |
| 362 | extern bool mkPath(const MMKVPath_t &str) { |
no test coverage detected