Luke Cole wrote:
>> I can't help but wonder - what happens if you end up with a
>> situation like this?:
>>
>> Directory called "abc" with a symlink inside to directory "def"
>> with a symlink inside to directory "abc".
>>
>> Does [del] loop forever?
Good question.. you mean "del /s", right?
No, in all the tests I tried (below) making circular 'directory'
links (mklink /d), it behaves well with both 'del /s' and 'rmdir /s'
it would seem.
The only command I was able to get to loop forever was 'dir /s'.
My approach was:
mkdir \temp\test
cd \temp\test
mkdir bar
echo foo > bar\aaa
echo foo > bar\bbb
mkdir bar\subdir
echo foo > bar\subdir\ccc
echo foo > bar\subdir\ddd _
mklink /d tobar \temp\test\bar |___ create circular links
mklink /d bar\totest \temp\test _|
..and then manipulating the 'tobar' link with the following commands.
DEL /S
------
In the case of 'del /s somelink', it just deletes the files
it finds in each directory recursively, then stops. No dirs
or links removed.
My guess is it prevents looping forever by keeping track of
the actual directories its been into, converting each link
it encounters as it goes into actual dir names, and /not/
descending into any link to a dir its already been to. Proof:
C:\TEMP\test>del /s tobar
C:\TEMP\test\tobar\*, Are you sure (Y/N)? y
Deleted file - C:\TEMP\test\tobar\aaa
Deleted file - C:\TEMP\test\tobar\bbb
C:\TEMP\test\tobar\subdir\*, Are you sure (Y/N)? y
Deleted file - C:\TEMP\test\tobar\subdir\ccc
Deleted file - C:\TEMP\test\tobar\subdir\ddd
C:\TEMP\test>dir
[..]
Directory of C:\TEMP\test
05/30/2007 10:26 AM <DIR> .
05/30/2007 10:26 AM <DIR> ..
05/30/2007 10:26 AM <DIR> bar
05/30/2007 10:26 AM <SYMLINKD> tobar [\temp\test\bar]
[..]
C:\TEMP\test>dir bar
[..]
Directory of C:\TEMP\test\bar
05/30/2007 10:26 AM <DIR> .
05/30/2007 10:26 AM <DIR> ..
05/30/2007 10:26 AM <DIR> subdir
05/30/2007 10:26 AM <SYMLINKD> totest [\temp\test]
[..]
C:\TEMP\test>dir bar\subdir
[..]
Directory of C:\TEMP\test\bar\subdir
05/30/2007 10:26 AM <DIR> .
05/30/2007 10:26 AM <DIR> ..
[..]
RMDIR /S
--------
I also tried with 'rmdir /s'.. if you run that on a link,
it just /removes the link/, as if the "/s" wasn't there.
It does not appear to descend the link at all, and does not
seem to affect the files/dirs the link points to.
So I guess when you want to recursively remove stuff,
you have to use the real directory name, not a link.
You can 'rmdir /s' a directory that contains links, and
the links themselves get deleted. I didn't check to see
if those links it encounters within were followed;
I imagine they're not. Proof:
C:\TEMP\test>rmdir /s tobar
tobar, Are you sure (Y/N)? y
C:\TEMP\test>dir
[..]
Directory of C:\TEMP\test
05/30/2007 10:28 AM <DIR> .
05/30/2007 10:28 AM <DIR> ..
05/30/2007 10:28 AM <DIR> bar
[..]
C:\TEMP\test>dir bar
[..]
Directory of C:\TEMP\test\bar
05/30/2007 10:28 AM <DIR> .
05/30/2007 10:28 AM <DIR> ..
05/30/2007 10:28 AM 6 aaa
05/30/2007 10:28 AM 6 bbb
05/30/2007 10:28 AM <DIR> subdir
05/30/2007 10:28 AM <SYMLINKD> totest [\temp\test]
[..]
C:\TEMP\test>dir bar\subdir
[..]
Directory of C:\TEMP\test\bar\subdir
05/30/2007 10:28 AM <DIR> .
05/30/2007 10:28 AM <DIR> ..
05/30/2007 10:28 AM 6 ccc
05/30/2007 10:28 AM 7 ddd
[..]
DIR /S
------
Trying 'dir /s' on a circular link tree caused it to loop
forever, showing a bigger and bigger list until it reached
a filename size limit, where it began truncating the pathnames,
printing 'arglist too long' as it went.
But it didn't stop, it just kept trying over and over forever.
The good thing is that it doesn't run out of memory or crash,
due to the filename limit. But you do have to hit ^C to stop it.
CAVEATS
-------
YMMV! This is with Vista Business Edition, first release.
MS could change this behavior, who knows? It's undocumented
in 'del /?' and 'rmdir /?', so it's hard to know the philosophy
from the designer's point of view, other than by observed behavior.
DOS online docs never did achieve 'man page' nirvana.
Maybe the docs will cover links in the future.
But currently the del/rmdir docs are about as short as they were
in the 80's.
--
Greg Ercolano, erco@(email surpressed)
Rush Render Queue, http://seriss.com/rush/
Tel: (Tel# suppressed)
Fax: (Tel# suppressed)
Cel: (Tel# suppressed)
[this post was edited slightly on 06/01/2007 to improve clarity -erco]
|