From: Jeff H. <JeffH@ActiveState.com> - 2002-07-24 22:41:20
|
Hemang brought up the following dilemma regarding the 'file copy' command in Tcl: -------8<-------8<-------8<-------8<-------8<-------8<-------8<------- It seems when I use "file copy -force -- $src $dst" and if $src is a soft link, then the resultant $dst created is also a softlink. Moreover, if $src is relative, $dst is also created as relative softlink which can result in error if the $dst has a different path. See below: godel:73> ls -l total 80 drwxr-xr-x 2 hlavana eng 69 Jul 24 17:04 bar lrwxrwxrwx 1 hlavana eng 8 Jul 24 17:01 foo -> test.exp -rw-r--r-- 1 hlavana eng 44 Jul 24 17:01 test.exp godel:74> tclsh % info patch 8.3.4 % file copy -force -- foo bar/abc % exit godel:75> ls -l bar/ total 16 lrwxrwxrwx 1 hlavana eng 8 Jul 24 17:05 abc -> test.exp godel:76> cat bar/abc cat: cannot open bar/abc godel:77> cp foo bar/def godel:78> ls -l bar/def -rw-r--r-- 1 hlavana eng 44 Jul 24 17:08 bar/def godel:79> On the other hand, if I use the unix cp command, it copies the file instead of creating a softlink. The same behavior is also observed with tcl8.4 (CVS Head). Is this the expected behavior? -------8<-------8<-------8<-------8<-------8<-------8<-------8<------- The question is, should Tcl be copying these as softlinks, or should it be more intelligent about it. Note that 8.4 file docs actually do doc the above behavior, but that is only because we (ActiveState) noticed this (what we considered unexpected) behavior and added it to the 8.4 docs for others. I don't want to necessarily validate that as the behavior though, if everyone else doesn't expect it either. Note that Linux has a cp -d option to copy as links, but Solaris and HP don't. However, cp -r on HP does copy links as links, whereas it normally copies links into new files (it docs this). Thoughts anyone? I'm inclined to make it check for links and copy those as files, but then this would slightly change behavior. The unix 'cp' throws an error, even with -f, when you want to copy a link that points to a non-existent file. Currently tcl doesn't complain at all, because it is only copying the link itself. Jeff Hobbs The Tcl Guy Senior Developer http://www.ActiveState.com/ Tcl Support and Productivity Solutions Join us in Sept. for Tcl'2002: http://www.tcl.tk/community/tcl2002/ |