adb_utils/commands/file_transfer/
push.rs

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