Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.1-beta-2
-
Fix Version/s: None
-
Component/s: groovy-jdk
-
Labels:None
-
Environment:redhat fc5, sun java 5 or 6, ubuntu feisty, sun java 5 or 6
-
Number of attachments :
Description
The following script will quickly stack overflow on linux if the IllegalArgumentException line is commented out.
#!/usr/bin/env groovy
def ff = new File("/sys/block/md0/subsystem");
def isSymlink(ff){
return ff.getAbsolutePath()!=ff.getCanonicalPath() ;
}
ff.eachFileRecurse {
printf("%s\n",it);
if( isSymlink(it) )
}
Issue Links
- is related to
-
GROOVY-2740
eachFileRecurse() goes into infinte loop traversing /proc filesystem in Linux
-
The updated test script below fixes a problem with the previous isSymlink() method.
When tested against groovy 1.5.3, the original problem disappears.
The remaining requirement seems to be one of the following:
1. prevent eachFileRecurse from recursion below symbolic links to directories
2. provide a way to reject recursion, for example, by registering a callback filter that decides whether to recurse each directory
The first approach is probably what is needed 99% of the time, the second is more flexible.
#!/usr/bin/env groovy
// setup the environment for this test by the following:
// mkdir testdir
// ln -s . testdir/parentdir
infile = new File("testdir")
{ throw new IllegalArgumentException("circular symlinks"); }infile.eachFileRecurse {
printf("%s\n",it);
if( isSymlink(it) )
}
// modified to reject false positives caused by symlinked parents
def isSymlink(ff){
absfile = ff.getAbsoluteFile()
parentDir = absfile.getParentFile()
isLink = false
{ println() printf(" ff: %-20s\n",ff) printf(" absfile: %-20s\n",absfile) printf("parentDir:%-20s\n",parentDir) printf("testfile: %-20s\n",testfile) printf(" ap: %-20s\n",aplower) printf(" cp: %-20s\n",cplower) }if( parentDir ){
testfile = new File(parentDir.getCanonicalFile(),ff.getName())
ap = testfile.getAbsolutePath()
cp = testfile.getCanonicalPath()
aplower = ap.toLowerCase()
cplower = cp.toLowerCase()
isLink = (aplower != cplower)
if( isLink )
}
return isLink
}