TIP #99 Version 1.9: Add 'file link' to Tcl

This is not necessarily the current version of this TIP.


TIP:99
Title:Add 'file link' to Tcl
Version:$Revision: 1.9 $
Author:Vince Darley <vincentdarley at users dot sourceforge dot net>
State:Draft
Type:Project
Tcl-Version:8.4
Vote:Pending
Created:Tuesday, 11 June 2002

Abstract

Tcl can read links, but cannot create them. This TIP proposes adding a file link subcommand to allow cross-platform creation of links.

Proposal

Add a new subcommand with the following syntax:

      file link source ?target? ?linktype?

If target is not given, then returns the value of the link given by source (i.e. the name of the file it points to). If source isn't a symbolic link or its value cannot be read, then an error is returned. If target is given then creates a link from source to target.

When the target argument is given, an optional third argument linktype is allowed. When this third argument is not given, the type of link created is platform specific (i.e. the user is asking "please create any link that is possible in this filesystem"), but is by default a symbolic link where this is supported.

However, the user may wish to specify the type of the link explicitly with the optional linktype argument. Accepted values for linktype will be "symbolic" and "hard". On filesystems that either do not support any links, or do not support the specific type requested, an error message will be returned (in particular Windows 95, 98 and ME do not support any symbolic links at present, but Unix, MacOS and Windows NT/2000/XP (on NTFS drives) do).

The TIP proposes implementing:

           Unix,MacOSX       Win-NTFS             MacOS
symbolic:      yes        directories-only         yes
hard:          yes          files-only              no

This also leaves the avenue open, in the future, for the addition of other link types (e.g. Windows shortcuts) through additions to list of acceptable 'linktype's. This TIP only proposes adding the above options.

Rationale

There are many requests on comp.lang.tcl for this functionality (see http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF8&oe=UTF8&threadm=4dd3bea3.0206100250.95eeb4e%40posting.google.com&rnum=1&prev=/&frame=on for a recent thread), and if Tcl can read links (file readlink, file lstat), it really ought to be able to write them.

Discussion has shown that both symbolic and hard links are desirable.

Alternatives

There is no cross-platform alternative available. TclX provides a link command for Unix only, and Unix platforms can also use exec ln ?-s? command to achieve the same effect.

Reference Implementation

http://sourceforge.net/tracker/index.php?func=detail&aid=562970&group_id=10894&atid=310894

This reference implementation needs to be updated with the 'linktype' option.

Copyright

This document has been placed in the public domain.


Powered by TclThis is not necessarily the current version of this TIP.

TIP AutoGenerator - written by Donal K. Fellows