Re: How to determine if a directory is a subdirectory of another directory?
- From: Andreas Leitgeb <avl@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: 26 Nov 2008 08:38:44 GMT
Arjen Markus <arjen.markus@xxxxxxxxxx> wrote:
Directory contents:
work/
example.inp
Script:
foreach f [glob *] {
file copy $f work
}
which led to an almost endless loop (the path became too long, that is
why it stopped)
Comparing the normalized source and target (each with a slash appended!)
for substring-equality should suffice, unless you're on a platform that
supports symlinks, where you'd first have to resolve all symlinks along
the path, which is a non-trivial task.
Linux's "cp" detects such situations:
cp: cannot copy a directory, `work', into itself, `work/work'
(but still creates an empty directory `work/work')
Solaris's "cp" runs into the same trouble as tcl.
So, if you're on linux, you could [exec cp -r ...]
Perhaps a TIP to get this protection into tcl's file command might
be adequate (as I'd expect symlinks to be another possible cause of
trouble).
I'm not sure, if the problem is principially solveable at all.
Perhaps by keeping an array of the created inodes and refuse to
re-copy any of these?
.
- Follow-Ups:
- Re: How to determine if a directory is a subdirectory of another directory?
- From: Arjen Markus
- Re: How to determine if a directory is a subdirectory of another directory?
- References:
- How to determine if a directory is a subdirectory of another directory?
- From: Arjen Markus
- How to determine if a directory is a subdirectory of another directory?
- Prev by Date: Re: How to determine if a directory is a subdirectory of another directory?
- Next by Date: Re: How to determine if a directory is a subdirectory of another directory?
- Previous by thread: Re: How to determine if a directory is a subdirectory of another directory?
- Next by thread: Re: How to determine if a directory is a subdirectory of another directory?
- Index(es):
Relevant Pages
|