package com.perforce.cvs.parser; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class RcsFileFinder { private Logger logger = LoggerFactory.getLogger(RcsFileFinder.class); private int count = 0; List<File> files = new ArrayList<File>(); public RcsFileFinder(String path) { findFiles(new File(path)); } private void findFiles(File base) { if (!base.exists()) { logger.warn("CVSROOT does not exist: " + base); return; } // copy paths to local list to free up file handle recursion List<Path> paths = new ArrayList<Path>(); try { Path dir = base.toPath(); DirectoryStream<Path> stream = Files.newDirectoryStream(dir); Iterator<Path> iter = stream.iterator(); while (iter.hasNext()) { paths.add(iter.next()); } stream.close(); } catch (IOException e) { logger.error("Unable to list files: ", e); } // loop over found paths and recurse into directories for (Path path : paths) { if (path.toFile().isDirectory()) { if (!"CVSROOT".equals(path.getFileName().toString())) { findFiles(path.toFile()); } } else { if (path.toString().endsWith(",v")) { File file = verifyFile(path); if (logger.isDebugEnabled()) { logger.debug("file: " + file); } files.add(file); count++; System.out.print("Found: " + count + "\r"); } } } } private File verifyFile(Path path) { File file = path.toFile(); try { RandomAccessFile rf = new RandomAccessFile(file, "r"); try { rf.close(); } catch (IOException e) { logger.error("Unable to close file: ", file); } } catch (FileNotFoundException e) { String uriStr = path.toUri().toString(); uriStr = uriStr.replaceFirst("file://", ""); // re-encode path with a guess of CP1252, or fall back to URI. // Windows (Western Europe code page) most commonly miss read! try { uriStr = URLDecoder.decode(uriStr, "windows-1252"); logger.debug("... decoding path with: windows-1252"); } catch (UnsupportedEncodingException e2) { logger.warn("Unknown charset, encoding as URI"); } file = new File(uriStr); try { logger.info("... renaming: " + file); Files.move(path, file.toPath(), StandardCopyOption.ATOMIC_MOVE); } catch (IOException e1) { logger.error("Unable to rename file: " + file); } } return file; } public List<File> getFiles() { return files; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 13876 | Paul Allen | Rename/move file(s) | ||
//guest/paul_allen/p4convert-maven/src/com/perforce/cvs/parser/RcsFileFinder.java | |||||
#1 | 13873 | Paul Allen | Branching using p4convert-maven | ||
//guest/perforce_software/p4convert/src/com/perforce/cvs/parser/RcsFileFinder.java | |||||
#7 | 12418 | Paul Allen | CVS: When scanning for RCS files, store listing and close handle before recursion. | ||
#6 | 12386 | Paul Allen |
CVS: Prevent CVSROOT dir from being added. - includes test case064 |
||
#5 | 12339 | Paul Allen |
Performance improvements for the early stages of the CVS list building: - Building branch list - Building revision list |
||
#4 | 12334 | Paul Allen | Bug Fix: Close newDirectoryStream resource. | ||
#3 | 12260 | Paul Allen |
CVS: Rename badly encoded paths. First try CP1252, if that fails use a URI encoded path. If a URI encoded path is used then it will be decode to UTF8. |
||
#2 | 11186 | Paul Allen |
Support standard command line arguments. Important change please note... @rjackson @nmorse The change was needed to extend the current features like --info and --user for CVS and future SCM support. Please check the documentation and CLI usage for the new usage. - CVS support for --users - Unit tests for CLI arguments Example: standard usage. java -jar p4convert.jar --config=myFile.cfg Example: generate a CVS configuration file. java -jar p4convert.jar --type=CVS --default Example: report Subversion repository usage. java -jar p4convert.jar --type=SVN --repo=/path/to/repo.dump --info |
||
#1 | 9807 | Paul Allen | Initial import of p4-convert (from change 894340) |