Fossil SCM
Tidy up and fix implementation of empty-dirs setting.
Commit
529237a3c113d9946cc5d668304c07faa941d54e
Parent
eb93d6ae0ea50cf…
1 file changed
+32
-9
+32
-9
| --- src/update.c | ||
| +++ src/update.c | ||
| @@ -468,23 +468,46 @@ | ||
| 468 | 468 | void ensure_empty_dirs_created() |
| 469 | 469 | { |
| 470 | 470 | /* Make empty directories? */ |
| 471 | 471 | char *zEmptyDirs = db_get_versionable_setting("empty-dirs", 0); |
| 472 | 472 | if( zEmptyDirs!=0 ){ |
| 473 | - Blob dirsList, line; | |
| 473 | + Blob dirsList; | |
| 474 | 474 | blob_zero(&dirsList); |
| 475 | 475 | blob_init(&dirsList, zEmptyDirs, strlen(zEmptyDirs)); |
| 476 | - while( blob_line(&dirsList, &line) ){ | |
| 477 | - if( blob_buffer(&line)[0]=='#' ) continue; | |
| 478 | - Blob dirName; | |
| 479 | - int l = blob_token(&line, &dirName); | |
| 480 | - if(l > 0) { | |
| 481 | - /* Try and create the directory */ | |
| 482 | - if( file_mkdir(blob_str(&dirName), 0)!=0 ) { | |
| 483 | - fossil_warning("couldn't create empty-dir %s", blob_str(&dirName)); | |
| 476 | + /* Replace commas by spaces */ | |
| 477 | + char *bc = blob_str(&dirsList); | |
| 478 | + while( (*bc)!='\0' ){ | |
| 479 | + if( (*bc)==',' ) { *bc = ' '; } | |
| 480 | + ++bc; | |
| 481 | + } | |
| 482 | + /* Make directories */ | |
| 483 | + Blob dirName; | |
| 484 | + blob_zero(&dirName); | |
| 485 | + while( blob_token(&dirsList, &dirName) ){ | |
| 486 | + const char *zDir = blob_str(&dirName); | |
| 487 | + /* Make full pathname of the directory */ | |
| 488 | + Blob path; | |
| 489 | + blob_zero(&path); | |
| 490 | + blob_appendf(&path, "%s/%s", g.zLocalRoot, zDir); | |
| 491 | + const char *zPath = blob_str(&path); | |
| 492 | + /* Handle various cases of existence of the directory */ | |
| 493 | + switch( file_isdir(zPath) ){ | |
| 494 | + case 0: { /* doesn't exist */ | |
| 495 | + if( file_mkdir(zPath, 0)!=0 ) { | |
| 496 | + fossil_warning("couldn't create directory %s as required by empty-dirs setting", zDir); | |
| 497 | + } | |
| 498 | + break; | |
| 499 | + } | |
| 500 | + case 1: { /* exists, and is a directory */ | |
| 501 | + /* do nothing - required directory exists already */ | |
| 502 | + break; | |
| 503 | + } | |
| 504 | + case 2: { /* exists, but isn't a directory */ | |
| 505 | + fossil_warning("file %s found, but a directory is required by empty-dirs setting", zDir); | |
| 484 | 506 | } |
| 485 | 507 | } |
| 508 | + blob_reset(&path); | |
| 486 | 509 | } |
| 487 | 510 | } |
| 488 | 511 | } |
| 489 | 512 | |
| 490 | 513 | |
| 491 | 514 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -468,23 +468,46 @@ | |
| 468 | void ensure_empty_dirs_created() |
| 469 | { |
| 470 | /* Make empty directories? */ |
| 471 | char *zEmptyDirs = db_get_versionable_setting("empty-dirs", 0); |
| 472 | if( zEmptyDirs!=0 ){ |
| 473 | Blob dirsList, line; |
| 474 | blob_zero(&dirsList); |
| 475 | blob_init(&dirsList, zEmptyDirs, strlen(zEmptyDirs)); |
| 476 | while( blob_line(&dirsList, &line) ){ |
| 477 | if( blob_buffer(&line)[0]=='#' ) continue; |
| 478 | Blob dirName; |
| 479 | int l = blob_token(&line, &dirName); |
| 480 | if(l > 0) { |
| 481 | /* Try and create the directory */ |
| 482 | if( file_mkdir(blob_str(&dirName), 0)!=0 ) { |
| 483 | fossil_warning("couldn't create empty-dir %s", blob_str(&dirName)); |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | |
| 491 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -468,23 +468,46 @@ | |
| 468 | void ensure_empty_dirs_created() |
| 469 | { |
| 470 | /* Make empty directories? */ |
| 471 | char *zEmptyDirs = db_get_versionable_setting("empty-dirs", 0); |
| 472 | if( zEmptyDirs!=0 ){ |
| 473 | Blob dirsList; |
| 474 | blob_zero(&dirsList); |
| 475 | blob_init(&dirsList, zEmptyDirs, strlen(zEmptyDirs)); |
| 476 | /* Replace commas by spaces */ |
| 477 | char *bc = blob_str(&dirsList); |
| 478 | while( (*bc)!='\0' ){ |
| 479 | if( (*bc)==',' ) { *bc = ' '; } |
| 480 | ++bc; |
| 481 | } |
| 482 | /* Make directories */ |
| 483 | Blob dirName; |
| 484 | blob_zero(&dirName); |
| 485 | while( blob_token(&dirsList, &dirName) ){ |
| 486 | const char *zDir = blob_str(&dirName); |
| 487 | /* Make full pathname of the directory */ |
| 488 | Blob path; |
| 489 | blob_zero(&path); |
| 490 | blob_appendf(&path, "%s/%s", g.zLocalRoot, zDir); |
| 491 | const char *zPath = blob_str(&path); |
| 492 | /* Handle various cases of existence of the directory */ |
| 493 | switch( file_isdir(zPath) ){ |
| 494 | case 0: { /* doesn't exist */ |
| 495 | if( file_mkdir(zPath, 0)!=0 ) { |
| 496 | fossil_warning("couldn't create directory %s as required by empty-dirs setting", zDir); |
| 497 | } |
| 498 | break; |
| 499 | } |
| 500 | case 1: { /* exists, and is a directory */ |
| 501 | /* do nothing - required directory exists already */ |
| 502 | break; |
| 503 | } |
| 504 | case 2: { /* exists, but isn't a directory */ |
| 505 | fossil_warning("file %s found, but a directory is required by empty-dirs setting", zDir); |
| 506 | } |
| 507 | } |
| 508 | blob_reset(&path); |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | |
| 514 |