Hi, I have some problems with this patch, in that the directory scanner will become a lot more complex, in order to solve some kind of mis-configuration of a projects file structure.
In my opinion, the situation that is tried to be solved here (circularity in symbolic links) should never occur in a projects file structure. In the case it does occur, you better review your filestructure, instead of adapting your tools to it. Cheers, Arnout > -----Original Message----- > From: Robin Green [mailto:[EMAIL PROTECTED] > Sent: vrijdag 17 maart 2000 15:35 > To: [EMAIL PROTECTED] > Subject: [PATCH] - updated - Prevents infinite dir recursion > > > Please ignore the first patch from me fwded by Stefano - it > was incorrect. > > --- DirectoryScanner.java Fri Mar 17 14:04:16 2000 > +++ DirectoryScanner.java.orig Thu Mar 16 23:04:42 2000 > @@ -132,8 +132,6 @@ > * .class files in all directories under a directory called "modules" > * > * @author Arnout J. Kuiper <a > href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> > - * @author Robin D. Green > - * <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> > */ > public class DirectoryScanner { > > @@ -150,14 +148,6 @@ > "**/CVS/*", > "**/.cvsignore" > }; > - > - /** > - * Dummy filename to represent parent dir of a dir which > doesn't have a > - * parent. The only purpose is to be able to compare it > with equals (), > - * which doesn't work if null is used. This should be a non-null > illegal > - * filename. > - */ > - private static final String DUMMY_NO_PARENT = ""; > > /** > * The base directory which should be scanned. > @@ -208,27 +198,6 @@ > */ > private Vector dirsExcluded; > > - /** > - * If this is true, filesystem links that point to a parent of > themselves > - * will be followed maximally, until directories that > have already been > - * scanned are reached. (Actually, the current method may repeat > files.) > - * If false, they will not be followed at all. > - * In either case, a series of links that form a loop > will be detected. > - * Setting this to true is not recommended as it may drastically > - * increase the time required. > - * False by default. > - * > - * @see setMinLoopDetect(boolean) > - */ > - private boolean minLoopDetect = false; > - > - /** > - * This holds filesystem links that have already been traversed, > - * to prevent them being traversed again. > - * This acts like a HashSet. > - */ > - private Hashtable linksSeenAlready; > - > > > /** > @@ -607,22 +576,6 @@ > > > /** > - * If minLoopDetect is true, filesystem links that point > to a parent of > - * themselves will be followed maximally, until > directories that have > - * already been scanned are reached. > - * If false, they will not be followed at all. > - * In either case, a series of links that form a loop > will be detected. > - * Setting minLoopDetect to true is not recommended as it may > drastically > - * increase the time required. > - * False by default. > - */ > - public void setMinLoopDetect (boolean minLoopDetect) { > - this.minLoopDetect = minLoopDetect; > - } > - > - > - > - /** > * Scans the base directory for files that match at > least one include > * pattern, and don't match any exclude patterns. > * > @@ -655,8 +608,6 @@ > dirsNotIncluded = new Vector(); > dirsExcluded = new Vector(); > > - linksSeenAlready = new Hashtable(); > - > scandir(basedir,""); > } > > @@ -680,58 +631,6 @@ > * @see #dirsExcluded > */ > private void scandir(File dir, String vpath) { > - > - /* > - * RDG: Prevent "infinite" recursion if a filesystem > link points to > a > - * parent of itself, or if a series of traversed > links form a loop. > - * (Okay, making such a link might not be very sensible, > - * but the user may have good reasons for doing this, and > - * indefinite looping isn't desirable behaviour.) > - */ > - try { > - String canonicalDir = dir.getCanonicalPath (); > - > - // XXX: This will stop loops, but dirs may still > be repeated. > - if (linksSeenAlready.contains (canonicalDir)) { > - return; // We've been here already > - } > - else { > - /* > - * To save space we only remember links, not > all dirs. > - * No attempt to detect links pointing to > another dir in > same > - * directory, which are harmless anyway. > - * Need special handling for filesys roots > and links to > root(s). > - */ > - File canonDirFile = new File (canonicalDir); > - String dirParent = dir.getParent (), > - canonSrcParent = ((dirParent == null) > - ? DUMMY_NO_PARENT > - : new File (dirParent).getCanonicalPath ()), > - canonDestParent = canonDirFile.getParent (); > - > - if (canonDestParent == null) > - canonDestParent = DUMMY_NO_PARENT; > - boolean dangerousLink = > - !canonDestParent.equals (canonSrcParent); > - > - if (dangerousLink) { > - linksSeenAlready.put (canonicalDir, > canonicalDir); > - } > - if (!minLoopDetect) { > - if (canonSrcParent.startsWith (canonicalDir)) { > - /* > - * Filesystem link recursion detected. > - * For speed, don't bother following it. > - */ > - return; > - } > - } > - } > - } catch (IOException ex) { > - // dir doesn't appear to exist anyway > - return; > - } > - > String[] newfiles = dir.list(); > for (int i = 0; i < newfiles.length; i++) { > String name = vpath+newfiles[i]; > > ______________________________________________________ > Get Your Private, Free Email at http://www.hotmail.com >
