<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://tcl.activestate.com/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Thu Feb 09 11:18:28 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='99'>
<header><title>Add &apos;file link&apos; to Tcl</title><author address="mailto:vincentdarley@users.sourceforge.net">Vince Darley</author><status type='project' state='final' tclversion="8.4" vote='after'>$Revision: 1.23 $</status><history></history><created day='11' month='jun' year='2002' /></header>
<abstract>Tcl can read links, but cannot create them. This TIP proposes adding a <emph style="italic">file link</emph> subcommand to allow cross-platform creation of links.</abstract>
<body><section title="Proposal">
<para>Add a new subcommand with the following syntax:</para>
<verbatim><vline encoding='base64'>ICAgICAgZmlsZSBsaW5rID8tbGlua3R5cGU/IGxpbmtOYW1lID90YXJnZXQ/</vline></verbatim>
<para>If only one argument is given, that argument is assumed to be <emph style="italic">linkName</emph>, and this command returns the value of the link given by <emph style="italic">linkName</emph> (i.e. the name of the file it points to). If <emph style="italic">linkName</emph> isn&apos;t a link or its value cannot be read (as, for example, seems to be the case with hard links, which look just like ordinary files), then an error is returned.</para>
<para>If 2 arguments are given, then these are assumed to be <emph style="italic">linkName</emph> and <emph style="italic">target</emph>. If <emph style="italic">linkName</emph> already exists, or if <emph style="italic">target</emph> doesn&apos;t exist, an error will be returned. Otherwise, Tcl creates a new link called <emph style="italic">linkName</emph> which points to the existing filesystem object at <emph style="italic">target</emph>, where the type of the link is platform-specific (on Unix a symbolic link will be the default). This is useful for the case where the user wishes to create a link in a cross-platform way, and doesn&apos;t care what type of link is created.</para>
<para>If the user wishes to make a link of a <emph style="italic">specific type only</emph>, (and signal an error if for some reason that is not possible), then the optional <emph style="italic">linktype</emph> argument should be given. Accepted values for linktype are <emph style="italic">-symbolic</emph> and <emph style="italic">-hard</emph>.</para>
<para>When creating links 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).</para>
<para>The TIP proposes implementing:</para>
<verbatim><vline encoding='base64'>ICAgICAgICAgICBVbml4LE1hY09TWCAgICAgIFdpbi1OVEZTICAgICAgICAgICBNYWNPUw==</vline><vline encoding='base64'>c3ltYm9saWM6ICAgICAgeWVzICAgICAgICBkaXJlY3Rvcmllcy1vbmx5ICAgICAgeWVz</vline><vline encoding='base64'>aGFyZDogICAgICAgZmlsZXMtb25seSAgICAgZmlsZXMtb25seSAgICAgICAgICAgbm8=</vline></verbatim>
<para>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 <emph style="italic">linktype</emph>s. This TIP only proposes adding the above options.</para>
<para>This means that a general <emph style="italic">[file link $linkname $target]</emph> should always succeed on the above platforms (for both files and directories), but uses of <emph style="italic">-hard</emph> or <emph style="italic">-symbolic</emph> could fail, depending on the current platform, and the type of the path.</para>
</section>
<section title="Rationale">
<para>There are many requests on comp.lang.tcl for this functionality (see <url ref="http://groups.google.com/groups?dq=&amp;hl=en&amp;lr=&amp;ie=UTF8&amp;oe=UTF8&amp;threadm=4dd3bea3.0206100250.95eeb4e%40posting.google.com&amp;rnum=1&amp;prev=/&amp;frame=on"/> for a recent thread), and if Tcl can read links (<emph style="italic">file readlink</emph>, <emph style="italic">file lstat</emph>), it really ought to be able to write them.</para>
<para>Discussion has shown that both symbolic and hard links are desirable, and that for cross-platform use a general-purpose <emph style="italic">file link</emph> which creates <emph style="italic">something</emph> is useful.</para>
<para>Some users would prefer hard links to be the default, but on balance most people commenting seemed to prefer symbolic links as default. This has the added benefit that symbolic links will then be the default on MacOS, Unix and Windows for everything, <emph style="italic">except</emph> files on WinTcl (where hard-links are required).</para>
</section>
<section title="Alternatives">
<para>There is no cross-platform alternative available. TclX provides a <emph style="italic">link</emph> command for Unix only, and Unix platforms can also use <emph style="italic">exec ln ?-s?</emph> command to achieve the same effect.</para>
</section>
<section title="Reference Implementation">
<para>Tcl contains a <emph style="italic">testfilelink</emph> command in <emph style="italic">generic/tclTest.c</emph>, which is a partial implementation used by the test suite. For a full implementation of this TIP, including the <emph style="italic">-linktype</emph> switch, see:</para>
<para><emph style="italic"> <url ref="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=562970&amp;group_id=10894&amp;atid=310894"/> </emph></para>
<para>which includes extensive docs and tests.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>

