Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2015-10-06
14:51 • Closed ticket [b42a851475]: file normalize ~user returns wrong directory on Wind... artifact: 45ad011fdb user: jan.nijtmans
14:49
Fix [b42a851475]: file normalize ~user returns wrong directory on Windows check-in: 481cc1a100 user: jan.nijtmans tags: trunk
14:25
Fix [b42a851475]: file normalize ~user returns wrong directory on Windows check-in: d0d427004f user: jan.nijtmans tags: core-8-5-branch
10:14 • Ticket [b42a851475] file normalize ~user returns wrong directory on Windows ... artifact: fbb0e79a57 user: apnadkarni
03:00 • New ticket [b42a851475]. artifact: 6bffa021f4 user: apnadkarni

file normalize ~user returns wrong directory on Windows

Closed / Fixedb42a8514758d43c03f5404feb5543f921c22cf09Created 11 years agoUpdated 11 years ago
Descriptionplain2015-10-06 03:00:39
% file normalize ~
C:/Users/ashok/Documents
% file normalize ~ashok
C:/Users/Default

I would expect both to return the same result.

FWIW, 8.5.17 also has the same behaviour.
Referenced by2
  • 481cc1a100Fix [b42a851475]: file normalize ~user returns wrong directory on Windows check-in2015-10-06 14:49:23
  • d0d427004fFix [b42a851475]: file normalize ~user returns wrong directory on Windows check-in2015-10-06 14:25:36
apnadkarniplain2015-10-06 10:14:56
Some more information looking at the code in TclpGetUserHome in tclWinFile.c

- file normalize ~ looks at the HOME environment variable whereas ~ashok looks at the NetUserGetInfo call. The latter only returns non-null directory information if administrator has explicitly set the home dir path. Under the normal (default) case an empty string is returned. 

- When the home dir is "", the code then calls back to %SYSTEMDRIVE%:/users/default. This is broken for many reasons - the toplevel is "users" only on newer Windows versions and even that can be changed. Secondly the returned directory is not writable by the user without elevation. Third, it does not contain any files specific to the user.

The correct solution would be to use GetUserProfileDirectory but that is unworkable because that call requires a security token with the appropriate access rights.

A semi-workable solution would be to use GetProfilesDirectory and tack on the user name (essentially ~ashok -> GetProfilesDirectory/ashok) and return it if the corresponding directory exists. However, in this case ~ and ~ashok will not match. We cannot change semantics of ~ because current programs might be relying on it. Adding on a Documents part to the result of ~ashok is problematic because (I think) the folder is not called Documents on all Windows versions.

My suggestion is to go with the semi-workable solution because it is better than what we do today.
jan.nijtmanswiki2015-10-06 14:51:18

Suggested 'semi-workable solution' implemented now in core-8-5-branch and trunk.

Thanks for the report!

Log in (anonymous is fine) to add a comment.