Tcl Source Code

View Ticket
Login
2026-10-21
18:29 • Ticket [82049f96f8] file copy attempts to copy directory into itself status ... artifact: 79494e41b2 user: dgp
2026-10-19
18:54 • Ticket [875545270d] tcl::CopyDirectory copying /a/a /x/a/a error status stil... artifact: f9d02b912d user: serhiy.storchaka
18:54 • Ticket [82049f96f8] file copy attempts to copy directory into itself status ... artifact: 616bbebb7e user: serhiy.storchaka
18:53
Fix [82049f96f8] and [875545270d]: [file copy] of a directory into itself recursed until the path wa... leaf check-in: c51f96d014 user: serhiy.storchaka tags: copy-into-itself
2026-10-17
13:17 • Ticket [daba77ae1d] file delete -force fails with "file name too long&quo... artifact: eb8329112d user: serhiy.storchaka
10:53 • Ticket [82049f96f8] file copy attempts to copy directory into itself status ... artifact: 433c923ce3 user: serhiy.storchaka
10:51 • New ticket [daba77ae1d] file delete -force fails with "file name too long... artifact: 4cd8cba031 user: serhiy.storchaka
2018-11-21
14:06 • New ticket [82049f96f8] file copy attempts to copy directory into itself. artifact: cbfcf5d2d4 user: anonymous

Ticket UUID: 82049f96f841214bb8cee18e1bf8f84aa25ed9aa
Title: file copy attempts to copy directory into itself
Type: Bug Created on: 2018-11-21 14:06:54
Submitter: anonymous Assigned to: nobody
Subsystem: 37. File System Severity: Minor
Priority: 5 Medium Last modified: 2026-10-21 18:29:26
Status: Open Closed by: nobody
Resolution: None Closed on:
Version: 8.6.18, 9.0.5, 9.1.0
Description:
Tcl's "file copy" functionality attempts to copy a directory into itself.  Like:

$ mkdir 1
$ mkdir 1/2
$ tclsh
% file copy 1 1/2
error copying "1" to "1/2/1": "1/2/1/2/1/2[long string deleted]": file name too long

Other, similar programs seem to check the inodes of the path to ensure directories don't get copied into themselves:

$ mkdir 1
$ mkdir 1/2
$ cp -r 1 1/2
cp: cannot copy a directory, '1', into itself, '1/2/1'
User Comments:
serhiy.storchaka added on 2026-10-17 10:53:34:

The deep tree that [file copy 1 1/2] leaves behind cannot be removed with [file delete -force] either: [daba77ae1d].


serhiy.storchaka added on 2026-10-19 18:54:12:

Still present in 8.6, 9.0 and 9.1: [file copy 1 1/2] (and [file copy -force d d]) copies until the path is too long, and leaves a tree that [file delete -force] cannot remove ([daba77ae1d]).

Proposed fix in branch copy-into-itself, together with [875545270d]: copying a directory into itself is now an error, "trying to copy a directory into itself". The normalized paths are compared, so links are handled, and so is a different letter case on Windows (checked under Wine). If the target's parent does not exist, the old error is kept. Tests fCmd-21.13 and 21.14.


dgp added on 2026-10-21 18:29:26:
Just want to add a caution that Tcl's virtual filesystems
and ability to mount anywhere undermines a lot of 
"common sense" reasoning about the relationship between
directories.  Be sure to consider all the possibilities
and not limit your analysis to the assumption that all
paths are inside a single filesystem.