Fossil SCM
Fix the file_fullexename() function (used by the "info" and "test-which" commands) so that it works correctly on Windows.
Commit
d8c32ebdffcef75b0a9e5831da1c18f92021b09d8072594134a8857dd0690068
Parent
e39854ae510570a…
1 file changed
+44
+44
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -1298,10 +1298,54 @@ | ||
| 1298 | 1298 | ** This routine only works on unix. On Windows, simply return |
| 1299 | 1299 | ** a copy of the input. |
| 1300 | 1300 | */ |
| 1301 | 1301 | char *file_fullexename(const char *zCmd){ |
| 1302 | 1302 | #ifdef _WIN32 |
| 1303 | + char *zPath; | |
| 1304 | + char *z = 0; | |
| 1305 | + const char *zExe = ""; | |
| 1306 | + if( sqlite3_strlike("%.exe",zCmd,0)!=0 ) zExe = ".exe"; | |
| 1307 | + if( file_is_absolute_path(zCmd) ){ | |
| 1308 | + return mprintf("%s%s", zCmd, zExe); | |
| 1309 | + } | |
| 1310 | + if( strchr(zCmd,'\\')!=0 && strchr(zCmd,'/')!=0 ){ | |
| 1311 | + int i; | |
| 1312 | + Blob out = BLOB_INITIALIZER; | |
| 1313 | + file_canonical_name(zCmd, &out, 0); | |
| 1314 | + blob_append(&out, zExe, -1); | |
| 1315 | + z = fossil_strdup(blob_str(&out)); | |
| 1316 | + blob_reset(&out); | |
| 1317 | + for(i=0; z[i]; i++){ if( z[i]=='/' ) z[i] = '\\'; } | |
| 1318 | + return z; | |
| 1319 | + } | |
| 1320 | + z = mprintf(".\\%s%s", zCmd, zExe); | |
| 1321 | + if( file_isfile(z, ExtFILE) ){ | |
| 1322 | + int i; | |
| 1323 | + Blob out = BLOB_INITIALIZER; | |
| 1324 | + file_canonical_name(zCmd, &out, 0); | |
| 1325 | + blob_append(&out, zExe, -1); | |
| 1326 | + z = fossil_strdup(blob_str(&out)); | |
| 1327 | + blob_reset(&out); | |
| 1328 | + for(i=0; z[i]; i++){ if( z[i]=='/' ) z[i] = '\\'; } | |
| 1329 | + return z; | |
| 1330 | + } | |
| 1331 | + fossil_free(z); | |
| 1332 | + zPath = fossil_getenv("PATH"); | |
| 1333 | + while( zPath && zPath[0] ){ | |
| 1334 | + int n; | |
| 1335 | + char *zColon; | |
| 1336 | + zColon = strchr(zPath, ';'); | |
| 1337 | + n = zColon ? (int)(zColon-zPath) : (int)strlen(zPath); | |
| 1338 | + while( n>0 && zPath[n-1]=='\\' ){ n--; } | |
| 1339 | + z = mprintf("%.*s\\%s%s", n, zPath, zCmd, zExe); | |
| 1340 | + if( file_isfile(z, ExtFILE) ){ | |
| 1341 | + return z; | |
| 1342 | + } | |
| 1343 | + fossil_free(z); | |
| 1344 | + if( zColon==0 ) break; | |
| 1345 | + zPath = zColon+1; | |
| 1346 | + } | |
| 1303 | 1347 | return fossil_strdup(zCmd); |
| 1304 | 1348 | #else |
| 1305 | 1349 | char *zPath; |
| 1306 | 1350 | char *z; |
| 1307 | 1351 | if( zCmd[0]=='/' ){ |
| 1308 | 1352 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -1298,10 +1298,54 @@ | |
| 1298 | ** This routine only works on unix. On Windows, simply return |
| 1299 | ** a copy of the input. |
| 1300 | */ |
| 1301 | char *file_fullexename(const char *zCmd){ |
| 1302 | #ifdef _WIN32 |
| 1303 | return fossil_strdup(zCmd); |
| 1304 | #else |
| 1305 | char *zPath; |
| 1306 | char *z; |
| 1307 | if( zCmd[0]=='/' ){ |
| 1308 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -1298,10 +1298,54 @@ | |
| 1298 | ** This routine only works on unix. On Windows, simply return |
| 1299 | ** a copy of the input. |
| 1300 | */ |
| 1301 | char *file_fullexename(const char *zCmd){ |
| 1302 | #ifdef _WIN32 |
| 1303 | char *zPath; |
| 1304 | char *z = 0; |
| 1305 | const char *zExe = ""; |
| 1306 | if( sqlite3_strlike("%.exe",zCmd,0)!=0 ) zExe = ".exe"; |
| 1307 | if( file_is_absolute_path(zCmd) ){ |
| 1308 | return mprintf("%s%s", zCmd, zExe); |
| 1309 | } |
| 1310 | if( strchr(zCmd,'\\')!=0 && strchr(zCmd,'/')!=0 ){ |
| 1311 | int i; |
| 1312 | Blob out = BLOB_INITIALIZER; |
| 1313 | file_canonical_name(zCmd, &out, 0); |
| 1314 | blob_append(&out, zExe, -1); |
| 1315 | z = fossil_strdup(blob_str(&out)); |
| 1316 | blob_reset(&out); |
| 1317 | for(i=0; z[i]; i++){ if( z[i]=='/' ) z[i] = '\\'; } |
| 1318 | return z; |
| 1319 | } |
| 1320 | z = mprintf(".\\%s%s", zCmd, zExe); |
| 1321 | if( file_isfile(z, ExtFILE) ){ |
| 1322 | int i; |
| 1323 | Blob out = BLOB_INITIALIZER; |
| 1324 | file_canonical_name(zCmd, &out, 0); |
| 1325 | blob_append(&out, zExe, -1); |
| 1326 | z = fossil_strdup(blob_str(&out)); |
| 1327 | blob_reset(&out); |
| 1328 | for(i=0; z[i]; i++){ if( z[i]=='/' ) z[i] = '\\'; } |
| 1329 | return z; |
| 1330 | } |
| 1331 | fossil_free(z); |
| 1332 | zPath = fossil_getenv("PATH"); |
| 1333 | while( zPath && zPath[0] ){ |
| 1334 | int n; |
| 1335 | char *zColon; |
| 1336 | zColon = strchr(zPath, ';'); |
| 1337 | n = zColon ? (int)(zColon-zPath) : (int)strlen(zPath); |
| 1338 | while( n>0 && zPath[n-1]=='\\' ){ n--; } |
| 1339 | z = mprintf("%.*s\\%s%s", n, zPath, zCmd, zExe); |
| 1340 | if( file_isfile(z, ExtFILE) ){ |
| 1341 | return z; |
| 1342 | } |
| 1343 | fossil_free(z); |
| 1344 | if( zColon==0 ) break; |
| 1345 | zPath = zColon+1; |
| 1346 | } |
| 1347 | return fossil_strdup(zCmd); |
| 1348 | #else |
| 1349 | char *zPath; |
| 1350 | char *z; |
| 1351 | if( zCmd[0]=='/' ){ |
| 1352 |