adb_utils/commands/file_transfer/
pull.rs

1use std::process::Command;
2
3use crate::{ADBPathCommand, ADBResult};
4
5use super::CompressionAlgorithm;
6
7/// Copy files/directories from device
8pub struct ADBPull {
9    path: Option<String>,
10    remote: String,
11    local: String,
12    shell: Command,
13}
14
15impl ADBPull {
16    pub fn new(remote: &str, local: &str) -> Self {
17        let mut cmd = Command::new("adb");
18        cmd.arg("pull");
19
20        ADBPull {
21            path: None,
22            remote: remote.to_owned(),
23            local: local.to_owned(),
24            shell: cmd,
25        }
26    }
27
28    /// Preserve file timestamp and mode
29    pub fn timestamp(mut self) -> Self {
30        self.shell.arg("-a");
31        self
32    }
33
34    /// Enable compression with the specified algorithm
35    pub fn compression(mut self, algorithm: CompressionAlgorithm) -> Self {
36        self.shell.arg("-z").arg(algorithm.to_string());
37        self
38    }
39
40    /// Disable compression
41    pub fn no_compression(mut self) -> Self {
42        self.shell.arg("-Z");
43        self
44    }
45}
46
47impl ADBPathCommand for ADBPull {
48    fn build(&mut self) -> Result<&mut Command, String> {
49        match &self.path {
50            Some(path) => {
51                self.shell
52                    .arg(format!("{}{}", path, self.remote))
53                    .arg(&self.local);
54                Ok(&mut self.shell)
55            }
56            None => Err("No path specified".to_string()),
57        }
58    }
59
60    fn process_output(&self, output: ADBResult) -> ADBResult {
61        output
62    }
63
64    fn path(&mut self, path: Option<String>) {
65        self.path = path
66    }
67}