Fossil SCM

Enhance the file_canonical_name() function so that it always includes the drive letter prefix on Windows.

drh 2024-11-21 13:06 trunk
Commit 40376ef892bbee029f554a413112eaa7fe86c7c15469f5aad6a2f140ed6ce6f0
1 file changed +18 -6
+18 -6
--- src/file.c
+++ src/file.c
@@ -1302,25 +1302,37 @@
13021302
}
13031303
}
13041304
13051305
/*
13061306
** 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
+**
13111314
** If the slash parameter is non-zero, the trailing slash, if any,
13121315
** is retained.
13131316
**
13141317
** See also: file_canonical_name_dup()
13151318
*/
13161319
void file_canonical_name(const char *zOrigName, Blob *pOut, int slash){
1320
+ char zPwd[2000];
13171321
blob_zero(pOut);
13181322
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
+ }
13201333
}else{
1321
- char zPwd[2000];
13221334
file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName));
13231335
if( zPwd[0]=='/' && strlen(zPwd)==1 ){
13241336
/* when on '/', don't add an extra '/' */
13251337
if( zOrigName[0]=='.' && strlen(zOrigName)==1 ){
13261338
/* '.' when on '/' mean '/' */
13271339
--- 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

Keyboard Shortcuts

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