/** * Traverse the directory tree starting in dir and add all the encountered files to the Set * allFiles. */ private void traverseDirsForFiles(Set allFiles, File dir, FileFilter filter) { if (!filter.accept(dir)) { return; } if (dir.isFile()) { allFiles.add(dir); return; } File[] files = dir.listFiles(filter); if (files == null) { return; } try { getLocallyDeletedFiles(allFiles, dir); } catch (IOException ioe) { Debug.message("CVS error determining locally deleted files: " + ioe.getLocalizedMessage()); // TODO: should probably propagate and cause the command to fail. } for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { allFiles.add(files[i]); } else { traverseDirsForFiles(allFiles, files[i], filter); } } }
/** * Get a list of files which are in the repository, but which are not in the local project. This * includes both files which have been locally deleted, and files which have been added to the * repository from another location. * * <p>Throws CommandAbortedException if command aborted. * * @param client the client for processing the commands * @param files the list to store the discovered files in (may be null) * @param path the path to look at * @param remoteDirs a set to store all encountered remote directories in * @param localDirs whether to only look at directories which also exist locally * @throws InvalidCvsRootException * @throws AuthenticationException * @throws CommandException */ private void getRemoteFiles( Client client, List files, File path, Set remoteDirs, boolean localDirs) throws AuthenticationException, CommandAbortedException, CommandException { UpdateServerResponse updateResponse = getUpdateServerResponse(client, path.getAbsolutePath()); List updated = updateResponse.getUpdated(); Iterator i = updated.iterator(); while (i.hasNext()) { CvsUpdateResult ur = (CvsUpdateResult) i.next(); File f = new File(path, ur.getFilename()); remoteDirs.add(f.getParentFile()); if (files != null && !f.exists()) { files.add(f); } } // Now recurse into any new directories which were discovered. List newDirs = updateResponse.getNewDirectoryNames(); i = newDirs.iterator(); while (i.hasNext()) { String newDirName = i.next().toString(); File localPath = new File(path, newDirName); if (!localDirs || localPath.isDirectory()) { remoteDirs.add(localPath); getRemoteFiles(client, files, localPath, remoteDirs, localDirs); } } }
/* * (non-Javadoc) * @see bluej.groupwork.Repository#getAllLocallyDeletedFiles() */ public void getAllLocallyDeletedFiles(Set files) { LinkedList stack = new LinkedList(); stack.add(projectPath); Set tempSet = new HashSet(); FileFilter reposFilter = getMetadataFilter(); while (!stack.isEmpty()) { File dir = (File) stack.remove(0); File[] subDirs = dir.listFiles(new DirectoryFilter()); for (int i = 0; i < subDirs.length; i++) { if (reposFilter.accept(subDirs[i])) { stack.add(subDirs[i]); } } try { getLocallyDeletedFiles(files, dir); } catch (IOException ioe) { } } File delDir = new File(projectPath, "CVS"); delDir = new File(delDir, "deleted"); if (delDir.exists()) { stack.add(delDir); } while (!stack.isEmpty()) { File dir = (File) stack.remove(0); File[] subDirs = dir.listFiles(new DirectoryFilter()); for (int i = 0; i < subDirs.length; i++) { if (reposFilter.accept(subDirs[i])) { stack.add(subDirs[i]); } } try { getLocallyDeletedFiles(tempSet, dir); for (Iterator i = tempSet.iterator(); i.hasNext(); ) { File file = (File) i.next(); // map the file back to the real directory String fileStr = file.getPath(); fileStr = fileStr.substring(delDir.getPath().length()); file = new File(projectPath, fileStr); files.add(file); } tempSet.clear(); } catch (IOException ioe) { } } }
/** * Get the locally deleted files (files which are under version control, and which existed * locally, but which have been deleted locally). * * @param set The set to store the locally deleted files in * @param dir The directory to look for deleted files in (non-recursively) * @throws IOException */ public void getLocallyDeletedFiles(Set set, File dir) throws IOException { Iterator i = adminHandler.getEntries(dir); while (i.hasNext()) { Entry entry = (Entry) i.next(); File file = new File(dir, entry.getName()); if (!file.exists() && !entry.isDirectory()) { set.add(new File(dir, entry.getName())); } } }