private Directory createDirectory(final FileSet set) { final DirectoryScanner scanner = set.getDirectoryScanner(getProject()); final String[] files = scanner.getIncludedFiles(); if (files.length == 0) { // skip return null; } Directory root = new Directory(scanner.getBasedir()); Stream.of(files).map(Directory::getPath).forEach(path -> { Directory current = root; File currentParent = scanner.getBasedir(); for (String element : path) { final File file = new File(currentParent, element); if (file.isDirectory()) { current.addDirectory(new Directory(file)); current = current.getChild(file); currentParent = current.getDirectory(); } else if (file.isFile()) { current.addFile(file); } } }); return root; }
private void sendDirectory(final Directory current, final InputStream in, final OutputStream out) throws IOException { for (final Iterator<File> fileIt = current.filesIterator(); fileIt.hasNext();) { sendFileToRemote(fileIt.next(), in, out); } for (final Iterator<Directory> dirIt = current.directoryIterator(); dirIt.hasNext();) { sendDirectoryToRemote(dirIt.next(), in, out); } }
/** * Get the path components of this directory. * @return the path components as an array of strings. */ public String[] getPath() { return getPath(directory.getAbsolutePath()); }
/** * Get a child directory of this directory. * @param dir the directory to look for * @return the child directory, or null if not found */ public Directory getChild(File dir) { for (Directory current : childDirectories) { if (current.getDirectory().equals(dir)) { return current; } } return null; }
private void sendDirectoryToRemote(final Directory directory, final InputStream in, final OutputStream out) throws IOException { String command = "D0"; command += Integer.toOctalString(getDirMode()); command += " 0 "; command += directory.getDirectory().getName(); command += "\n"; out.write(command.getBytes()); out.flush(); waitForAck(in); sendDirectory(directory, in, out); out.write("E\n".getBytes()); out.flush(); waitForAck(in); }
Directory root = new Directory(baseDir); Directory current = root; File currentParent = baseDir; for (String element : Directory.getPath(name)) { final File file = new File(currentParent, element); if (file.isDirectory()) { current.addDirectory(new Directory(file)); current = current.getChild(file); currentParent = current.getDirectory(); } else if (file.isFile()) { current.addFile(file);
private void sendDirectory(final ChannelSftp channel, final Directory current) throws IOException, SftpException { for (final Iterator<File> fileIt = current.filesIterator(); fileIt.hasNext();) { sendFileToRemote(channel, fileIt.next(), null); } for (final Iterator<Directory> dirIt = current.directoryIterator(); dirIt.hasNext();) { sendDirectoryToRemote(channel, dirIt.next()); } }
private void sendDirectoryToRemote(final ChannelSftp channel, final Directory directory) throws IOException, SftpException { final String dir = directory.getDirectory().getName(); try { channel.stat(dir); } catch (final SftpException e) { // dir does not exist. if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { channel.mkdir(dir); channel.chmod(getDirMode(), dir); } } channel.cd(dir); sendDirectory(channel, directory); channel.cd(".."); }
} catch (final SftpException e) { String msg = "Error sending directory"; if (current != null && current.getDirectory() != null) { msg += " '" + current.getDirectory().getName() + "'";