yazi_scheduler/file/
op.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use yazi_fs::Cha;
use yazi_shared::url::Url;

#[derive(Debug)]
pub enum FileOp {
	Paste(FileOpPaste),
	Link(FileOpLink),
	Hardlink(FileOpHardlink),
	Delete(FileOpDelete),
	Trash(FileOpTrash),
}

impl FileOp {
	pub fn id(&self) -> usize {
		match self {
			Self::Paste(op) => op.id,
			Self::Link(op) => op.id,
			Self::Hardlink(op) => op.id,
			Self::Delete(op) => op.id,
			Self::Trash(op) => op.id,
		}
	}
}

// --- Paste
#[derive(Clone, Debug)]
pub struct FileOpPaste {
	pub id:     usize,
	pub from:   Url,
	pub to:     Url,
	pub cha:    Option<Cha>,
	pub cut:    bool,
	pub follow: bool,
	pub retry:  u8,
}

impl FileOpPaste {
	pub(super) fn spawn(&self, from: Url, to: Url, cha: Cha) -> Self {
		Self {
			id: self.id,
			from,
			to,
			cha: Some(cha),
			cut: self.cut,
			follow: self.follow,
			retry: self.retry,
		}
	}
}

// --- Link
#[derive(Clone, Debug)]
pub struct FileOpLink {
	pub id:       usize,
	pub from:     Url,
	pub to:       Url,
	pub cha:      Option<Cha>,
	pub resolve:  bool,
	pub relative: bool,
	pub delete:   bool,
}

impl From<FileOpPaste> for FileOpLink {
	fn from(value: FileOpPaste) -> Self {
		Self {
			id:       value.id,
			from:     value.from,
			to:       value.to,
			cha:      value.cha,
			resolve:  true,
			relative: false,
			delete:   value.cut,
		}
	}
}

// --- Hardlink
#[derive(Clone, Debug)]
pub struct FileOpHardlink {
	pub id:     usize,
	pub from:   Url,
	pub to:     Url,
	pub cha:    Option<Cha>,
	pub follow: bool,
}

impl FileOpHardlink {
	pub(super) fn spawn(&self, from: Url, to: Url, cha: Cha) -> Self {
		Self { id: self.id, from, to, cha: Some(cha), follow: self.follow }
	}
}

// --- Delete
#[derive(Clone, Debug)]
pub struct FileOpDelete {
	pub id:     usize,
	pub target: Url,
	pub length: u64,
}

// --- Trash
#[derive(Clone, Debug)]
pub struct FileOpTrash {
	pub id:     usize,
	pub target: Url,
	pub length: u64,
}