private void pullDirectory(final IDevice device, final String name) throws Exception { // Output path on private internal storage, for KitKat and below. FileEntry internalDir = getDirectoryOnInternalStorage(name); logDebug(debug, "Internal path is " + internalDir.getFullPath()); // Output path on public external storage, for Lollipop and above. FileEntry externalDir = getDirectoryOnExternalStorage(device, name); logDebug(debug, "External path is " + externalDir.getFullPath()); // Sync test output files to the local filesystem. logDebug(debug, "Pulling files from external dir on [%s]", serial); String localDirName = work.getAbsolutePath(); adbPull(device, externalDir, localDirName); logDebug(debug, "Pulling files from internal dir on [%s]", serial); adbPull(device, internalDir, localDirName); logDebug(debug, "Done pulling %s from on [%s]", name, serial); }
if ( sourceFileEntry.isDirectory() )
fileEntry = fileEntry.findChild( destinationPathSegment ); if ( fileEntry == null )
if (useCache && entry.needFetch() == false) { return entry.getCachedChildren(); return entry.getCachedChildren(); Thread t = new Thread("ls " + entry.getFullPath()) { //$NON-NLS-1$ @Override public void run() {
entry = new FileEntry(mParentEntry, name, objectType, false /* isRoot */);
if (useCache && !entry.needFetch()) { return entry.getCachedChildren(); return entry.getCachedChildren(); Thread t = new Thread("ls " + entry.getFullPath()) { //$NON-NLS-1$ @Override public void run() {
doLs(entry); receiver.setChildren(entry, entry.getCachedChildren()); final FileEntry[] children = entry.getCachedChildren(); if (children.length > 0 && children[0].isApplicationPackage()) { final HashMap<String, FileEntry> map = new HashMap<String, FileEntry>(); String path = child.getFullPath(); map.put(path, child);
doLs(entry); receiver.setChildren(entry, entry.getCachedChildren()); final FileEntry[] children = entry.getCachedChildren(); if (children.length > 0 && children[0].isApplicationPackage()) { final HashMap<String, FileEntry> map = new HashMap<String, FileEntry>(); String path = child.getFullPath(); map.put(path, child);
int type = e.getType(); if (type == FileListingService.TYPE_DIRECTORY) { monitor.startSubTask(e.getFullPath()); String dest = localPath + File.separator + e.getName(); monitor.advance(1); } else if (type == FileListingService.TYPE_FILE) { monitor.startSubTask(e.getFullPath()); String dest = localPath + File.separator + e.getName(); doPullFile(e.getFullPath(), dest, monitor);
int type = e.getType(); if (type == FileListingService.TYPE_DIRECTORY) { monitor.startSubTask(e.getFullPath()); String dest = localPath + File.separator + e.getName(); monitor.advance(1); } else if (type == FileListingService.TYPE_FILE) { monitor.startSubTask(e.getFullPath()); String dest = localPath + File.separator + e.getName(); doPullFile(e.getFullPath(), dest, monitor);
private void doLsAndThrow(FileEntry entry) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { // create a list that will receive the list of the entries ArrayList<FileEntry> entryList = new ArrayList<FileEntry>(); // create a list that will receive the link to compute post ls; ArrayList<String> linkList = new ArrayList<String>(); try { // create the command String command = "ls -l " + entry.getFullEscapedPath(); //$NON-NLS-1$ if (entry.isDirectory()) { // If we expect a file to behave like a directory, we should stick a "/" at the end. // This is a good habit, and is mandatory for symlinks-to-directories, which will // otherwise behave like symlinks. command += FILE_SEPARATOR; } // create the receiver object that will parse the result from ls LsReceiver receiver = new LsReceiver(entry, entryList, linkList); // call ls. mDevice.executeShellCommand(command, receiver); // finish the process of the receiver to handle links receiver.finishLinks(mDevice, entryList); } finally { // at this point we need to refresh the viewer entry.fetchTime = System.currentTimeMillis(); // sort the children and set them as the new children Collections.sort(entryList, FileEntry.sEntryComparator); entry.setChildren(entryList); } }
result = result.findChild(segment); if (result == null) { return true; // Send the file if it doesn't exist if (result.getSizeValue() != getLocalSourceFile().length()) { return true; // Send the file if the sizes don't match LocalDateTime remoteFileTime = LocalDateTime.parse(result.getDate() + "T" + result.getTime()); LocalDateTime localFileTime = Instant.ofEpochMilli(getLocalSourceFile().lastModified()) .atZone(ZoneId.systemDefault()).toLocalDateTime();
/** * Push several files. * @param local An array of loca files to push * @param remote the remote {@link FileEntry} representing a directory. * @param monitor The progress monitor. Cannot be null. * @throws SyncException if file could not be pushed * @throws IOException in case of I/O error on the connection. * @throws TimeoutException in case of a timeout reading responses from the device. */ public void push(String[] local, FileEntry remote, ISyncProgressMonitor monitor) throws SyncException, IOException, TimeoutException { if (!remote.isDirectory()) { throw new SyncException(SyncError.REMOTE_IS_FILE); } // make a list of File from the list of String ArrayList<File> files = new ArrayList<File>(); for (String path : local) { files.add(new File(path)); } // get the total count of the bytes to transfer File[] fileArray = files.toArray(new File[files.size()]); int total = getTotalLocalFileSize(fileArray); monitor.start(total); doPush(fileArray, remote.getFullPath(), monitor); monitor.stop(); }
/** * Push several files. * @param local An array of loca files to push * @param remote the remote {@link FileEntry} representing a directory. * @param monitor The progress monitor. Cannot be null. * @throws SyncException if file could not be pushed * @throws IOException in case of I/O error on the connection. * @throws TimeoutException in case of a timeout reading responses from the device. */ public void push(String[] local, FileEntry remote, ISyncProgressMonitor monitor) throws SyncException, IOException, TimeoutException { if (remote.isDirectory() == false) { throw new SyncException(SyncError.REMOTE_IS_FILE); } // make a list of File from the list of String ArrayList<File> files = new ArrayList<File>(); for (String path : local) { files.add(new File(path)); } // get the total count of the bytes to transfer File[] fileArray = files.toArray(new File[files.size()]); int total = getTotalLocalFileSize(fileArray); monitor.start(total); doPush(fileArray, remote.getFullPath(), monitor); monitor.stop(); }
/** * compute the recursive file size of all the files in the list. Folder * have a weight of 1. * @param entries * @param fls * @return */ private int getTotalRemoteFileSize(FileEntry[] entries, FileListingService fls) { int count = 0; for (FileEntry e : entries) { int type = e.getType(); if (type == FileListingService.TYPE_DIRECTORY) { // get the children FileEntry[] children = fls.getChildren(e, false, null); count += getTotalRemoteFileSize(children, fls) + 1; } else if (type == FileListingService.TYPE_FILE) { count += e.getSizeValue(); } } return count; }
/** * Returns the children of a {@link FileEntry}. * <p> * This method is the explicit synchronous version of * {@link #getChildren(FileEntry, boolean, IListingReceiver)}. It is roughly equivalent to * calling * getChildren(FileEntry, false, null) * * @param entry The parent entry. * @return The list of children * @throws TimeoutException in case of timeout on the connection when sending the command. * @throws AdbCommandRejectedException if adb rejects the command. * @throws ShellCommandUnresponsiveException in case the shell command doesn't send any output * for a period longer than <var>maxTimeToOutputResponse</var>. * @throws IOException in case of I/O error on the connection. */ public FileEntry[] getChildrenSync(final FileEntry entry) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { doLsAndThrow(entry); return entry.getCachedChildren(); }
/** * compute the recursive file size of all the files in the list. Folder * have a weight of 1. * @param entries * @param fls * @return */ private int getTotalRemoteFileSize(FileEntry[] entries, FileListingService fls) { int count = 0; for (FileEntry e : entries) { int type = e.getType(); if (type == FileListingService.TYPE_DIRECTORY) { // get the children FileEntry[] children = fls.getChildren(e, false, null); count += getTotalRemoteFileSize(children, fls) + 1; } else if (type == FileListingService.TYPE_FILE) { count += e.getSizeValue(); } } return count; }
/** * Pulls a single file. * @param remote the remote file * @param localFilename The local destination. * @param monitor The progress monitor. Cannot be null. * * @throws IOException in case of an IO exception. * @throws TimeoutException in case of a timeout reading responses from the device. * @throws SyncException in case of a sync exception. * * @see FileListingService.FileEntry * @see #getNullProgressMonitor() */ public void pullFile(FileEntry remote, String localFilename, ISyncProgressMonitor monitor) throws IOException, SyncException, TimeoutException { int total = remote.getSizeValue(); monitor.start(total); doPullFile(remote.getFullPath(), localFilename, monitor); monitor.stop(); }
/** * Create an ls receiver/parser. * @param currentChildren The list of current children. To prevent * collapse during update, reusing the same FileEntry objects for * files that were already there is paramount. * @param entryList the list of new children to be filled by the * receiver. * @param linkList the list of link path to compute post ls, to figure * out if the link pointed to a file or to a directory. */ public LsReceiver(FileEntry parentEntry, ArrayList<FileEntry> entryList, ArrayList<String> linkList) { mParentEntry = parentEntry; mCurrentChildren = parentEntry.getCachedChildren(); mEntryList = entryList; mLinkList = linkList; }