diff --git a/devlib/target.py b/devlib/target.py index 2989b9c..f07f326 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -649,7 +649,7 @@ class Target(object): return paths @call_conn - def pull(self, source, dest, as_root=False, timeout=None, globbing=False): # pylint: disable=arguments-differ + def pull(self, source, dest, as_root=False, timeout=None, globbing=False, via_temp=False): # pylint: disable=arguments-differ source = str(source) dest = str(dest) @@ -658,17 +658,21 @@ class Target(object): else: sources = [source] + # The SSH server might not have the right permissions to read the file, + # so use a temporary copy instead. + via_temp |= as_root + mapping = self._prepare_xfer('pull', sources, dest, pattern=source if globbing else None, as_root=as_root) def do_pull(sources, dest): self.conn.pull(sources, dest, timeout=timeout) - if as_root: + if via_temp: for sources, dest in mapping.items(): for source in sources: with self._xfer_cache_path(source) as device_tempfile: - self.execute("cp -r -- {} {}".format(quote(source), quote(device_tempfile)), as_root=True) - self.execute("{} chmod 0644 -- {}".format(self.busybox, quote(device_tempfile)), as_root=True) + self.execute("cp -r -- {} {}".format(quote(source), quote(device_tempfile)), as_root=as_root) + self.execute("{} chmod 0644 -- {}".format(self.busybox, quote(device_tempfile)), as_root=as_root) do_pull([device_tempfile], dest) else: for sources, dest in mapping.items(): diff --git a/doc/target.rst b/doc/target.rst index 10f7db2..f17cfe4 100644 --- a/doc/target.rst +++ b/doc/target.rst @@ -249,7 +249,7 @@ Target matches, ``dest`` must be a folder (or will be created as such if it does not exists yet). -.. method:: Target.pull(source, dest [, as_root, timeout, globbing]) +.. method:: Target.pull(source, dest [, as_root, timeout, globbing, via_temp]) Transfer a file from the target device to the host machine. @@ -267,6 +267,10 @@ Target pattern instead of being take as-is. If the pattern has multiple matches, ``dest`` must be a folder (or will be created as such if it does not exists yet). + :param via_temp: If ``True``, copy the file first to a temporary location on + the target, and then pull it. This can avoid issues some filesystems, + notably paramiko + OpenSSH combination having performance issues when + pulling big files from sysfs. .. method:: Target.execute(command [, timeout [, check_exit_code [, as_root [, strip_colors [, will_succeed [, force_locale]]]]]])