Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2015-05-31
08:33 • Ticket [e3da32d816] max os x glob returns the decomposed filenames status ... artifact: f16f9ab227 user: anonymous
2015-05-25
21:23 • Ticket [e3da32d816]: 4 changes artifact: 1204e76c36 user: anonymous
2015-05-16
06:01 • Ticket [e3da32d816]: 6 changes artifact: 88b34a4b80 user: dkf
2015-04-21
05:03 • New ticket [e3da32d816]. artifact: 85fb63ca24 user: anonymous

max os x [glob] returns the decomposed filenames

Opene3da32d8169e7584f93dea8592f1f5b9a37f0413Created 12 years agoUpdated 12 years ago
Descriptionplain2015-04-21 05:03:23
On the mac, a [glob] will return the decomposed utf-8 form of the filename.
glob should convert the filenames to the standard utf-8 format.
An encoding to convert these might also be useful.

#!/opt/local/bin/tclsh
#
# references
#     http://stackoverflow.com/questions/6153345/different-utf8-encoding-in-filenames-os-x
#     https://developer.apple.com/library/mac/qa/qa1173/_index.html

set orig {aá}
set fh [open $orig w]
close $fh
set fnlist [glob -nocomplain a*]
foreach {fn} $fnlist {
  if { ! [regexp {^a} $fn] } {
    continue
  }
  puts "orig:$orig"
  puts "  fn:$fn"
  if { $orig == $fn } {
    puts "  equal"
  } else {
    puts "  not equal"
  }
}
dkfhtml2015-05-16 06:01:10

This is exactly why we need to put encoding normalization into Tcl as part of the unicode fixes. That's a lot of code, unfortunately. But we'll probably leave glob doing what it does now, since it's just telling you what is there, and will work correctly for the main use case of getting filenames so that you can use them with file-manipulating operations.

anonymous (claiming to be [email protected])plain2015-05-25 21:23:50
This bug has been extant since 2003 ( http://sourceforge.net/p/tcl/bugs/2501/ ).

I guess I'm not in the main use case :), though I certainly agree -- most of the time, if the user is just dealing with files, it's not an issue.
anonymous (claiming to be [email protected])plain2015-05-31 08:33:30
Here is the work around in case anyone else looks for this issue.
  set flist [glob *]
  set fn gfl.txt
  set fh [open $fn w]
  puts $fh $flist
  close $fh
  set flist [exec iconv -f UTF-8-MAC -t UTF-8 $fn]
  file delete $fn
Log in (anonymous is fine) to add a comment.