file copy attempts to copy directory into itself
Open82049f96f841214bb8cee18e1bf8f84aa25ed9aaCreated 8 years agoUpdated 42 days ago
Descriptionplain2018-11-21 14:06:54
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'
Referenced by4
f9d02b912dTicket [875545270d] tcl::CopyDirectory copying /a/a /x/a/a error status still Open with 4 other changes ticket2026-10-19 18:54:12c51f96d014Fix [82049f96f8] and [875545270d]: [file copy] of a directory into itself recursed until the path was too long; now it is an error. tcl::CopyDirectory, used for copies between file systems, rejected targets that only contained the source path, because it used [string first]; compare path prefixes instead. check-in2026-10-19 18:53:17eb8329112dTicket [daba77ae1d] [file delete -force] fails with "file name too long" on trees deeper than PATH_MAX (Unix) status still Open with 3 other changes ticket2026-10-17 13:17:314cd8cba031New ticket [daba77ae1d] [file delete -force] fails with "file name too long" on trees deeper than PATH_MAX (Unix). ticket2026-10-17 10:51:11
serhiy.storchakawiki2026-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.storchakawiki2026-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.
dgpplain2026-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.
Log in (anonymous is fine) to add a comment.