android_tools/adb/
adb_push.rs

1use crate::error::*;
2use std::{
3    path::{Path, PathBuf},
4    process::Command,
5};
6
7#[derive(Clone, Default)]
8pub struct AdbPush {
9    sync: Option<PathBuf>,
10    n: bool,
11    z_enable_compression: bool,
12    z_disable_compression: bool,
13}
14
15impl AdbPush {
16    pub fn new() -> Self {
17        Self {
18            ..Default::default()
19        }
20    }
21
22    /// Only push files that are newer on the host than the device
23    pub fn sync(&mut self, sync: &Path) -> &mut Self {
24        self.sync = Some(sync.to_owned());
25        self
26    }
27
28    /// Dry run: push files to device without storing to the filesystem
29    pub fn n(&mut self, n: bool) -> &mut Self {
30        self.n = n;
31        self
32    }
33
34    /// Enable compression with a specified algorithm (any, none, brotli)
35    pub fn z_enable_compression(&mut self, z_enable_compression: bool) -> &mut Self {
36        self.z_enable_compression = z_enable_compression;
37        self
38    }
39
40    /// Disable compression
41    pub fn z_disable_compression(&mut self, z_disable_compression: bool) -> &mut Self {
42        self.z_disable_compression = z_disable_compression;
43        self
44    }
45
46    pub fn run(&self) -> Result<()> {
47        let mut adb_push = Command::new("adb");
48        adb_push.arg("push");
49        if let Some(sync) = &self.sync {
50            adb_push.arg("--sync").arg(sync);
51        }
52        if self.n {
53            adb_push.arg("-n");
54        }
55        if self.z_enable_compression {
56            adb_push.arg("-z");
57        }
58        if self.z_disable_compression {
59            adb_push.arg("-Z");
60        }
61        adb_push.output_err(true)?;
62        Ok(())
63    }
64}