Fossil SCM
(cherry-pick): Remove a redundant directory separator character from the temporary filenames generated on windows. (cherry-pick): Change the file_mkfolder() implementation to assume that the folder already exists and only go about creating it and its path if it does not previously exit.
Commit
adacbfbcfb77d0e8c6b20be68f0c5115411f94536f9a75fccf1c5c30575a9e50
Parent
dbda6e2a5dcd94d…
2 files changed
+28
-16
+28
-16
+28
-16
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -632,32 +632,23 @@ | ||
| 632 | 632 | char *zName; |
| 633 | 633 | |
| 634 | 634 | nName = strlen(zFilename); |
| 635 | 635 | zName = mprintf("%s", zFilename); |
| 636 | 636 | nName = file_simplify_name(zName, nName, 0); |
| 637 | - for(i=1; i<nName; i++){ | |
| 638 | - if( zName[i]=='/' ){ | |
| 639 | - zName[i] = 0; | |
| 640 | -#if defined(_WIN32) || defined(__CYGWIN__) | |
| 641 | - /* | |
| 642 | - ** On Windows, local path looks like: C:/develop/project/file.txt | |
| 643 | - ** The if stops us from trying to create a directory of a drive letter | |
| 644 | - ** C: in this example. | |
| 645 | - */ | |
| 646 | - if( !(i==2 && zName[1]==':') ){ | |
| 647 | -#endif | |
| 637 | + while( nName>0 && zName[nName-1]!='/' ){ nName--; } | |
| 638 | + if( nName ){ | |
| 639 | + zName[nName-1] = 0; | |
| 640 | + if( file_wd_isdir(zName)!=1 ){ | |
| 641 | + rc = file_mkfolder(zName, forceFlag, errorReturn); | |
| 642 | + if( rc==0 ){ | |
| 648 | 643 | if( file_mkdir(zName, forceFlag) && file_wd_isdir(zName)!=1 ){ |
| 649 | - if (errorReturn <= 0) { | |
| 644 | + if( errorReturn <= 0 ){ | |
| 650 | 645 | fossil_fatal_recursive("unable to create directory %s", zName); |
| 651 | 646 | } |
| 652 | 647 | rc = errorReturn; |
| 653 | - break; | |
| 654 | 648 | } |
| 655 | -#if defined(_WIN32) || defined(__CYGWIN__) | |
| 656 | 649 | } |
| 657 | -#endif | |
| 658 | - zName[i] = '/'; | |
| 659 | 650 | } |
| 660 | 651 | } |
| 661 | 652 | free(zName); |
| 662 | 653 | return rc; |
| 663 | 654 | } |
| @@ -1413,10 +1404,14 @@ | ||
| 1413 | 1404 | #if defined(_WIN32) |
| 1414 | 1405 | wchar_t zTmpPath[MAX_PATH]; |
| 1415 | 1406 | |
| 1416 | 1407 | if( GetTempPathW(MAX_PATH, zTmpPath) ){ |
| 1417 | 1408 | azDirs[0] = fossil_path_to_utf8(zTmpPath); |
| 1409 | + /* Removing trailing \ from the temp path */ | |
| 1410 | + z = (char*)azDirs[0]; | |
| 1411 | + i = (int)strlen(z)-1; | |
| 1412 | + if( i>0 && z[i]=='\\' ) z[i] = 0; | |
| 1418 | 1413 | } |
| 1419 | 1414 | |
| 1420 | 1415 | azDirs[1] = fossil_getenv("TEMP"); |
| 1421 | 1416 | azDirs[2] = fossil_getenv("TMP"); |
| 1422 | 1417 | #else |
| @@ -1452,10 +1447,27 @@ | ||
| 1452 | 1447 | #else |
| 1453 | 1448 | fossil_path_free((char *)azDirs[0]); |
| 1454 | 1449 | #endif |
| 1455 | 1450 | } |
| 1456 | 1451 | |
| 1452 | + | |
| 1453 | +/* | |
| 1454 | +** COMMAND: test-tempname | |
| 1455 | +** Usage: fossil test-name BASENAME ... | |
| 1456 | +** | |
| 1457 | +** Generate temporary filenames derived from BASENAME | |
| 1458 | +*/ | |
| 1459 | +void file_test_tempname(void){ | |
| 1460 | + int i; | |
| 1461 | + Blob x = BLOB_INITIALIZER; | |
| 1462 | + for(i=2; i<g.argc; i++){ | |
| 1463 | + file_tempname(&x, g.argv[i]); | |
| 1464 | + fossil_print("%s\n", blob_str(&x)); | |
| 1465 | + blob_reset(&x); | |
| 1466 | + } | |
| 1467 | +} | |
| 1468 | + | |
| 1457 | 1469 | |
| 1458 | 1470 | /* |
| 1459 | 1471 | ** Return true if a file named zName exists and has identical content |
| 1460 | 1472 | ** to the blob pContent. If zName does not exist or if the content is |
| 1461 | 1473 | ** different in any way, then return false. |
| 1462 | 1474 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -632,32 +632,23 @@ | |
| 632 | char *zName; |
| 633 | |
| 634 | nName = strlen(zFilename); |
| 635 | zName = mprintf("%s", zFilename); |
| 636 | nName = file_simplify_name(zName, nName, 0); |
| 637 | for(i=1; i<nName; i++){ |
| 638 | if( zName[i]=='/' ){ |
| 639 | zName[i] = 0; |
| 640 | #if defined(_WIN32) || defined(__CYGWIN__) |
| 641 | /* |
| 642 | ** On Windows, local path looks like: C:/develop/project/file.txt |
| 643 | ** The if stops us from trying to create a directory of a drive letter |
| 644 | ** C: in this example. |
| 645 | */ |
| 646 | if( !(i==2 && zName[1]==':') ){ |
| 647 | #endif |
| 648 | if( file_mkdir(zName, forceFlag) && file_wd_isdir(zName)!=1 ){ |
| 649 | if (errorReturn <= 0) { |
| 650 | fossil_fatal_recursive("unable to create directory %s", zName); |
| 651 | } |
| 652 | rc = errorReturn; |
| 653 | break; |
| 654 | } |
| 655 | #if defined(_WIN32) || defined(__CYGWIN__) |
| 656 | } |
| 657 | #endif |
| 658 | zName[i] = '/'; |
| 659 | } |
| 660 | } |
| 661 | free(zName); |
| 662 | return rc; |
| 663 | } |
| @@ -1413,10 +1404,14 @@ | |
| 1413 | #if defined(_WIN32) |
| 1414 | wchar_t zTmpPath[MAX_PATH]; |
| 1415 | |
| 1416 | if( GetTempPathW(MAX_PATH, zTmpPath) ){ |
| 1417 | azDirs[0] = fossil_path_to_utf8(zTmpPath); |
| 1418 | } |
| 1419 | |
| 1420 | azDirs[1] = fossil_getenv("TEMP"); |
| 1421 | azDirs[2] = fossil_getenv("TMP"); |
| 1422 | #else |
| @@ -1452,10 +1447,27 @@ | |
| 1452 | #else |
| 1453 | fossil_path_free((char *)azDirs[0]); |
| 1454 | #endif |
| 1455 | } |
| 1456 | |
| 1457 | |
| 1458 | /* |
| 1459 | ** Return true if a file named zName exists and has identical content |
| 1460 | ** to the blob pContent. If zName does not exist or if the content is |
| 1461 | ** different in any way, then return false. |
| 1462 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -632,32 +632,23 @@ | |
| 632 | char *zName; |
| 633 | |
| 634 | nName = strlen(zFilename); |
| 635 | zName = mprintf("%s", zFilename); |
| 636 | nName = file_simplify_name(zName, nName, 0); |
| 637 | while( nName>0 && zName[nName-1]!='/' ){ nName--; } |
| 638 | if( nName ){ |
| 639 | zName[nName-1] = 0; |
| 640 | if( file_wd_isdir(zName)!=1 ){ |
| 641 | rc = file_mkfolder(zName, forceFlag, errorReturn); |
| 642 | if( rc==0 ){ |
| 643 | if( file_mkdir(zName, forceFlag) && file_wd_isdir(zName)!=1 ){ |
| 644 | if( errorReturn <= 0 ){ |
| 645 | fossil_fatal_recursive("unable to create directory %s", zName); |
| 646 | } |
| 647 | rc = errorReturn; |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | free(zName); |
| 653 | return rc; |
| 654 | } |
| @@ -1413,10 +1404,14 @@ | |
| 1404 | #if defined(_WIN32) |
| 1405 | wchar_t zTmpPath[MAX_PATH]; |
| 1406 | |
| 1407 | if( GetTempPathW(MAX_PATH, zTmpPath) ){ |
| 1408 | azDirs[0] = fossil_path_to_utf8(zTmpPath); |
| 1409 | /* Removing trailing \ from the temp path */ |
| 1410 | z = (char*)azDirs[0]; |
| 1411 | i = (int)strlen(z)-1; |
| 1412 | if( i>0 && z[i]=='\\' ) z[i] = 0; |
| 1413 | } |
| 1414 | |
| 1415 | azDirs[1] = fossil_getenv("TEMP"); |
| 1416 | azDirs[2] = fossil_getenv("TMP"); |
| 1417 | #else |
| @@ -1452,10 +1447,27 @@ | |
| 1447 | #else |
| 1448 | fossil_path_free((char *)azDirs[0]); |
| 1449 | #endif |
| 1450 | } |
| 1451 | |
| 1452 | |
| 1453 | /* |
| 1454 | ** COMMAND: test-tempname |
| 1455 | ** Usage: fossil test-name BASENAME ... |
| 1456 | ** |
| 1457 | ** Generate temporary filenames derived from BASENAME |
| 1458 | */ |
| 1459 | void file_test_tempname(void){ |
| 1460 | int i; |
| 1461 | Blob x = BLOB_INITIALIZER; |
| 1462 | for(i=2; i<g.argc; i++){ |
| 1463 | file_tempname(&x, g.argv[i]); |
| 1464 | fossil_print("%s\n", blob_str(&x)); |
| 1465 | blob_reset(&x); |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | |
| 1470 | /* |
| 1471 | ** Return true if a file named zName exists and has identical content |
| 1472 | ** to the blob pContent. If zName does not exist or if the content is |
| 1473 | ** different in any way, then return false. |
| 1474 |
+28
-16
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -632,32 +632,23 @@ | ||
| 632 | 632 | char *zName; |
| 633 | 633 | |
| 634 | 634 | nName = strlen(zFilename); |
| 635 | 635 | zName = mprintf("%s", zFilename); |
| 636 | 636 | nName = file_simplify_name(zName, nName, 0); |
| 637 | - for(i=1; i<nName; i++){ | |
| 638 | - if( zName[i]=='/' ){ | |
| 639 | - zName[i] = 0; | |
| 640 | -#if defined(_WIN32) || defined(__CYGWIN__) | |
| 641 | - /* | |
| 642 | - ** On Windows, local path looks like: C:/develop/project/file.txt | |
| 643 | - ** The if stops us from trying to create a directory of a drive letter | |
| 644 | - ** C: in this example. | |
| 645 | - */ | |
| 646 | - if( !(i==2 && zName[1]==':') ){ | |
| 647 | -#endif | |
| 637 | + while( nName>0 && zName[nName-1]!='/' ){ nName--; } | |
| 638 | + if( nName ){ | |
| 639 | + zName[nName-1] = 0; | |
| 640 | + if( file_wd_isdir(zName)!=1 ){ | |
| 641 | + rc = file_mkfolder(zName, forceFlag, errorReturn); | |
| 642 | + if( rc==0 ){ | |
| 648 | 643 | if( file_mkdir(zName, forceFlag) && file_wd_isdir(zName)!=1 ){ |
| 649 | - if (errorReturn <= 0) { | |
| 644 | + if( errorReturn <= 0 ){ | |
| 650 | 645 | fossil_fatal_recursive("unable to create directory %s", zName); |
| 651 | 646 | } |
| 652 | 647 | rc = errorReturn; |
| 653 | - break; | |
| 654 | 648 | } |
| 655 | -#if defined(_WIN32) || defined(__CYGWIN__) | |
| 656 | 649 | } |
| 657 | -#endif | |
| 658 | - zName[i] = '/'; | |
| 659 | 650 | } |
| 660 | 651 | } |
| 661 | 652 | free(zName); |
| 662 | 653 | return rc; |
| 663 | 654 | } |
| @@ -1413,10 +1404,14 @@ | ||
| 1413 | 1404 | #if defined(_WIN32) |
| 1414 | 1405 | wchar_t zTmpPath[MAX_PATH]; |
| 1415 | 1406 | |
| 1416 | 1407 | if( GetTempPathW(MAX_PATH, zTmpPath) ){ |
| 1417 | 1408 | azDirs[0] = fossil_path_to_utf8(zTmpPath); |
| 1409 | + /* Removing trailing \ from the temp path */ | |
| 1410 | + z = (char*)azDirs[0]; | |
| 1411 | + i = (int)strlen(z)-1; | |
| 1412 | + if( i>0 && z[i]=='\\' ) z[i] = 0; | |
| 1418 | 1413 | } |
| 1419 | 1414 | |
| 1420 | 1415 | azDirs[1] = fossil_getenv("TEMP"); |
| 1421 | 1416 | azDirs[2] = fossil_getenv("TMP"); |
| 1422 | 1417 | #else |
| @@ -1452,10 +1447,27 @@ | ||
| 1452 | 1447 | #else |
| 1453 | 1448 | fossil_path_free((char *)azDirs[0]); |
| 1454 | 1449 | #endif |
| 1455 | 1450 | } |
| 1456 | 1451 | |
| 1452 | + | |
| 1453 | +/* | |
| 1454 | +** COMMAND: test-tempname | |
| 1455 | +** Usage: fossil test-name BASENAME ... | |
| 1456 | +** | |
| 1457 | +** Generate temporary filenames derived from BASENAME | |
| 1458 | +*/ | |
| 1459 | +void file_test_tempname(void){ | |
| 1460 | + int i; | |
| 1461 | + Blob x = BLOB_INITIALIZER; | |
| 1462 | + for(i=2; i<g.argc; i++){ | |
| 1463 | + file_tempname(&x, g.argv[i]); | |
| 1464 | + fossil_print("%s\n", blob_str(&x)); | |
| 1465 | + blob_reset(&x); | |
| 1466 | + } | |
| 1467 | +} | |
| 1468 | + | |
| 1457 | 1469 | |
| 1458 | 1470 | /* |
| 1459 | 1471 | ** Return true if a file named zName exists and has identical content |
| 1460 | 1472 | ** to the blob pContent. If zName does not exist or if the content is |
| 1461 | 1473 | ** different in any way, then return false. |
| 1462 | 1474 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -632,32 +632,23 @@ | |
| 632 | char *zName; |
| 633 | |
| 634 | nName = strlen(zFilename); |
| 635 | zName = mprintf("%s", zFilename); |
| 636 | nName = file_simplify_name(zName, nName, 0); |
| 637 | for(i=1; i<nName; i++){ |
| 638 | if( zName[i]=='/' ){ |
| 639 | zName[i] = 0; |
| 640 | #if defined(_WIN32) || defined(__CYGWIN__) |
| 641 | /* |
| 642 | ** On Windows, local path looks like: C:/develop/project/file.txt |
| 643 | ** The if stops us from trying to create a directory of a drive letter |
| 644 | ** C: in this example. |
| 645 | */ |
| 646 | if( !(i==2 && zName[1]==':') ){ |
| 647 | #endif |
| 648 | if( file_mkdir(zName, forceFlag) && file_wd_isdir(zName)!=1 ){ |
| 649 | if (errorReturn <= 0) { |
| 650 | fossil_fatal_recursive("unable to create directory %s", zName); |
| 651 | } |
| 652 | rc = errorReturn; |
| 653 | break; |
| 654 | } |
| 655 | #if defined(_WIN32) || defined(__CYGWIN__) |
| 656 | } |
| 657 | #endif |
| 658 | zName[i] = '/'; |
| 659 | } |
| 660 | } |
| 661 | free(zName); |
| 662 | return rc; |
| 663 | } |
| @@ -1413,10 +1404,14 @@ | |
| 1413 | #if defined(_WIN32) |
| 1414 | wchar_t zTmpPath[MAX_PATH]; |
| 1415 | |
| 1416 | if( GetTempPathW(MAX_PATH, zTmpPath) ){ |
| 1417 | azDirs[0] = fossil_path_to_utf8(zTmpPath); |
| 1418 | } |
| 1419 | |
| 1420 | azDirs[1] = fossil_getenv("TEMP"); |
| 1421 | azDirs[2] = fossil_getenv("TMP"); |
| 1422 | #else |
| @@ -1452,10 +1447,27 @@ | |
| 1452 | #else |
| 1453 | fossil_path_free((char *)azDirs[0]); |
| 1454 | #endif |
| 1455 | } |
| 1456 | |
| 1457 | |
| 1458 | /* |
| 1459 | ** Return true if a file named zName exists and has identical content |
| 1460 | ** to the blob pContent. If zName does not exist or if the content is |
| 1461 | ** different in any way, then return false. |
| 1462 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -632,32 +632,23 @@ | |
| 632 | char *zName; |
| 633 | |
| 634 | nName = strlen(zFilename); |
| 635 | zName = mprintf("%s", zFilename); |
| 636 | nName = file_simplify_name(zName, nName, 0); |
| 637 | while( nName>0 && zName[nName-1]!='/' ){ nName--; } |
| 638 | if( nName ){ |
| 639 | zName[nName-1] = 0; |
| 640 | if( file_wd_isdir(zName)!=1 ){ |
| 641 | rc = file_mkfolder(zName, forceFlag, errorReturn); |
| 642 | if( rc==0 ){ |
| 643 | if( file_mkdir(zName, forceFlag) && file_wd_isdir(zName)!=1 ){ |
| 644 | if( errorReturn <= 0 ){ |
| 645 | fossil_fatal_recursive("unable to create directory %s", zName); |
| 646 | } |
| 647 | rc = errorReturn; |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | free(zName); |
| 653 | return rc; |
| 654 | } |
| @@ -1413,10 +1404,14 @@ | |
| 1404 | #if defined(_WIN32) |
| 1405 | wchar_t zTmpPath[MAX_PATH]; |
| 1406 | |
| 1407 | if( GetTempPathW(MAX_PATH, zTmpPath) ){ |
| 1408 | azDirs[0] = fossil_path_to_utf8(zTmpPath); |
| 1409 | /* Removing trailing \ from the temp path */ |
| 1410 | z = (char*)azDirs[0]; |
| 1411 | i = (int)strlen(z)-1; |
| 1412 | if( i>0 && z[i]=='\\' ) z[i] = 0; |
| 1413 | } |
| 1414 | |
| 1415 | azDirs[1] = fossil_getenv("TEMP"); |
| 1416 | azDirs[2] = fossil_getenv("TMP"); |
| 1417 | #else |
| @@ -1452,10 +1447,27 @@ | |
| 1447 | #else |
| 1448 | fossil_path_free((char *)azDirs[0]); |
| 1449 | #endif |
| 1450 | } |
| 1451 | |
| 1452 | |
| 1453 | /* |
| 1454 | ** COMMAND: test-tempname |
| 1455 | ** Usage: fossil test-name BASENAME ... |
| 1456 | ** |
| 1457 | ** Generate temporary filenames derived from BASENAME |
| 1458 | */ |
| 1459 | void file_test_tempname(void){ |
| 1460 | int i; |
| 1461 | Blob x = BLOB_INITIALIZER; |
| 1462 | for(i=2; i<g.argc; i++){ |
| 1463 | file_tempname(&x, g.argv[i]); |
| 1464 | fossil_print("%s\n", blob_str(&x)); |
| 1465 | blob_reset(&x); |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | |
| 1470 | /* |
| 1471 | ** Return true if a file named zName exists and has identical content |
| 1472 | ** to the blob pContent. If zName does not exist or if the content is |
| 1473 | ** different in any way, then return false. |
| 1474 |