Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!pa.dec.com!bacchus!mwm From: mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) Newsgroups: comp.sys.amiga.programmer Subject: Re: Checking to see if a file's a link Message-ID: Date: 30 Apr 91 19:35:40 GMT References: <15127@darkstar.ucsc.edu> <1991Apr30.070121.24535@watdragon.waterloo.edu> Sender: news@pa.dec.com (News) Organization: Missionaria Phonibalonica Lines: 39 In-Reply-To: ccplumb@rose.waterloo.edu's message of 30 Apr 91 07:01:21 GMT In article <1991Apr30.070121.24535@watdragon.waterloo.edu> ccplumb@rose.waterloo.edu (Colin Plumb) writes: mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) wrote: > Last time I reported this bug, I was told that they were going to > "fix" the problem by having makelink not allow circular links. That > this implied searching the entire subtree beneath the link didn't seem > to bother the person who posted that fix. You have to do this on rename, anyway, to avoid the Ouroboros bug. (Under 1.3, on a scratch floppy, makedir foo; makedir foo/bar; rename foo foo/bar/foo; *Poof*.) Actually, to check for this, you don't search the entire subtree under the source; rather you check all parents of the destination. To check that a proposed link to foo: with name bar:foo isn't circular, check that bar:, bar:/, bar://, etc. are not the same as foo:. Given SameLock(), it's trivial to write. Nope, just checking parents of the destination isn't good enough. If there is a link to a parent of the destination somewhere under the source, then a recursive descent of the source will follow the old link to that parent, down to the destination, and back to the source via the new link. Checking the parents only finds things that are directly circular; it doesn't find things that are indirectly circular. I.e, if foo:bar is a link to bar, then your test won't notice that foo:bar/foo is the same as foo: (and bar:foo/bar is the same as bar:). Unix solved this in two different ways for the two different kinds of links. Applications don't walk soft links unless they are explicitly told to. You can guard against loops (if you want to) by keeping a list of the soft links you've walked. The ln command won't (normally) let you create a hard link to a directory, so there can't be any circular links with hard links.