computer_protocol/
transfer.rs1use serde::{Deserialize, Serialize};
2
3pub const MAX_LISTED_SKIPS: usize = 50;
5
6pub const SKIP_REPORT_ENTRY: &str = ".computerd-skipped";
8
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11pub struct UploadQuery {
12 pub path: String,
14 #[serde(default)]
16 pub overwrite: bool,
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
21pub struct UploadCheck {
22 pub path: String,
23 #[serde(default)]
24 pub overwrite: bool,
25 pub name: String,
27 pub folder: bool,
29}
30
31#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
33pub struct DownloadRequest {
34 pub path: String,
36}
37
38#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40pub struct Skipped {
41 pub path: String,
42 pub reason: String,
43}
44
45#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
47pub struct SkipList {
48 pub entries: Vec<Skipped>,
49 pub omitted: u64,
50}
51
52impl SkipList {
53 pub fn push(&mut self, path: impl Into<String>, reason: impl Into<String>) {
54 if self.entries.len() < MAX_LISTED_SKIPS {
55 self.entries.push(Skipped {
56 path: path.into(),
57 reason: reason.into(),
58 });
59 } else {
60 self.omitted += 1;
61 }
62 }
63
64 pub fn merge(&mut self, other: Self) {
66 self.omitted += other.omitted;
67 for entry in other.entries {
68 self.push(entry.path, entry.reason);
69 }
70 }
71
72 #[must_use]
73 pub fn is_empty(&self) -> bool {
74 self.entries.is_empty() && self.omitted == 0
75 }
76}
77
78#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
80pub struct TransferReply {
81 pub path: String,
83 pub files: u64,
84 pub folders: u64,
85 pub bytes: u64,
87 pub skipped: SkipList,
88}