Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!kuhub.cc.ukans.edu!markv From: markv@kuhub.cc.ukans.edu Newsgroups: comp.sys.amiga.programmer Subject: Re: Checking to see if a file's a link Message-ID: <1991Apr29.160901.30173@kuhub.cc.ukans.edu> Date: 29 Apr 91 16:08:59 CDT References: <15127@darkstar.ucsc.edu> Organization: University of Kansas Academic Computing Services Lines: 37 In article , mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) writes: > In article <15127@darkstar.ucsc.edu> davids@ucscb.ucsc.edu (Dave Schreiber) writes: > Is there a way, under 2.0, to examine a file or directory from a program > and determine whether or not it's a link? I'm trying to write a DU program > that will avoid going in circles if there's a link in a directory to an > ancestor of that directory. > > Yeah - check DirEntryType (or whatever you check to see if it's a > directory).... > On a related topic, will the release version of Workbench 2.x have this > sort of protection built into it's recursive commands (like dir)? > Currently, if I have a directory 'foo', with a link to it's parent > directory, and I do a 'dir foo all', dir ends up going in circles. > > Last time I reported this bug, I was told that they were going to > "fix" the problem by having makelink not allow circular links. I think the latest 2.0 Makelink will still do make circular links. There is a better solution. 2.0 dos.library has a function called SameLock() that takes two locks and returns TRUE if they are the same object (I think all it does is check for a match of the handler and header block fields). With this, just keep a Lock on each level of the tree you've walked down, and if you step into a link, then check for a match with each parent. If you get a match, you've made a cycle and skip that link, otherwise, you can proceed with that link safely. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Mark Gooderum Only... \ Good Cheer !!! Academic Computing Services /// \___________________________ University of Kansas /// /| __ _ Bix: mgooderum \\\ /// /__| |\/| | | _ /_\ makes it Bitnet: MARKV@UKANVAX \/\/ / | | | | |__| / \ possible... Internet: markv@kuhub.cc.ukans.edu ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~