| 511 | | |
| 512 | | /// |
| 513 | | /// @brief Creates the directory and all its parent directories. |
| 514 | | /// |
| 515 | | /// If the directory already exists it does nothing. |
| 516 | | /// |
| 517 | | /// @param path The directory to create. |
| 518 | | /// |
| 519 | | void |
| 520 | | makeDirWithParents (const gchar *path) |
| 521 | | { |
| 522 | | // Get the list of directories to create. |
| 523 | | GList *dirs = NULL; |
| 524 | | gchar *dirName = g_strdup (path); |
| 525 | | while ( !g_file_test (dirName, G_FILE_TEST_EXISTS) ) |
| 526 | | { |
| 527 | | dirs = g_list_prepend (dirs, dirName); |
| 528 | | dirName = g_path_get_dirname (dirName); |
| 529 | | } |
| 530 | | |
| 531 | | // Now create all of them. |
| 532 | | GList *dir = g_list_first (dirs); |
| 533 | | while ( NULL != dir ) |
| 534 | | { |
| 535 | | if ( -1 == g_mkdir ((gchar *)dir->data, 0700) ) |
| 536 | | { |
| 537 | | g_warning ("Couldn't make directory '%s'\n", (gchar *)dir->data); |
| 538 | | } |
| 539 | | g_free (dir->data); |
| 540 | | dir = g_list_next (dir); |
| 541 | | } |
| 542 | | g_list_free (dirs); |
| 543 | | } |