From: Michael A. <mic...@us...> - 2005-11-07 01:51:42
|
Update of /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8501/modules/scanner/src/com/babeldoc/scanner/worker Modified Files: FtpScanner.java Log Message: Patch provided by Albert Apolloner <ap...@em...> to fix the following issues: 1) If includeSubfolder=true the scanner only walked down the first line of the directory tree 2) A permanent connect/disconnect activity (> 1/sec) despite the period property was set to 60000ms 3) Problem with FTP server timeouts Index: FtpScanner.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker/FtpScanner.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** FtpScanner.java 24 Jul 2004 00:18:52 -0000 1.24 --- FtpScanner.java 7 Nov 2005 01:51:33 -0000 1.25 *************** *** 110,113 **** --- 110,114 ---- public static final String SCAN_SUBFOLDERS = "includeSubfolders"; public static final String FILTER_FILENAME = "filter"; + public static final String MAX_DEPTH = "maxDepth"; //private final static int rertyCount = 3; *************** *** 118,122 **** private String ftpPassword = ""; private String ftpUsername = ""; ! private int ftpFileType = FTPClient.ASCII_FILE_TYPE; private String localBackupFolder = ""; private boolean scanSubfolders = false; --- 119,125 ---- private String ftpPassword = ""; private String ftpUsername = ""; ! private int ftpFileType = FTPClient.ASCII_FILE_TYPE; ! private int maxDepth = 0; ! private int curDepth = 0; private String localBackupFolder = ""; private boolean scanSubfolders = false; *************** *** 191,194 **** --- 194,198 ---- .equalsIgnoreCase(this.getInfo().getStrValue(SCAN_SUBFOLDERS)))) { scanSubfolders = true; + maxDepth = Integer.parseInt(this.getInfo().getStrValue(MAX_DEPTH)); } *************** *** 238,249 **** if (ftpClient.login(ftpUsername, ftpPassword)) { if (ftpClient.changeWorkingDirectory(ftpFolder)) { ! if(ftpClient.setFileType(ftpFileType)) { ! // ! } else { ! ftpClient.disconnect(); ! throw new ScannerException( ! I18n.get("scanner.FtpScanner.error.filetype")); ! } ! } else { ftpClient.disconnect(); throw new ScannerException( --- 242,253 ---- if (ftpClient.login(ftpUsername, ftpPassword)) { if (ftpClient.changeWorkingDirectory(ftpFolder)) { ! if(ftpClient.setFileType(ftpFileType)) { ! // ! } else { ! ftpClient.disconnect(); ! throw new ScannerException( ! I18n.get("scanner.FtpScanner.error.filetype")); ! } ! } else { ftpClient.disconnect(); throw new ScannerException( *************** *** 462,474 **** log.logDebug("Scanning " + ftpClient.printWorkingDirectory()); } ! ! if ((ftpClient.getReplyCode() == FTPReply.CLOSING_DATA_CONNECTION) ! || (ftpClient.getReplyCode() == FTPReply.SERVICE_NOT_AVAILABLE)) { ! ftpClient.disconnect(); ! connectToHost(); ! } //first change working dir! ftpClient.changeWorkingDirectory(folder); FTPFile[] ftpFiles = null; --- 466,481 ---- log.logDebug("Scanning " + ftpClient.printWorkingDirectory()); } ! ! /* the following code creates unnecessary reconnects - if you think it is necessary uncoment it ! * if ((ftpClient.getReplyCode() == FTPReply.CLOSING_DATA_CONNECTION) ! * || (ftpClient.getReplyCode() == FTPReply.SERVICE_NOT_AVAILABLE)) { ! * //ftpClient.disconnect(); ! * //connectToHost(); ! * } ! */ //first change working dir! ftpClient.changeWorkingDirectory(folder); + curDepth++; FTPFile[] ftpFiles = null; *************** *** 499,502 **** --- 506,512 ---- if (ftpFiles == null) { + // no files found in this dir - so return to parent + ftpClient.changeWorkingDirectory( ".." ); + curDepth--; return; } *************** *** 515,521 **** } else if (ftpFiles[i].isDirectory() && scanSubfolders) { //Get files from new current diretory by executing this method recurs. ! processFtpFolder(ftpFiles[i].getName()); } } } catch (Exception e) { throw new ScannerException( --- 525,539 ---- } else if (ftpFiles[i].isDirectory() && scanSubfolders) { //Get files from new current diretory by executing this method recurs. ! if (curDepth <= maxDepth){ ! //Walk down the tree until max depth limit is reached ! processFtpFolder(ftpFiles[i].getName()); ! } } } + // return to parent, otherwise you get stuck at the end of the first branch + // when walking down subdirs + ftpClient.changeWorkingDirectory( ".." ); + curDepth--; + } catch (Exception e) { throw new ScannerException( *************** *** 618,622 **** --- 636,649 ---- I18n.get("scanner.FtpScannerInfo.option.filter"))); + options.add( + new ConfigOption( + FtpScanner.MAX_DEPTH, + IConfigOptionType.STRING, + "0", + false, + "scanner.FtpScannerInfo.option.maxDepth")); + return options; } } + |