Fossil SCM
Enhance the file_canonical_name() function so that it always includes the drive letter prefix on Windows.
Commit
40376ef892bbee029f554a413112eaa7fe86c7c15469f5aad6a2f140ed6ce6f0
Parent
761c24e7b08137a…
1 file changed
+18
-6
+18
-6
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -1302,25 +1302,37 @@ | ||
| 1302 | 1302 | } |
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | /* |
| 1306 | 1306 | ** Compute a canonical pathname for a file or directory. |
| 1307 | -** Make the name absolute if it is relative. | |
| 1308 | -** Remove redundant / characters | |
| 1309 | -** Remove all /./ path elements. | |
| 1310 | -** Convert /A/../ to just / | |
| 1307 | +** | |
| 1308 | +** * Make the name absolute if it is relative. | |
| 1309 | +** * Remove redundant / characters | |
| 1310 | +** * Remove all /./ path elements. | |
| 1311 | +** * Convert /A/../ to just / | |
| 1312 | +** * On windows, add the drive letter prefix. | |
| 1313 | +** | |
| 1311 | 1314 | ** If the slash parameter is non-zero, the trailing slash, if any, |
| 1312 | 1315 | ** is retained. |
| 1313 | 1316 | ** |
| 1314 | 1317 | ** See also: file_canonical_name_dup() |
| 1315 | 1318 | */ |
| 1316 | 1319 | void file_canonical_name(const char *zOrigName, Blob *pOut, int slash){ |
| 1320 | + char zPwd[2000]; | |
| 1317 | 1321 | blob_zero(pOut); |
| 1318 | 1322 | if( file_is_absolute_path(zOrigName) ){ |
| 1319 | - blob_appendf(pOut, "%/", zOrigName); | |
| 1323 | +#if defined(_WIN32) | |
| 1324 | + if( fossil_isdirsep(zOrigName[0]) ){ | |
| 1325 | + /* Add the drive letter to the full pathname */ | |
| 1326 | + file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName)); | |
| 1327 | + blob_appendf(pOut, "%.2s%/", zPwd, zOrigName); | |
| 1328 | + }else | |
| 1329 | +#endif | |
| 1330 | + { | |
| 1331 | + blob_appendf(pOut, "%/", zOrigName); | |
| 1332 | + } | |
| 1320 | 1333 | }else{ |
| 1321 | - char zPwd[2000]; | |
| 1322 | 1334 | file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName)); |
| 1323 | 1335 | if( zPwd[0]=='/' && strlen(zPwd)==1 ){ |
| 1324 | 1336 | /* when on '/', don't add an extra '/' */ |
| 1325 | 1337 | if( zOrigName[0]=='.' && strlen(zOrigName)==1 ){ |
| 1326 | 1338 | /* '.' when on '/' mean '/' */ |
| 1327 | 1339 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -1302,25 +1302,37 @@ | |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | /* |
| 1306 | ** Compute a canonical pathname for a file or directory. |
| 1307 | ** Make the name absolute if it is relative. |
| 1308 | ** Remove redundant / characters |
| 1309 | ** Remove all /./ path elements. |
| 1310 | ** Convert /A/../ to just / |
| 1311 | ** If the slash parameter is non-zero, the trailing slash, if any, |
| 1312 | ** is retained. |
| 1313 | ** |
| 1314 | ** See also: file_canonical_name_dup() |
| 1315 | */ |
| 1316 | void file_canonical_name(const char *zOrigName, Blob *pOut, int slash){ |
| 1317 | blob_zero(pOut); |
| 1318 | if( file_is_absolute_path(zOrigName) ){ |
| 1319 | blob_appendf(pOut, "%/", zOrigName); |
| 1320 | }else{ |
| 1321 | char zPwd[2000]; |
| 1322 | file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName)); |
| 1323 | if( zPwd[0]=='/' && strlen(zPwd)==1 ){ |
| 1324 | /* when on '/', don't add an extra '/' */ |
| 1325 | if( zOrigName[0]=='.' && strlen(zOrigName)==1 ){ |
| 1326 | /* '.' when on '/' mean '/' */ |
| 1327 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -1302,25 +1302,37 @@ | |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | /* |
| 1306 | ** Compute a canonical pathname for a file or directory. |
| 1307 | ** |
| 1308 | ** * Make the name absolute if it is relative. |
| 1309 | ** * Remove redundant / characters |
| 1310 | ** * Remove all /./ path elements. |
| 1311 | ** * Convert /A/../ to just / |
| 1312 | ** * On windows, add the drive letter prefix. |
| 1313 | ** |
| 1314 | ** If the slash parameter is non-zero, the trailing slash, if any, |
| 1315 | ** is retained. |
| 1316 | ** |
| 1317 | ** See also: file_canonical_name_dup() |
| 1318 | */ |
| 1319 | void file_canonical_name(const char *zOrigName, Blob *pOut, int slash){ |
| 1320 | char zPwd[2000]; |
| 1321 | blob_zero(pOut); |
| 1322 | if( file_is_absolute_path(zOrigName) ){ |
| 1323 | #if defined(_WIN32) |
| 1324 | if( fossil_isdirsep(zOrigName[0]) ){ |
| 1325 | /* Add the drive letter to the full pathname */ |
| 1326 | file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName)); |
| 1327 | blob_appendf(pOut, "%.2s%/", zPwd, zOrigName); |
| 1328 | }else |
| 1329 | #endif |
| 1330 | { |
| 1331 | blob_appendf(pOut, "%/", zOrigName); |
| 1332 | } |
| 1333 | }else{ |
| 1334 | file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName)); |
| 1335 | if( zPwd[0]=='/' && strlen(zPwd)==1 ){ |
| 1336 | /* when on '/', don't add an extra '/' */ |
| 1337 | if( zOrigName[0]=='.' && strlen(zOrigName)==1 ){ |
| 1338 | /* '.' when on '/' mean '/' */ |
| 1339 |