Tcl Source Code

View Ticket
Login
Ticket UUID: 566669
Title: [fix] file dirname ~
Type: Patch Version: None
Submitter: taguchiv6 Created on: 2002-06-10 03:29:15
Subsystem: 37. File System Assigned To: vincentdarley
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2002-06-28 08:48:44
Resolution: Fixed Closed By: taguchiv6
    Closed on: 2002-06-28 01:48:44
Description:
Under Unix env, "file dirname ~" command does not
work fine.

TclpObjNormalizePath() in unix/tclUnixFCmd.c has a bug.
valiable "nextCheckPoint" sometime still 0, but
This value is used as argments for
Tcl_UtfToExternalDString().

This patch will fix this probrem.

Thanks.
User Comments: taguchiv6 added on 2002-06-28 08:48:44:
Logged In: YES 
user_id=357728

Thanks, Vince!

My plathomes are:
FreeBSD-3.2, 4.5, 4.6, and FreeBSD-5.0.

Under all version of FreeBSD, this probrem
has fixed.

Thanks.

vincentdarley added on 2002-06-27 19:29:26:
Logged In: YES 
user_id=32170

Applied fix to cvs head.  Note that fix is different to 
attached patches.

vincentdarley added on 2002-06-27 15:21:15:
Logged In: YES 
user_id=32170

Could you give some more details of your platform 
(what version of what unix)?  Unless we can reliably 
reproduce this problem and find the root cause of it, we 
can't fix it.  Clearly on the unix platform I tested (Linux), 
this problem isn't seen.  Nor on Windows or MacOS.

The patch you've given addresses the symptom of the 
problem you are seeing, but not the root cause, so we 
cannot apply that as is.

taguchiv6 added on 2002-06-27 12:45:02:
Logged In: YES 
user_id=357728

I've got following outputs from "make test"

==== cmdAH-8.44 Tcl_FileObjCmd: dirname FAILED
==== Contents of test case:

    global env
    set temp $env(HOME)
    set env(HOME) "~"
    testsetplatform unix
    set result [list [catch {file dirname ~} msg] $msg]
    set env(HOME) $temp
    set result

---- Result was:
0 /usr/local/src/tcl
---- Result should have been (exact matching):
0 ~
==== cmdAH-8.44 FAILED
==== cmdAH-8.46 Tcl_FileObjCmd: dirname FAILED
==== Contents of test case:

    global env
    set temp $env(HOME)
    set env(HOME) "/home/test"
    testsetplatform mac
    set result [list [catch {file dirname ~} msg] $msg]
    set env(HOME) $temp
    set result

---- Result was:
0 usr:local:src:tcl:unixhome
---- Result should have been (exact matching):
0 home:
==== cmdAH-8.46 FAILED


==== cmdAH-9.43 Tcl_FileObjCmd: tail FAILED
==== Contents of test case:

    global env
    set temp $env(HOME)
    set env(HOME) "~"
    testsetplatform unix
    set result [file tail ~]
    set env(HOME) $temp
    set result

---- Result was:
unix~
---- Result should have been (exact matching):

==== cmdAH-9.43 FAILED

... [snip] ...
==== filename-11.13 Tcl_GlobCmd FAILED
==== Contents of test case:

    list [catch {file join [lindex [glob ~] 0]} msg] $msg

---- Result was:
1 {no files matched glob pattern "~"}
---- Result should have been (exact matching):
0 /root
==== filename-11.13 FAILED


==== filename-11.45 Tcl_GlobCmd on root volume FAILED
==== Contents of test case:

    set res1 ""
    set res2 ""
    catch {
        set res1 [glob -dir [lindex [file volumes] 0] -tails
*]
    }
    catch {
        set tmpd [pwd]
        cd [lindex [file volumes] 0]
        set res2 [glob *]
        cd $tmpd
    }
    expr {$res1 == $res2}

---- Result was:
0
---- Result should have been (exact matching):
1
==== filename-11.45 FAILED
==== filesystem-5.1 cache and ~ FAILED
==== Contents of test case:
set orig $env(HOME)
        set ::env(HOME) /foo/bar/blah
        set testdir ~
        set res1 "Parent of ~ (/foo/bar/blah) is [file
dirname $testdir]"
        set ::env(HOME) /a/b/c
        set res2 "Parent of ~ (/a/b/c) is [file dirname
$testdir]"
        set ::env(HOME) $orig
        list $res1 $res2
---- Result was:
{Parent of ~ (/foo/bar/blah) is
/usr/local/src/tcl/unix/foo/bar} {Parent of ~ (/
a/b/c) is /usr/local/src/tcl/unix/a/b}
---- Result should have been (regexp matching):
{Parent of ~ \(/foo/bar/blah\) is (/foo/bar|foo:bar)}
{Parent of ~ \(/a/b/c\) is
 (/a/b|a:b)}
==== filesystem-5.1 FAILED

vincentdarley added on 2002-06-21 23:29:41:
Logged In: YES 
user_id=32170

I must say, I cannot reproduce your "bug" at all.  
According to your message below, (2002-06-18), you 
list the desired return values for various calls.  I've just 
compiled the latest tcl 8.4 cvs distribution and get the 
following:

% info tclv
8.4
% file dirname ~
/home/users/v/vi
% cd ~
% pwd
/home/users/v/vi/vincentdarley
% set env(HOME) ~
~
% file dirname ~
~
% file tail ~
%

I don't see how these differ from what you are expecting!

If you disagree, please provide a standard Tcl test which 
reproduces the problems you see.

vincentdarley added on 2002-06-18 17:37:04:
Logged In: YES 
user_id=32170

Assigning to Donal for his opinion on validity of the 
desired behaviour (the patch itself needs to be rewritten 
to move the desired behaviour deeper into Tcl).

I don't understand the comment "these behaviours are 
written in test code", when Tcl 8.4 currently passes all 
filesystem tests on unix, yet you are saying Tcl 8.4's 
behaviour is wrong?  Can you provide some new tests 
which (a) fail on Tcl 8.4 (and 8.3?) at present, but (b) 
pass with your patch?

cheers,  Vince.

taguchiv6 added on 2002-06-18 14:41:22:

File Added - 25299: tcl-file-normalize+dirname+tail-patch-20020618

Logged In: YES 
user_id=357728

Here is a new patch-set.

unix/tclUnixFCmd.c:
"file dirname ~" will return correct value.

generic/tclFileName.c:
Special case. if env(HOME) == "~", then
"file dirname ~" must return "~".

generic/tclCmdAH.c:
same case. if env(HOME) == "~", then
"file tail ~" must return "".

These behaviors are written in test code.

I've tested them using "make test".
I think these patch work fine.
some tests for "file" command and filesystem
will repare by this patch.

Thanks.

vincentdarley added on 2002-06-13 15:37:40:
Logged In: YES 
user_id=32170

Looks possible!  Have you run the entire test suite 
('make test') with this new change?  What happens?  Else 
can someone else with a Unix machine test this...

taguchiv6 added on 2002-06-13 11:42:48:

File Added - 25015: tcl-file-normalize-patch-20020613

Logged In: YES 
user_id=357728

How about this new patch?

vincentdarley added on 2002-06-11 15:32:23:
Logged In: YES 
user_id=32170

I've been informed that running the test suite with your 
patched version shows up a large number of errors...  
This means we can't commit the change.  I do accept 
that it is a bug, though!

taguchiv6 added on 2002-06-11 08:12:07:

File Added - 24847: tcl-patch-ac

Logged In: YES 
user_id=357728

Here is a test sequence:

1. Original version:
%puts $env(HOME)
/root
% puts [pwd]
/usr/local/src/tcl-current/tcl/unix
% file dirname ~
/usr/local/src/tcl-current/tcl/unix

I think this return value is unexpected one.

2. Patched version:
%puts $env(HOME)
/root
% puts [pwd]
/usr/local/src/tcl-current/tcl/unix
% file dirname ~
/

I think it work fine.

And thanks Vince.
I cannot find out variable "pathLen" ;-)
So I used strlen(3).
But I think using "pathLen" is more excelent.

Here is a new patch for tclUnixFCmd.c, v1.21 2002/04/07.

Please commit it.
Thanks.

nobody added on 2002-06-10 17:36:37:
Logged In: NO 

What does 'file dirname ~' give for you?  Can you provide 
a test we can add to the test suite which shows the bug?

thanks,

vincentdarley added on 2002-06-10 15:59:37:
Logged In: YES 
user_id=32170

Would 'nextCheckpoint = pathLen' work for you as 
well?  I believe this will have the same value as 'strlen
(path), and will avoid the need to recompute the length.. 
(which will therefore be faster, in this crucial procedure).

taguchiv6 added on 2002-06-10 10:29:15:

File Added - 24762: tcl-patch-ac

Attachments: