TIP 601: remove home folder shortcuts "~/" and "~user/" from file commands

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Author:         Harald Oehlmann <[email protected]>
State:          Draft
Type:           Project
Vote:           Pending
Tcl-Version:    9.0

Abstract

A user home folder is inserted, if a file path starts with "~". This proposal is to remove this functionality.

Rationale

A file name: "~abc.txt" is interpreted as the home folder of user "abc.txt". This results in an error message, even if the file exists.

This mimic may be helpful in an interactive shell, but makes access to files starting with "~" quite difficult. The file name must be prefixed by "./", if it is in the beginning of a file path.

The required code for file handling for files from foreign sources is:

if {[string match ~* $path]} {
    set path "./$path"
}

And the other way around on file output.

Specification

Remove the special handling of "~" from TCL file commands.

If it is used somewhere, replace it by a construction like "$env(HOME)/".

Discussion

clt thread

Please refer to the CLT thread titled "User does not exists when file name start with ~" and started 2021-05-06 10:13

Some highlights:

broken code to fixed by this TIP

open [lindex $argv 0] ;

or:

foreach fn [glob *] { open $fn } ;

the latter is especially puzzling, once you have a file starting with ~ in the directory, it suddenly fails.

Compatibility remark

And, the ~ breakage appears in the first run of an old script in a future v9 interpreter (file not found error) while the hidden latent data dependent bug is just waiting to bite someday.

Comment by Don Porter

This is a much deeper issue than either that draft TIP or the posts here have uncovered. The VFS layer has a problem not only with paths beginning with '~', but with all paths that have a prefix that can be claimed by a mounted Tcl_Filesystem. The same ./ prefixing has to be applied to workaround implications of this unfortunate design. A related matter is that prefixes and patterns that determine [file system] assignments are not accomplished by a registration, but by a round-robin game of hot potato. The design flaws are large and deep. A good solution is a pretty major rewrite. This isn't a quick fix.

Sometimes I think a good partial solution would be a rewrite that replaced all the conditional branches that implement the ~ translation pervasively in the VFS implementation, with a different strategy that made ~ translation available only through a separately mounted Tcl_Filesystem that claimed the path names matching ~*. In that revised strategy, more scripts and apps would have the option of unmounting that Tcl_Filesystem to disable the feature.

Some history and additional information in ticket

https://core.tcl-lang.org/tcl/tktview/2511011

and probably other tickets I cannot find quickly now.

wiki

Here is the wiki page dedicated to this issue:

https://wiki.tcl-lang.org/page/Tilde+Substitution

Implementation

ToDo - volunteers ?

Compatibility

No compatibility, as targeting TCL9.

Copyright

This document has been placed in the public domain.