Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2009-10-28
23:51 • Closed ticket [2806250fff]: glob, tilde string representation anomaly plus 6... artifact: 4cb68eba66 user: kennykb
23:51 • Ticket [2806250fff]: 4 changes artifact: 9e21f81e8c user: kennykb
23:22 • Ticket [2806250fff]: 1 change artifact: ef435be004 user: dgp
23:22 • Ticket [2806250fff]: 4 changes artifact: ebe073f0d1 user: dgp
04:01 • Open ticket [2806250fff]. artifact: bf15e7239f user: dgp
04:00 • Ticket [2806250fff]: 4 changes artifact: 38f72b1631 user: dgp
2009-08-20
22:18 • Closed ticket [2806250fff]. artifact: 510517fdde user: dgp
22:00 • Ticket [2806250fff]: 4 changes artifact: 26714fc932 user: dgp
21:52 • Ticket [2806250fff]: 4 changes artifact: 33b92a45ef user: dgp
21:50 • Add attachment 2806250-2.patch to ticket [2806250fff] artifact: 265ee3f77b user: dgp
21:50 • Ticket [2806250fff] glob, tilde string representation anomaly status still O... artifact: 8c324b21b4 user: dgp
04:49 • Ticket [2806250fff]: 4 changes artifact: fc33cb932f user: dgp
04:49 • Ticket [2806250fff]: 4 changes artifact: 17dc50c4e6 user: dgp
04:49 • Add attachment 2806250.patch to ticket [2806250fff] artifact: 21d9a82b9a user: dgp
00:25 • Ticket [2806250fff] glob, tilde string representation anomaly status still O... artifact: 0b3c6def0b user: dgp
2009-08-19
00:42 • Ticket [2806250fff]: 4 changes artifact: 970a9a65c4 user: dgp
2009-08-10
07:26 • Ticket [2806250fff]: 4 changes artifact: 2140700d93 user: dkf
06:50 • Ticket [2806250fff]: 1 change artifact: 31697cfefc user: juliannoble
06:50 • Ticket [2806250fff]: 4 changes artifact: 8aafff0143 user: juliannoble
2009-08-09
19:12 • Ticket [2806250fff]: 5 changes artifact: fd1a74e736 user: juliannoble
2009-06-17
01:30 • Ticket [2806250fff]: 4 changes artifact: a4806bd8bb user: juliannoble
00:47 • Open ticket [2806250fff]. artifact: f33f44f827 user: juliannoble
2009-06-16
01:42 • Pending ticket [2806250fff]. artifact: fb67b2ffdb user: dgp
01:21 • Ticket [2806250fff]: 1 change artifact: 012b8cb7b9 user: dgp
01:20 • Ticket [2806250fff]: 4 changes artifact: d8b3814dc3 user: dgp
2009-06-15
22:17 • Ticket [2806250fff]: 4 changes artifact: b4e61565c3 user: juliannoble
2009-06-14
16:57 • New ticket [2806250fff]. artifact: 161b58bdd8 user: juliannoble

glob, tilde string representation anomaly

Closed / Fixed2806250fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2009-06-14 16:57:33
  When a filename contains a tilde character 'file exists' may falsely return zero.
  The bug occurs when the filename as returned from glob is used.
  Any call to 'file normalize' - even without using the returned value will cause a subsequent 'file exists' to correctly return 1.

  When the path is entered directly in tclsh, or hardcoded into a script, file exists correctly returns 1.

  set folder {/usr/local/test/} 
  set files [glob -dir $folder -type f *] 
  foreach f $files { 
      #puts [file normalize $f] 
      puts "$f exists: [file exists $f]" 
  } 


Simply create a text file with the name "~test.txt" in the test 
folder. 


With the 1st puts commented, the output is: 
/usr/local/test/~test.txt exists: 0 


With the puts uncommented, the output is: 
/usr/local/test/~test.txt 
/usr/local/test/~test.txt exists: 1 


Tested on FreeBSD  8.6b1.1 2009-06-14 checkout.
juliannobleplain2009-06-15 22:17:57
Verified that bug occurs on windows vista x64 with Tcl 8.6b1.1
Does not occur with an 8.5.2 tclkitsh on that platform.

The bug appears to also relate in some way to the current working directory.

If there is another copy of the file ~test.txt  within whatever directory [pwd] refers to - then [info exists] returns 1.

The tilde seems to somehow cause the path to refer to the working directory instead of the one being globbed upon.

(so for example - if the original script is placed in the same folder as the one with the test file and run from there - the bug is not apparent)
dgpplain2009-06-16 01:20:06
Can't reproduce on Linux with the tip of
any active branch.
dgp Ticket [2806250fff]: 1 change [History diff]2009-06-16 01:21:47
dgpplain2009-06-16 01:42:19
Perhaps some detail is not getting
reported, and what's really happening
is some symptom of Bug 2511011?
juliannobleplain2009-06-17 00:47:38
Verified that it does occur on Linux (CentOS) with 8.6b1.1
(but does not occur with 8.5.7 tclkit)

uname -a
Linux project-open-v33 2.6.18-53.1.21.el4 #1 SMP Tue May 20 09:34:19 EDT 2008 i686 i686 i386 GNU/Linux

This is the 3rd platform I've duplicated the bug on.
I'll explain it a bit more step by step - as I've found a couple of ways the bug can be hidden.

--------------------------------

create a folder structure  /tmp/working/examine

Make sure the examine folder contains only the ~test.txt  file
Save the following script as filenames.tcl - into the /tmp/working folder

set folder {/tmp/working/examine}
set files [glob -dir $folder -type f *]
foreach f $files {
    #puts [file normalize $f]
    puts "$f exists: [file exists $f]"
}


Make sure you run the script from within /tmp/working 
As mentioned in my other comment - if you run the script whilst your pwd is /tmp/working/examine - the bug will be masked.  

> cd /tmp/working/filenames.tcl
> tclsh filenames.tcl
/tmp/working/examine/~test.txt exists: 0


----------------------------------------------------------
Note that if you run it with the full path name to the script - you won't see the zero in the output.
ie it must be called as  'tclsh filenames.tcl'  not 'tclsh /tmp/working/filenames.tcl'

Another weird thing is that if you add the following line to the top of filenames.tcl - then suddenly the bug *does* appear when called as 'tclsh /tmp/working/filenames.tcl'

puts stdout "pwd: [pwd]"


It seems to me that it's possibly somewhat different to bug 2511011  because in this case we are supplying the -dir argument to glob and not using -tail,  so we are always dealing with the complete path.  As far as I can see - there should be no tilde/homedir substitution involved in this case.
juliannobleplain2009-06-17 01:30:22
> cd /tmp/working/filenames.tcl

should read:

>cd /tmp/working
juliannobleplain2009-08-09 19:12:22
priority raised.
This issue has come up again on CLT.
http://groups.google.com/group/comp.lang.tcl/browse_thread/thread/2c8027298fe860f3/28cb705e1fb0e74d#28cb705e1fb0e74d
juliannobleplain2009-08-10 06:50:06
Title updated to remove reference to 'file normalize'.
It seems that various other operations on the string  (e.g subst) can be used to coax a bad path representation to do the correct thing.
e.g
set f [string range $f 0 end]
juliannoble Ticket [2806250fff]: 1 change [History diff]2009-08-10 06:50:07
dkfplain2009-08-10 07:26:07
Sounds like a problem internal rep.
dgpplain2009-08-19 00:42:51
committed test fileName-20.7 to
all branches to test for this bug.
dgpplain2009-08-20 00:25:32
The PATHFLAGS != 0 internal rep for path
values stores the path in two parts, a "head"
and a "tail".  Much of the code that operates
on this rep makes the assumption that the
"tail" is a relative path.  When a value starting
with ~ is permitted to get stored as the tail,
these assumptions no longer hold.
dgpplain2009-08-20 04:49:20
File Added - 339822: 2806250.patch
dgpplain2009-08-20 04:49:46
Attached a patch for 8.5
dgpplain2009-08-20 21:50:43
File Added - 339935: 2806250-2.patch
dgpplain2009-08-20 21:52:32
Version 2 of the patch also removes some
special workaround code in TclMakePathRelative()
that prevented it from doing the wrong thing when
the "tail" held a string starting with ~.  Since we no
longer permit that, we do not need the workaround.

Large comments questioning the rationale of some
bits of code, and pondering about their reform also
in the new patch.
dgpplain2009-08-20 22:00:38
fix committed for 8.5.8.  Should see the
tests fileName-20.7,8 now pass.
dgpplain2009-08-20 22:18:44
allow_comments - 1


Committed more radical patch to HEAD
for 8.6b2 that also removes some large chunks
of code complexity which had no obvious value.
dgpplain2009-10-28 04:00:59
Reports on the chat indicate that tests
fileName-20.7,8 are failing on Windows.
Re-opened.
dgpplain2009-10-28 04:01:00
allow_comments - 0
dgpplain2009-10-28 23:22:34
tests are broken, kbk has the fix.
dgp Ticket [2806250fff]: 1 change [History diff]2009-10-28 23:22:35
kennykbplain2009-10-28 23:51:34
Fix committed - was poor test hygiene in managing the working directory.
kennykbplain2009-10-28 23:51:36
allow_comments - 1
Log in (anonymous is fine) to add a comment.

Attachments: