adb_utils/commands/file_transfer/
sync.rs1use std::{fmt::Display, process::Command};
2
3use crate::{ADBCommand, ADBResult};
4
5use super::CompressionAlgorithm;
6
7pub struct ADBSync {
9 location: SyncLocation,
10 shell: Command,
11}
12
13impl ADBSync {
14 pub fn new(location: SyncLocation) -> Self {
15 let mut cmd = Command::new("adb");
16 cmd.arg("sync");
17
18 ADBSync {
19 shell: cmd,
20 location,
21 }
22 }
23
24 pub fn dry_run(mut self) -> Self {
26 self.shell.arg("-n");
27 self
28 }
29
30 pub fn list(mut self) -> Self {
32 self.shell.arg("-l");
33 self
34 }
35
36 pub fn compression(mut self, algorithm: CompressionAlgorithm) -> Self {
38 self.shell.arg("-z").arg(algorithm.to_string());
39 self
40 }
41
42 pub fn no_compression(mut self) -> Self {
44 self.shell.arg("-Z");
45 self
46 }
47}
48
49impl ADBCommand for ADBSync {
50 fn build(&mut self) -> Result<&mut Command, String> {
51 self.shell.arg(self.location.to_string());
52 Ok(&mut self.shell)
53 }
54
55 fn process_output(&self, output: ADBResult) -> ADBResult {
56 output
57 }
58}
59
60pub enum SyncLocation {
61 All,
62 Data,
63 Odm,
64 Oem,
65 Product,
66 System,
67 SystemExt,
68 Vendor,
69}
70
71impl Display for SyncLocation {
72 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73 write!(
74 f,
75 "{}",
76 match self {
77 SyncLocation::All => "all",
78 SyncLocation::Data => "data",
79 SyncLocation::Odm => "odm",
80 SyncLocation::Oem => "oem",
81 SyncLocation::Product => "product",
82 SyncLocation::System => "system",
83 SyncLocation::SystemExt => "system_ext",
84 SyncLocation::Vendor => "vendor",
85 }
86 )
87 }
88}