Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-17
09:08 • Ticket [1827008fff] delete and copy fail in linux when path contains "..&qu... artifact: 706e165202 user: serhiy.storchaka
09:07
Fix [1827008fff]: on Unix [file delete -force d1/d2/d3/..] deleted the contents of d2 but not d2, an... leaf check-in: 50534654de user: serhiy.storchaka tags: delete-refuse-dot-dot
2007-11-06
17:15 • New ticket [1827008fff] delete and copy fail in linux when path contains ".... artifact: 222545e891 user: mgma

delete and copy fail in linux when path contains ".."

Open1827008fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 47 days ago
Descriptionplain2007-11-06 17:15:50
The code below runs correctly in Windows, but not in Linux. (I'm using ActiveTcl 8.4.7 in both cases).

% file mkdir d1/d2/d3
% file delete -force d1/d2/d3/..

In Windows, it deletes d2 and leaves d1 empty. However, in Linux I get the error:

'error deleting "d1/d2/d3/..": no such file or directory

In Linux, d3 is deleted, but not d2.

In order that it works I must normalize the file name:

% file delete -force [file normalize d1/d2/d3/..]

I think that it might not be correct that the operation is partially performed and then fails. I also find the error message not very descriptive of the problem.

The same thing happens when using [file copy] with directory paths containing "..".

I've asked about this at comp.lang.tcl, and Donald G Porter suggested that it may be the same as Bug 961646.
Referenced by1
  • 50534654deFix [1827008fff]: on Unix [file delete -force d1/d2/d3/..] deleted the contents of d2 but not d2, and reported success. Refuse to remove a path ending in "." or "..", as rm(1) does: on POSIX ".." is resolved physically, so "d1/d2/d3/.." is not necessarily "d1/d2". check-in2026-10-17 09:07:41
serhiy.storchakawiki2026-10-17 09:08:45

Still there, and since 8.5 the failure is silent: [file delete -force d1/d2/d3/..] deletes the contents of d2 but not d2 itself, and returns success (the final rmdir() fails with ENOENT, which is ignored). Proposed fix in branch delete-refuse-dot-dot: on Unix, refuse to remove a path ending in "." or "..", as rm(1) does. Normalizing the path, as on Windows, would be wrong on POSIX: ".." is resolved physically there, so if d3 is a symbolic link, "d1/d2/d3/.." is the parent of its target, not "d1/d2". Test fCmd-5.14.

Log in (anonymous is fine) to add a comment.