Fossil SCM
Added fix for issue seen with merge; would fail due to file_copy() issue where files of renamed directories would not have the new directory created beforehand. Also added fix for issue seen after large merge; 'changes' command would fail due to WriteConsoleW() returning with error ERROR_NOT_ENOUGH_MEMORY; fix seems hacky but works.
Commit
3f31dc65977d999833b85fbe485f11890fb84efe
Parent
16642f9c183f704…
2 files changed
+21
+7
-2
+21
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -349,10 +349,26 @@ | ||
| 349 | 349 | if( z[0]=='/' ) zTail = &z[1]; |
| 350 | 350 | z++; |
| 351 | 351 | } |
| 352 | 352 | return zTail; |
| 353 | 353 | } |
| 354 | + | |
| 355 | +/* | |
| 356 | +** Return the head of a file pathname. The head is everything leading up | |
| 357 | +** to the last component of the path. For example, the head of "/a/b/c.d" is "/a/b". | |
| 358 | +** The trailing slash is removed. | |
| 359 | +*/ | |
| 360 | +void file_head(const char *z, char *h){ | |
| 361 | + int i = file_tail(z)-z; | |
| 362 | + if( !i ){ | |
| 363 | + memmove(h, z, strlen(z)); | |
| 364 | + return; | |
| 365 | + } | |
| 366 | + if( '/' == z[i-1] ) i--; | |
| 367 | + memmove(h, z, i); | |
| 368 | + h[i] = '\0'; | |
| 369 | +} | |
| 354 | 370 | |
| 355 | 371 | /* |
| 356 | 372 | ** Copy the content of a file from one place to another. |
| 357 | 373 | */ |
| 358 | 374 | void file_copy(const char *zFrom, const char *zTo){ |
| @@ -359,10 +375,15 @@ | ||
| 359 | 375 | FILE *in, *out; |
| 360 | 376 | int got; |
| 361 | 377 | char zBuf[8192]; |
| 362 | 378 | in = fossil_fopen(zFrom, "rb"); |
| 363 | 379 | if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom); |
| 380 | + file_head(zTo, zBuf); | |
| 381 | + if( !file_isdir(zBuf) ) | |
| 382 | + { | |
| 383 | + file_mkdir(zBuf, 0); | |
| 384 | + } | |
| 364 | 385 | out = fossil_fopen(zTo, "wb"); |
| 365 | 386 | if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo); |
| 366 | 387 | while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){ |
| 367 | 388 | fwrite(zBuf, 1, got, out); |
| 368 | 389 | } |
| 369 | 390 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -349,10 +349,26 @@ | |
| 349 | if( z[0]=='/' ) zTail = &z[1]; |
| 350 | z++; |
| 351 | } |
| 352 | return zTail; |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | ** Copy the content of a file from one place to another. |
| 357 | */ |
| 358 | void file_copy(const char *zFrom, const char *zTo){ |
| @@ -359,10 +375,15 @@ | |
| 359 | FILE *in, *out; |
| 360 | int got; |
| 361 | char zBuf[8192]; |
| 362 | in = fossil_fopen(zFrom, "rb"); |
| 363 | if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom); |
| 364 | out = fossil_fopen(zTo, "wb"); |
| 365 | if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo); |
| 366 | while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){ |
| 367 | fwrite(zBuf, 1, got, out); |
| 368 | } |
| 369 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -349,10 +349,26 @@ | |
| 349 | if( z[0]=='/' ) zTail = &z[1]; |
| 350 | z++; |
| 351 | } |
| 352 | return zTail; |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | ** Return the head of a file pathname. The head is everything leading up |
| 357 | ** to the last component of the path. For example, the head of "/a/b/c.d" is "/a/b". |
| 358 | ** The trailing slash is removed. |
| 359 | */ |
| 360 | void file_head(const char *z, char *h){ |
| 361 | int i = file_tail(z)-z; |
| 362 | if( !i ){ |
| 363 | memmove(h, z, strlen(z)); |
| 364 | return; |
| 365 | } |
| 366 | if( '/' == z[i-1] ) i--; |
| 367 | memmove(h, z, i); |
| 368 | h[i] = '\0'; |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | ** Copy the content of a file from one place to another. |
| 373 | */ |
| 374 | void file_copy(const char *zFrom, const char *zTo){ |
| @@ -359,10 +375,15 @@ | |
| 375 | FILE *in, *out; |
| 376 | int got; |
| 377 | char zBuf[8192]; |
| 378 | in = fossil_fopen(zFrom, "rb"); |
| 379 | if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom); |
| 380 | file_head(zTo, zBuf); |
| 381 | if( !file_isdir(zBuf) ) |
| 382 | { |
| 383 | file_mkdir(zBuf, 0); |
| 384 | } |
| 385 | out = fossil_fopen(zTo, "wb"); |
| 386 | if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo); |
| 387 | while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){ |
| 388 | fwrite(zBuf, 1, got, out); |
| 389 | } |
| 390 |
+7
-2
| --- src/utf8.c | ||
| +++ src/utf8.c | ||
| @@ -212,12 +212,17 @@ | ||
| 212 | 212 | if( nChar==0 ){ |
| 213 | 213 | free(zUnicode); |
| 214 | 214 | return 0; |
| 215 | 215 | } |
| 216 | 216 | zUnicode[nChar] = '\0'; |
| 217 | - WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode, nChar, | |
| 218 | - &dummy, 0); | |
| 217 | + if( 0==WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), | |
| 218 | + zUnicode, nChar, &dummy, 0) ){ | |
| 219 | + /** print UTF8 to console if all else fails */ | |
| 220 | + WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), | |
| 221 | + zUtf8, nChar, &dummy, 0); | |
| 222 | + } | |
| 223 | + | |
| 219 | 224 | return nChar; |
| 220 | 225 | #else |
| 221 | 226 | return -1; /* No-op on unix */ |
| 222 | 227 | #endif |
| 223 | 228 | } |
| 224 | 229 |
| --- src/utf8.c | |
| +++ src/utf8.c | |
| @@ -212,12 +212,17 @@ | |
| 212 | if( nChar==0 ){ |
| 213 | free(zUnicode); |
| 214 | return 0; |
| 215 | } |
| 216 | zUnicode[nChar] = '\0'; |
| 217 | WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode, nChar, |
| 218 | &dummy, 0); |
| 219 | return nChar; |
| 220 | #else |
| 221 | return -1; /* No-op on unix */ |
| 222 | #endif |
| 223 | } |
| 224 |
| --- src/utf8.c | |
| +++ src/utf8.c | |
| @@ -212,12 +212,17 @@ | |
| 212 | if( nChar==0 ){ |
| 213 | free(zUnicode); |
| 214 | return 0; |
| 215 | } |
| 216 | zUnicode[nChar] = '\0'; |
| 217 | if( 0==WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), |
| 218 | zUnicode, nChar, &dummy, 0) ){ |
| 219 | /** print UTF8 to console if all else fails */ |
| 220 | WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), |
| 221 | zUtf8, nChar, &dummy, 0); |
| 222 | } |
| 223 | |
| 224 | return nChar; |
| 225 | #else |
| 226 | return -1; /* No-op on unix */ |
| 227 | #endif |
| 228 | } |
| 229 |