Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2002-01-25
20:43 • Ticket [504950ffff] SetFsPathFromAny: ~//foo -> /foo status still Closed ... artifact: e84cd8b633 user: dgp
18:11 • Ticket [504950ffff]: 4 changes artifact: 7c0045d5c4 user: nobody
11:27 • Closed ticket [504950ffff]. artifact: d5642b1136 user: dgp
2002-01-24
01:40 • Ticket [504950ffff]: 4 changes artifact: a989545f8c user: dgp
01:39 • Add attachment tilde.patch to ticket [504950ffff] artifact: b63935c70d user: dgp
01:39 • Ticket [504950ffff] SetFsPathFromAny: ~//foo -> /foo status still Open wi... artifact: 6c29f1c3e7 user: dgp
2002-01-23
21:40 • Ticket [504950ffff]: 4 changes artifact: d93e10b05c user: vincentdarley
20:45 • Ticket [504950ffff]: 4 changes artifact: 74439469a6 user: dgp
20:42 • Ticket [504950ffff]: 5 changes artifact: f9b0d3e223 user: dgp
20:39 • Ticket [504950ffff]: 5 changes artifact: e15d7ff77d user: dgp
01:49 • Ticket [504950ffff]: 4 changes artifact: 44e5ee1fad user: dgp
2002-01-22
17:40 • Ticket [504950ffff]: 4 changes artifact: 63d5cfc709 user: vincentdarley
01:31 • Ticket [504950ffff]: 4 changes artifact: 55fdc059df user: dgp
00:33 • Ticket [504950ffff]: 4 changes artifact: 73046c5205 user: nobody
2002-01-19
01:53 • Ticket [504950ffff]: 4 changes artifact: 264dc677cf user: dgp
01:41 • Ticket [504950ffff]: 4 changes artifact: 966830794b user: dgp
2002-01-17
17:01 • New ticket [504950ffff]. artifact: 96cd11245e user: dgp

SetFsPathFromAny: ~//foo -> /foo

Closed / Fixed504950ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 25 years ago
Descriptionplain2002-01-17 17:01:24
The new Tcl_FSGetTranslatedStringPath appears to be
the VFS-aware counterpart of Tcl_TranslateFileName.
However, they differ in their translation of file
names on non-Unix platforms.

On Windows, Tcl_TranslateFileName converts all '/'
separators to '\'.  The new routine does not.

On Mac, Tcl_TranslateFileName and the new routine
differ on how they manage runs of ':'.

In particular, if I rewrite Tcl_TranslateFileName
as a wrapper around Tcl_FSGetTranslatedStringPath,
then the following tests fail:

cmdAH-19.7
filename-10.2
filename-10.3
filename-10.13
filename-10.15
filename-10.16
filename-10.17
filename-10.18
filename-10.21
filename-10.22
dgpplain2002-01-19 01:41:16
Logged In: YES 
user_id=80530

Hmmm.... Tcl_FSGetNativePath might be what I want instead.
dgpplain2002-01-19 01:53:42
Logged In: YES 
user_id=80530

Nope.  Tcl_FSGetNativePath is much worse.
nobodyplain2002-01-22 00:33:29
Logged In: NO 

Tcl_FSGetTranslatedStringPath is designed _not_ to convert 
backslashes, (unlike the older string based API), so those 
tests will need changing if they now claim to test the new 
routine (this is documented in the source code, but perhaps 
not in the docs).  Could you please list the actual bad 
test results instead of just the numbers (else, I will have 
time in a couple of weeks to look at this properly).

More generally, 'Tcl_FSGetNormalizedPath' is the ideal 
thing to use under most circumstances (but, note, it 
returns an absolute path).

-- Vince.
dgpplain2002-01-22 01:31:49
Logged In: YES 
user_id=80530

Let me ask it this way then.  The command [file nativename]
is implemented in lines 1016-1032 of tclCmdAH.c as:

1016         case FILE_NATIVENAME: {
1017             char *fileName;
1018             Tcl_DString ds;
1019
1020             if (objc != 3) {
1021                 goto only3Args;
1022             }
1023             fileName = Tcl_GetString(objv[2]);
1024             fileName = Tcl_TranslateFileName(interp, 
fileName, &ds);
1025             if (fileName == NULL) {
1026                 return TCL_ERROR;
1027             }
1028             
Tcl_SetStringObj(Tcl_GetObjResult(interp), fileName,
1029                              Tcl_DStringLength(&ds));
1030             Tcl_DStringFree(&ds);
1031             return TCL_OK;
1032         }

If I want to re-implement so that Tcl_TranslateFileName()
is not called, but some of the new VFS-aware routines are
called instead, what should I call to get the same results?
vincentdarleyplain2002-01-22 17:40:59
Logged In: YES 
user_id=32170

My recommendation would be to implement those lines 
as 'Tcl_FSGetTranslatedPathString', followed by (on 
Windows) a manual translation of forward slashes to 
backslashes to yield the desired 'native path name'.

The rest of the Tcl core's C code doesn't really care about 
the result of the Tcl-level command 'file nativename' (the 
core uses the caching Tcl_FSGetNativePath), so I think it's 
ok to do things like this.

An alternative (more complex) would be to add a new Tcl_FS 
command which returns the relative part of the normalized 
native path, but that's quite a complex operation.

Daniel Steffen may need to look at how the code handles 
runs of ':' if there are problems there.

Hope that helps; sorry not to be more actively helpful 
right now.
dgpplain2002-01-23 01:49:37
Logged In: YES 
user_id=80530

OK, that will take care of me on Windows and Unix.

After looking over filename.n, it appears to me that
Tcl_FsGetTranslatedPathString may be buggy in its
interpretation of multiple ':' on Mac.  '::' mean
parent directory, ':::' means parent of parent, etc.,
but it's not clear that meaning is being preserved.

More details after I look it over.
dgpplain2002-01-23 20:39:06
Logged In: YES 
user_id=80530


Here's a specific bug related to the trouble seen on
Macs.  The tilde-expansion in SetFsPathFromAny is
flawed in the way it handle separators right after
the expanded tilde.  This is most easily seen by the
way it converts the string ~//foo to the path /foo.
dgpplain2002-01-23 20:42:11
Logged In: YES 
user_id=80530


Here's a specific bug related to the trouble seen on
Macs.  The tilde-expansion in SetFsPathFromAny is
flawed in the way it handle separators right after
the expanded tilde.  This is most easily seen by the
way it converts the string ~//foo to the path /foo.
dgpplain2002-01-23 20:45:34
Logged In: YES 
user_id=80530


Here's a specific bug related to the trouble seen on
Macs.  The tilde-expansion in SetFsPathFromAny is
flawed in the way it handle separators right after
the expanded tilde.  This is most easily seen by the
way it converts the string ~//foo to the path /foo.
vincentdarleyplain2002-01-23 21:40:18
Logged In: YES 
user_id=32170

What should the correct result of '~//foo' be?  Is it 
defined to be the same as '~/foo'?

What about on MacOS?  What are ~::foo and ~:::foo?

Vince.
dgpplain2002-01-24 01:39:55
Logged In: YES 
user_id=80530

Yes, and see tests filename-10.{13,15,16}.

Here's a patch that fixes the problem.  Please
review that it fits in with the VFS system design.
dgpplain2002-01-24 01:40:09
File Added - 16643: tilde.patch
dgpplain2002-01-25 11:27:34
Logged In: YES 
user_id=80530

committing fix to HEAD (8.4a4).  If you find problems
with it, Vince, we can back it out.
nobodyplain2002-01-25 18:11:34
Logged In: NO 

This looks fine.  A more efficient solution _might_ be 
possible (I haven't looked closely enough to be absolutely 
sure), by simply skipping any extra separators and then 
using the existing 'JoinToPath' stuff.   Anyway, the 
existing solution looks good.  -- Vince.
dgpplain2002-01-25 20:43:38
Logged In: YES 
user_id=80530

That approach would be correct and more efficient on
unix-style paths, but would be completely wrong for
the mac-style paths.  It seemed somehow "cleaner" to
use existing TclpNative* routines to cover the platform
differences rather than add more platform-specific
processing directly in SetFsPathFromAny itself.

That said, I certainly have no objection if later on you
replace this correct implementation with a different
correct implementation that's also more efficient.
Log in (anonymous is fine) to add a comment.

Attachments: