protected File searchFile ( String scriptName , String [ ] path ) { if ( scriptName == null || path == null ) { return null ; } for ( String pathElement : path ) { final File pathElementDir = new File ( pathElement ) ; // skip if pathElement is not a directory if ( ! pathElementDir . isDirectory ( ) ) { continue ; } final File file = new File ( pathElementDir , scriptName . replaceAll ( "/" , Matcher . quoteReplacement ( File . separator ) ) ) ; if ( ! file . exists ( ) ) { continue ; } try { // prevent attacks with scripts using ".." in their name. if ( ! isInside ( file , pathElementDir ) ) { return null ; } } catch ( IOException e ) { logger . warn ( "Unable to check whether '" + file . getPath ( ) + "' is below '" + pathElementDir . getPath ( ) + "'" ) ; continue ; } try { return file . getCanonicalFile ( ) ; } catch ( IOException e ) { logger . error ( "Unable to get canonical file for '" + file . getPath ( ) + "'" , e ) ; } } return null ; }
Searches for the file with the given name on the path .