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.

jan.nijtmans 2017-08-23 18:53 UTC branch-2.3
Commit adacbfbcfb77d0e8c6b20be68f0c5115411f94536f9a75fccf1c5c30575a9e50
2 files changed +28 -16 +28 -16
+28 -16
--- src/file.c
+++ src/file.c
@@ -632,32 +632,23 @@
632632
char *zName;
633633
634634
nName = strlen(zFilename);
635635
zName = mprintf("%s", zFilename);
636636
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 ){
648643
if( file_mkdir(zName, forceFlag) && file_wd_isdir(zName)!=1 ){
649
- if (errorReturn <= 0) {
644
+ if( errorReturn <= 0 ){
650645
fossil_fatal_recursive("unable to create directory %s", zName);
651646
}
652647
rc = errorReturn;
653
- break;
654648
}
655
-#if defined(_WIN32) || defined(__CYGWIN__)
656649
}
657
-#endif
658
- zName[i] = '/';
659650
}
660651
}
661652
free(zName);
662653
return rc;
663654
}
@@ -1413,10 +1404,14 @@
14131404
#if defined(_WIN32)
14141405
wchar_t zTmpPath[MAX_PATH];
14151406
14161407
if( GetTempPathW(MAX_PATH, zTmpPath) ){
14171408
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;
14181413
}
14191414
14201415
azDirs[1] = fossil_getenv("TEMP");
14211416
azDirs[2] = fossil_getenv("TMP");
14221417
#else
@@ -1452,10 +1447,27 @@
14521447
#else
14531448
fossil_path_free((char *)azDirs[0]);
14541449
#endif
14551450
}
14561451
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
+
14571469
14581470
/*
14591471
** Return true if a file named zName exists and has identical content
14601472
** to the blob pContent. If zName does not exist or if the content is
14611473
** different in any way, then return false.
14621474
--- 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 @@
632632
char *zName;
633633
634634
nName = strlen(zFilename);
635635
zName = mprintf("%s", zFilename);
636636
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 ){
648643
if( file_mkdir(zName, forceFlag) && file_wd_isdir(zName)!=1 ){
649
- if (errorReturn <= 0) {
644
+ if( errorReturn <= 0 ){
650645
fossil_fatal_recursive("unable to create directory %s", zName);
651646
}
652647
rc = errorReturn;
653
- break;
654648
}
655
-#if defined(_WIN32) || defined(__CYGWIN__)
656649
}
657
-#endif
658
- zName[i] = '/';
659650
}
660651
}
661652
free(zName);
662653
return rc;
663654
}
@@ -1413,10 +1404,14 @@
14131404
#if defined(_WIN32)
14141405
wchar_t zTmpPath[MAX_PATH];
14151406
14161407
if( GetTempPathW(MAX_PATH, zTmpPath) ){
14171408
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;
14181413
}
14191414
14201415
azDirs[1] = fossil_getenv("TEMP");
14211416
azDirs[2] = fossil_getenv("TMP");
14221417
#else
@@ -1452,10 +1447,27 @@
14521447
#else
14531448
fossil_path_free((char *)azDirs[0]);
14541449
#endif
14551450
}
14561451
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
+
14571469
14581470
/*
14591471
** Return true if a file named zName exists and has identical content
14601472
** to the blob pContent. If zName does not exist or if the content is
14611473
** different in any way, then return false.
14621474
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button